yangjie #37

Merged
yangqiang merged 8 commits from yangjie into master 2024-11-26 10:15:06 +08:00
9 changed files with 32 additions and 76 deletions
Showing only changes of commit 74a21a789f - Show all commits

View File

@ -10,7 +10,7 @@
"publish": [ "publish": [
{ {
"provider": "generic", "provider": "generic",
"url": "https://meeting-api.23544.com/meeting/update/syzh" "url": "https://meeting-api.23544.com/meeting/xysz"
} }
], ],
"files": [ "files": [

View File

@ -1,58 +0,0 @@
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
module.exports = {
packagerConfig: {
"name": "MyElectronApp", // 应用程序的名称
"files": [],
"productName": "My Electron App", // 产品名称(用于生成安装包的名称)
// "icon": "path/to/icon.png", // 应用程序的图标路径
"out": "build/", // 输出目录的路径
"overwrite": true, // 是否覆盖已存在的打包文件
"asar": true, // 是否使用asar打包格式
"version": "0.0.1", // 应用程序版本号
// "copyright": "Copyright © 2023", // 版权信息
// "ignore": [ // 不需要打包的文件和文件夹的路径列表
// ".git",
// ".vscode",
// "node_modules/.cache",
// "src"
// ],
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {}
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {},
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
};

30
main.js
View File

@ -24,6 +24,7 @@ let isMaximized = false;
let env; let env;
let regKey; let regKey;
let connection = null; let connection = null;
let envStr;
class AppWindow extends BrowserWindow { class AppWindow extends BrowserWindow {
constructor(config) { constructor(config) {
@ -43,7 +44,7 @@ class AppWindow extends BrowserWindow {
}; };
const finalConfig = { ...basicConfig, ...config }; const finalConfig = { ...basicConfig, ...config };
super(finalConfig); super(finalConfig);
if (env === 'development') { if (envStr === 'development') {
// 开发 // 开发
this.loadURL('http://localhost:3000'); this.loadURL('http://localhost:3000');
} else { } else {
@ -60,7 +61,7 @@ function quit() {
} }
function createTray() { function createTray() {
const iconPath = `${__dirname}/src/assets/icon.png`; const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(envStr)}.png`;
const trayIcon = nativeImage.createFromPath(iconPath); const trayIcon = nativeImage.createFromPath(iconPath);
const tray = new Tray(trayIcon); const tray = new Tray(trayIcon);
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
@ -83,7 +84,7 @@ function createTray() {
// icon: iconPath, // icon: iconPath,
}, },
]); ]);
tray.setToolTip(updateJs.getTitle(env)); tray.setToolTip(updateJs.getTitle(envStr));
tray.setContextMenu(contextMenu); tray.setContextMenu(contextMenu);
tray.on('click', () => { tray.on('click', () => {
mainWindow.webContents.send('isOpenWindows'); mainWindow.webContents.send('isOpenWindows');
@ -108,11 +109,6 @@ app.on('ready', () => {
autoUpdater.updateConfigPath = path.join('latest.yml') autoUpdater.updateConfigPath = path.join('latest.yml')
} }
createWindow() createWindow()
updateHandle() // 检查更新
setInterval(() => {
updateHandle() // 每一小时检查更新
}, 1000 * 60 * 60)
createTray()
regKey = new Registry({ regKey = new Registry({
hive: Registry.HKCU, hive: Registry.HKCU,
key: '\\Software\\ZhiHuiXiang' key: '\\Software\\ZhiHuiXiang'
@ -128,11 +124,9 @@ app.on('ready', () => {
} }
// 监听f12打开控制台 // 监听f12打开控制台
mainWindow.webContents.on('before-input-event', (event, input) => { mainWindow.webContents.on('before-input-event', (event, input) => {
// if (env === 'development') {
if (input.key === 'F12') { if (input.key === 'F12') {
mainWindow.webContents.openDevTools() mainWindow.webContents.openDevTools()
} }
// }
}); });
// 监听移动 // 监听移动
mainWindow.on('move', () => { mainWindow.on('move', () => {
@ -145,6 +139,14 @@ app.on('ready', () => {
isMaximized = true; isMaximized = true;
} }
}); });
ipcMain.handle('setEnv', (event, str) => {
envStr = str;
updateHandle() // 检查更新
setInterval(() => {
updateHandle() // 每一小时检查更新
}, 1000 * 60 * 60)
createTray()
});
// socket // socket
ipcMain.handle('startSignalr', (event, user) => { ipcMain.handle('startSignalr', (event, user) => {
startSignalr(user) startSignalr(user)
@ -519,7 +521,7 @@ app.on('ready', () => {
width: config.width, width: config.width,
height: config.height, height: config.height,
}) })
if (env === 'development') { if (envStr === 'development') {
// 开发 // 开发
child.loadURL(config.url) child.loadURL(config.url)
} else { } else {
@ -536,11 +538,9 @@ app.on('ready', () => {
windowOperation(config) windowOperation(config)
}) })
child.webContents.on('before-input-event', (event, input) => { child.webContents.on('before-input-event', (event, input) => {
// if (env === 'development') {
if (input.key === 'F12') { if (input.key === 'F12') {
child.webContents.openDevTools() child.webContents.openDevTools()
} }
// }
}); });
}); });
// 关闭子窗口 // 关闭子窗口
@ -628,7 +628,7 @@ function updateHandle() {
updateAva: '检测到新版本,正在下载……', updateAva: '检测到新版本,正在下载……',
updateNotAva: '已经是最新版本,不用更新' updateNotAva: '已经是最新版本,不用更新'
} }
autoUpdater.setFeedURL(updateJs.getUpdateUrl(env)) autoUpdater.setFeedURL(updateJs.getUpdateUrl(envStr))
autoUpdater.autoDownload = false // 不自动下载安装包 autoUpdater.autoDownload = false // 不自动下载安装包
autoUpdater.autoInstallOnAppQuit = false // 不自动安装 autoUpdater.autoInstallOnAppQuit = false // 不自动安装
autoUpdater.on('error', function (error) { autoUpdater.on('error', function (error) {
@ -720,7 +720,7 @@ function mainWindowCenter() {
const startSignalr = async (user) => { const startSignalr = async (user) => {
connection = new signalR.HubConnectionBuilder() connection = new signalR.HubConnectionBuilder()
.withUrl(`${env === 'development' ? 'http://192.168.2.9:5192' : 'https://meeting-api.23544.com/pc'}/session-manage`, { .withUrl(`${envStr === 'development' ? 'http://192.168.2.9:5192' : 'https://meeting-api.23544.com/pc'}/session-manage`, {
skipNegotiation: true, skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets, transport: signalR.HttpTransportType.WebSockets,
accessTokenFactory: () => user.token accessTokenFactory: () => user.token

View File

@ -87,6 +87,10 @@ window.electron = {
isOpenWindows: (callback) => { isOpenWindows: (callback) => {
ipcRenderer.on('isOpenWindows', callback) ipcRenderer.on('isOpenWindows', callback)
}, },
// 设置环境变量
setEnv: (str) => {
ipcRenderer.invoke('setEnv', str)
},
// 通知下载最新的包 // 通知下载最新的包
onDownload: (type) => { onDownload: (type) => {
ipcRenderer.invoke('updateDownload', type) ipcRenderer.invoke('updateDownload', type)

View File

@ -41,6 +41,7 @@ const App: React.FC = () => {
useEffect(() => { useEffect(() => {
let userInfo = JSON.parse(storage.getItem('user') as string) let userInfo = JSON.parse(storage.getItem('user') as string)
let loginInfo = JSON.parse(storage.getItem('login') as string) let loginInfo = JSON.parse(storage.getItem('login') as string)
window.electron.setEnv(import.meta.env.VITE_ENV);
if (userInfo && !userInfo.isAnonymous) { if (userInfo && !userInfo.isAnonymous) {
if (loginInfo && loginInfo.isAutoLogin) { if (loginInfo && loginInfo.isAutoLogin) {
PostLogin({ PostLogin({

BIN
src/assets/icon54.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

1
src/render.d.ts vendored
View File

@ -24,6 +24,7 @@ export interface IElectronAPI {
downFile: (callBack: Function) => void; downFile: (callBack: Function) => void;
quitAndInstall: (callBack: Function) => void; quitAndInstall: (callBack: Function) => void;
isOpenWindows: (callBack: Function) => void; isOpenWindows: (callBack: Function) => void;
setEnv: (str: string) => any;
getVersion: () => Promise<string>; getVersion: () => Promise<string>;
isVisible: () => Promise<string>; isVisible: () => Promise<string>;
setRegistry: (uuid: string) => any; setRegistry: (uuid: string) => any;

View File

@ -58,7 +58,7 @@ export const storageSeeting: any = {
export const getUpdateUrl = (env: string) => { export const getUpdateUrl = (env: string) => {
switch (env) { switch (env) {
case 'xy': case 'xy':
return 'https://meeting-api.23544.com/meeting/update/syzh' return 'https://meeting-api.23544.com/meeting/xysz'
default: default:
return 'https://meeting-api.23544.com/meeting/update' return 'https://meeting-api.23544.com/meeting/update'
} }

View File

@ -2,7 +2,7 @@ module.exports = {
getUpdateUrl(env) { getUpdateUrl(env) {
switch (env) { switch (env) {
case 'xy': case 'xy':
return 'https://meeting-api.23544.com/meeting/update/syzh' return 'https://meeting-api.23544.com/meeting/xysz'
default: default:
return 'https://meeting-api.23544.com/meeting/update' return 'https://meeting-api.23544.com/meeting/update'
} }
@ -14,5 +14,13 @@ module.exports = {
default: default:
return '智汇享' return '智汇享'
} }
},
getIcon(env) {
switch (env) {
case 'xy':
return 'icon54'
default:
return 'icon'
}
} }
} }