This commit is contained in:
yj 2024-11-25 17:59:01 +08:00
parent 39598fc5fe
commit 74a21a789f
9 changed files with 32 additions and 76 deletions

View File

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

View File

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

View File

@ -41,6 +41,7 @@ const App: React.FC = () => {
useEffect(() => {
let userInfo = JSON.parse(storage.getItem('user') as string)
let loginInfo = JSON.parse(storage.getItem('login') as string)
window.electron.setEnv(import.meta.env.VITE_ENV);
if (userInfo && !userInfo.isAnonymous) {
if (loginInfo && loginInfo.isAutoLogin) {
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;
quitAndInstall: (callBack: Function) => void;
isOpenWindows: (callBack: Function) => void;
setEnv: (str: string) => any;
getVersion: () => Promise<string>;
isVisible: () => Promise<string>;
setRegistry: (uuid: string) => any;

View File

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

View File

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