Skip to content

Commit

Permalink
feat: merge from base
Browse files Browse the repository at this point in the history
  • Loading branch information
modstart committed Dec 30, 2024
2 parents c46f5dc + 5005a92 commit 943a0a5
Show file tree
Hide file tree
Showing 25 changed files with 618 additions and 21 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.4.0

- 新增:工单反馈功能,便于解决问题
- 新增:应用 loading 窗口
- 优化:请求异常时增加错误码

## v0.3.0

- 新增:支持设置投屏视频比特率和刷新率
Expand Down
2 changes: 2 additions & 0 deletions electron/config/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const WindowConfig = {
guideHeight:540,
aboutWidth: 500,
aboutHeight: 400,
feedbackWidth: 600,
feedbackHeight: 600,
setupWidth: 800,
setupHeight: 540,
}
4 changes: 2 additions & 2 deletions electron/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {AppConfig} from "../../src/config";
import Apps from "../mapi/app";

export type ResultType<T> = {
code: boolean,
code: number,
msg: string,
data: T
data?: T
}

export const post = async (url: string, data: any) => {
Expand Down
20 changes: 20 additions & 0 deletions electron/mapi/app/icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const icons = {
success: '<svg t="1733817409678" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1488" width="1024" height="1024"><path d="M512 832c-176.448 0-320-143.552-320-320S335.552 192 512 192s320 143.552 320 320-143.552 320-320 320m0-704C300.256 128 128 300.256 128 512s172.256 384 384 384 384-172.256 384-384S723.744 128 512 128" fill="#FFF" p-id="1489"></path><path d="M619.072 429.088l-151.744 165.888-62.112-69.6a32 32 0 1 0-47.744 42.624l85.696 96a32 32 0 0 0 23.68 10.688h0.192c8.96 0 17.536-3.776 23.616-10.4l175.648-192a32 32 0 0 0-47.232-43.2" fill="#FFF" p-id="1490"></path></svg>',
error: '<svg t="1733817396560" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1326" width="1024" height="1024"><path d="M512 128C300.8 128 128 300.8 128 512s172.8 384 384 384 384-172.8 384-384S723.2 128 512 128zM512 832c-179.2 0-320-140.8-320-320s140.8-320 320-320 320 140.8 320 320S691.2 832 512 832z" fill="#FFF" p-id="1327"></path><path d="M672 352c-12.8-12.8-32-12.8-44.8 0L512 467.2 396.8 352C384 339.2 364.8 339.2 352 352S339.2 384 352 396.8L467.2 512 352 627.2c-12.8 12.8-12.8 32 0 44.8s32 12.8 44.8 0L512 556.8l115.2 115.2c12.8 12.8 32 12.8 44.8 0s12.8-32 0-44.8L556.8 512l115.2-115.2C684.8 384 684.8 364.8 672 352z" fill="#FFF" p-id="1328"></path></svg>',
info: '<svg t="1733992721464" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1357" width="1024" height="1024"><path d="M512 898.71874973C299.30468777 898.71874973 125.28125027 724.69531223 125.28125027 512S299.30468777 125.28125027 512 125.28125027s386.71874973 174.0234375 386.71874973 386.71874973-174.0234375 386.71874973-386.71874973 386.71874973z m0-696.09375c-170.15625027 0-309.37500027 139.21875-309.37500027 309.37500027 0 170.15625027 139.21875 309.37500027 309.37500027 309.37500027 170.15625027 0 309.37500027-139.21875 309.37500027-309.37500027 0-170.15625027-139.21875-309.37500027-309.37500027-309.37500027z" fill="#FFFFFF" p-id="1358"></path><path d="M512 746.59765652a37.96875 37.96875 0 0 1-38.67187473-38.67187554v-221.6953125c0-21.9375 16.76953125-38.67187473 38.67187473-38.67187473 21.90234348 0 38.67187473 16.73437473 38.67187473 38.67187473v221.6953125c0 21.9375-16.76953125 38.67187473-38.67187473 38.67187554zM512 390.81640625a37.96875 37.96875 0 0 1-38.67187473-38.67187473V316.07421902c0-21.9375 16.76953125-38.67187473 38.67187473-38.67187554 21.90234348 0 38.67187473 16.73437473 38.67187473 38.67187554v36.0703125c0 21.9375-18.03515625 38.67187473-38.67187473 38.67187473z" fill="#FFFFFF" p-id="1359"></path></svg>',
loading: `
<svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
<rect fill="#FFFFFF" x="21.5" y="21.5" width="25" height="25" rx="3" ry="3">
<animate attributeName="x" calcMode="linear" values="21.5;53.5;53.5;53.5;53.5;21.5;21.5;21.5;21.5" keyTimes="0;0.083;0.25;0.333;0.5;0.583;0.75;0.833;1" dur="1.5" begin="-1.375s" repeatCount="indefinite"></animate>
<animate attributeName="y" calcMode="linear" values="21.5;53.5;53.5;53.5;53.5;21.5;21.5;21.5;21.5" keyTimes="0;0.083;0.25;0.333;0.5;0.583;0.75;0.833;1" dur="1.5" begin="-1s" repeatCount="indefinite"></animate>
</rect>
<rect fill="#FFFFFF" x="21.5" y="53.5" width="25" height="25" rx="3" ry="3">
<animate attributeName="x" calcMode="linear" values="21.5;53.5;53.5;53.5;53.5;21.5;21.5;21.5;21.5" keyTimes="0;0.083;0.25;0.333;0.5;0.583;0.75;0.833;1" dur="1.5" begin="-0.875s" repeatCount="indefinite"></animate>
<animate attributeName="y" calcMode="linear" values="21.5;53.5;53.5;53.5;53.5;21.5;21.5;21.5;21.5" keyTimes="0;0.083;0.25;0.333;0.5;0.583;0.75;0.833;1" dur="1.5" begin="-0.5s" repeatCount="indefinite"></animate>
</rect>
<rect fill="#FFFFFF" x="53.5" y="42.919" width="25" height="25" rx="3" ry="3">
<animate attributeName="x" calcMode="linear" values="21.5;53.5;53.5;53.5;53.5;21.5;21.5;21.5;21.5" keyTimes="0;0.083;0.25;0.333;0.5;0.583;0.75;0.833;1" dur="1.5" begin="-0.375s" repeatCount="indefinite"></animate>
<animate attributeName="y" calcMode="linear" values="21.5;53.5;53.5;53.5;53.5;21.5;21.5;21.5;21.5" keyTimes="0;0.083;0.25;0.333;0.5;0.583;0.75;0.833;1" dur="1.5" begin="0s" repeatCount="indefinite"></animate>
</rect>
</svg>`,
}
164 changes: 164 additions & 0 deletions electron/mapi/app/loading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import {BrowserWindow} from "electron";
import {AppsMain} from "./main";
import {icons} from "./icons";

export const makeLoading = (msg: string, options?: {
timeout?: number,
percentAuto?: boolean,
percentTotalSeconds?: number,
}): {
close: () => void,
percent: (value: number) => void
} => {

options = Object.assign({
percentAuto: false,
percentTotalSeconds: 30,
timeout: 0
}, options)

if (options.timeout === 0) {
options.timeout = 60 * 10 * 1000
}
// console.log('options', options)

const display = AppsMain.getCurrentScreenDisplay()
// console.log('xxxx', primaryDisplay);
const width = display.workArea.width
const height = 60
const icon = icons.loading

const win = new BrowserWindow({
height,
width,
x: 0,
y: 0,
modal: false,
frame: false,
alwaysOnTop: true,
center: false,
transparent: true,
hasShadow: false,
show: false,
focusable: false,
skipTaskbar: true,
})
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
<style>
html,body{
height: 100vh;
margin: 0;
padding: 0;
background: rgba(0, 0, 0, 0.4);
color: #FFFFFF;
}
.message-view {
height: 100vh;
display:flex;
text-align:center;
padding:0 10px;
position:relative;
}
.message-view #message{
margin: auto;
font-size: 16px;
display: inline-block;
line-height: 30px;
white-space: nowrap;
}
.message-view #message .icon{
width: 30px;
height: 30px;
display:inline-block;
margin-right: 5px;
vertical-align: top;
}
.message-view #percent{
position: absolute;
bottom: 5px;
left: 5px;
right: 5px;
height: 5px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.4);
overflow: hidden;
display:none;
}
.message-view #percent .value{
border-radius: 5px;
height: 100%;
width: 0%;
background: #FFFFFF;
}
::-webkit-scrollbar {
width: 0;
}
</style>
</head>
<body>
<div class="message-view">
<div id="message">${icon}${msg}</div>
<div id="percent">
<div class="value"></div>
</div>
</div>
</body>
</html>
`;

const encodedHTML = encodeURIComponent(htmlContent);
let percentAutoTimer = null
win.loadURL(`data:text/html;charset=UTF-8,${encodedHTML}`);
win.on('ready-to-show', async () => {
const width = Math.ceil(await win.webContents.executeJavaScript(`(()=>{
const message = document.getElementById('message');
const width = message.scrollWidth;
return width;
})()`))
win.setSize(width + 20, height)
const x = display.workArea.x + (display.workArea.width / 2) - ((width + 20) / 2)
const y = display.workArea.y + (display.workArea.height * 2 / 3)
win.setPosition(Math.floor(x), Math.floor(y))
win.show()
if (options.percentAuto) {
let percent = 0
percentAutoTimer = setInterval(() => {
percent += 0.01
if (percent >= 1) {
clearInterval(percentAutoTimer)
return
}
controller.percent(percent)
}, options.percentTotalSeconds * 1000 / 100)
}
// win.webContents.openDevTools({
// mode: 'detach'
// })
})
const winCloseTimer = setTimeout(() => {
win.close()
clearTimeout(winCloseTimer)
}, options.timeout)
const controller = {
close: () => {
win.close()
clearTimeout(winCloseTimer)
if (percentAutoTimer) {
clearInterval(percentAutoTimer)
}
},
percent: (value: number) => {
const percent = 100 * value
win.webContents.executeJavaScript(`(()=>{
const percent = document.querySelector('#percent');
const percentValue = document.querySelector('#percent .value');
percent.style.display = 'block';
percentValue.style.width = '${percent}%';
})()`)
}
}
return controller
}
32 changes: 30 additions & 2 deletions electron/mapi/app/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {app, BrowserWindow, ipcMain, screen, shell, clipboard, nativeImage, nativeTheme} from "electron";
import {app, BrowserWindow, clipboard, ipcMain, nativeImage, nativeTheme, screen, shell} from "electron";
import {WindowConfig} from "../../config/window";
import {AppRuntime} from "../env";
import {isDev, isMac} from "../../lib/env";
import {isDev, isMac, platformArch, platformName} from "../../lib/env";
import {AppPosition} from "./lib/position";
import {Events} from "../event/main";
import {ConfigMain} from "../config/main";
Expand All @@ -11,6 +11,7 @@ import {Page} from "../../page";
import {makeToast} from "./toast";
import {SetupMain} from "./setup";
import {Files} from "../file/main";
import {makeLoading} from "./loading";


const getWindowByName = (name?: string) => {
Expand Down Expand Up @@ -282,6 +283,21 @@ ipcMain.handle('app:toast', (event, msg: string, option?: any) => {
return toast(msg, option)
})

const loading = (msg: string, options?: {
timeout?: number,
percentAuto?: boolean,
percentTotalSeconds?: number,
}): {
close: () => void,
percent: (value: number) => void
} => {
return makeLoading(msg, options)
}

ipcMain.handle('app:loading', (event, msg: string, option?: any) => {
return loading(msg, option)
})

ipcMain.handle('app:setupList', async () => {
return SetupMain.list()
})
Expand Down Expand Up @@ -315,6 +331,17 @@ ipcMain.handle('app:getBuildInfo', async () => {
return getBuildInfo()
})

const collect = async (options?: {}) => {
return {
platformName: platformName(),
platformArch: platformArch(),
}
}

ipcMain.handle('app:collect', async (event, options?: {}) => {
return collect(options)
})

export default {
quit
}
Expand All @@ -330,6 +357,7 @@ export const AppsMain = {
getCurrentScreenDisplay,
calcPositionInCurrentDisplay,
toast,
loading,
setupIsOk,
windowOpen,
}
13 changes: 13 additions & 0 deletions electron/mapi/app/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ const appEnv = async () => {
return AppEnv
}

const setRenderAppEnv = (env: any) => {
AppEnv.isInit = true
AppEnv.appRoot = env.appRoot
AppEnv.appData = env.appData
AppEnv.userData = env.userData
}

const getClipboardText = () => {
return ipcRenderer.invoke('app:getClipboardText')
}
Expand Down Expand Up @@ -112,6 +119,10 @@ const getBuildInfo = async () => {
return ipcRenderer.invoke('app:getBuildInfo')
}

const collect = async (options?: {}) => {
return ipcRenderer.invoke('app:collect', options)
}

export const AppsRender = {
isDarkMode,
resourcePathResolve,
Expand All @@ -131,6 +142,7 @@ export const AppsRender = {
openExternalWeb,
getPreload,
appEnv,
setRenderAppEnv,
getClipboardText,
setClipboardText,
getClipboardImage,
Expand All @@ -140,6 +152,7 @@ export const AppsRender = {
setupOpen,
setupIsOk,
getBuildInfo,
collect,
shell: appIndex.shell,
spawnShell: appIndex.spawnShell,
availablePort: appIndex.availablePort,
Expand Down
8 changes: 2 additions & 6 deletions electron/mapi/app/toast.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {BrowserWindow, screen} from "electron";
import {BrowserWindow} from "electron";
import {AppsMain} from "./main";
import {icons} from "./icons";

const icons = {
success: '<svg t="1733817409678" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1488" width="1024" height="1024"><path d="M512 832c-176.448 0-320-143.552-320-320S335.552 192 512 192s320 143.552 320 320-143.552 320-320 320m0-704C300.256 128 128 300.256 128 512s172.256 384 384 384 384-172.256 384-384S723.744 128 512 128" fill="#FFF" p-id="1489"></path><path d="M619.072 429.088l-151.744 165.888-62.112-69.6a32 32 0 1 0-47.744 42.624l85.696 96a32 32 0 0 0 23.68 10.688h0.192c8.96 0 17.536-3.776 23.616-10.4l175.648-192a32 32 0 0 0-47.232-43.2" fill="#FFF" p-id="1490"></path></svg>',
error: '<svg t="1733817396560" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1326" width="1024" height="1024"><path d="M512 128C300.8 128 128 300.8 128 512s172.8 384 384 384 384-172.8 384-384S723.2 128 512 128zM512 832c-179.2 0-320-140.8-320-320s140.8-320 320-320 320 140.8 320 320S691.2 832 512 832z" fill="#FFF" p-id="1327"></path><path d="M672 352c-12.8-12.8-32-12.8-44.8 0L512 467.2 396.8 352C384 339.2 364.8 339.2 352 352S339.2 384 352 396.8L467.2 512 352 627.2c-12.8 12.8-12.8 32 0 44.8s32 12.8 44.8 0L512 556.8l115.2 115.2c12.8 12.8 32 12.8 44.8 0s12.8-32 0-44.8L556.8 512l115.2-115.2C684.8 384 684.8 364.8 672 352z" fill="#FFF" p-id="1328"></path></svg>',
info:'<svg t="1733992721464" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1357" width="1024" height="1024"><path d="M512 898.71874973C299.30468777 898.71874973 125.28125027 724.69531223 125.28125027 512S299.30468777 125.28125027 512 125.28125027s386.71874973 174.0234375 386.71874973 386.71874973-174.0234375 386.71874973-386.71874973 386.71874973z m0-696.09375c-170.15625027 0-309.37500027 139.21875-309.37500027 309.37500027 0 170.15625027 139.21875 309.37500027 309.37500027 309.37500027 170.15625027 0 309.37500027-139.21875 309.37500027-309.37500027 0-170.15625027-139.21875-309.37500027-309.37500027-309.37500027z" fill="#FFFFFF" p-id="1358"></path><path d="M512 746.59765652a37.96875 37.96875 0 0 1-38.67187473-38.67187554v-221.6953125c0-21.9375 16.76953125-38.67187473 38.67187473-38.67187473 21.90234348 0 38.67187473 16.73437473 38.67187473 38.67187473v221.6953125c0 21.9375-16.76953125 38.67187473-38.67187473 38.67187554zM512 390.81640625a37.96875 37.96875 0 0 1-38.67187473-38.67187473V316.07421902c0-21.9375 16.76953125-38.67187473 38.67187473-38.67187554 21.90234348 0 38.67187473 16.73437473 38.67187473 38.67187554v36.0703125c0 21.9375-18.03515625 38.67187473-38.67187473 38.67187473z" fill="#FFFFFF" p-id="1359"></path></svg>',
}
let win = null
let winCloseTimer = null

Expand Down
Loading

0 comments on commit 943a0a5

Please sign in to comment.