yangjie #49

Merged
yangqiang merged 71 commits from yangjie into master 2025-03-10 14:21:26 +08:00
4 changed files with 16 additions and 20 deletions
Showing only changes of commit caba67da14 - Show all commits

26
main.js
View File

@ -24,10 +24,9 @@ app.allowRendererProcessReuse = false;
let mainWindow = null; let mainWindow = null;
let childWindow = {} let childWindow = {}
let isMaximized = false; let isMaximized = false;
let env; let env = 'development'; //development production
let regKey; let regKey;
let connection = null; let connection = null;
let envStr;
let startNumber = 0; let startNumber = 0;
let buildStatus = false; //true 打包开发版本 false 本地开发 let buildStatus = false; //true 打包开发版本 false 本地开发
powerSaveBlocker.start('prevent-display-sleep') powerSaveBlocker.start('prevent-display-sleep')
@ -53,15 +52,13 @@ class AppWindow extends BrowserWindow {
const finalConfig = { ...basicConfig, ...config }; const finalConfig = { ...basicConfig, ...config };
super(finalConfig); super(finalConfig);
if (env === 'development') { if (env === 'development') {
// 开发
if (buildStatus) { if (buildStatus) {
this.loadFile(path.resolve(__dirname, './dist/index.html')); this.loadURL('http://192.168.2.9:8827/');
} else { } else {
this.loadURL('http://localhost:3000'); this.loadURL('http://localhost:3000');
} }
} else { } else {
// 测试 | 生产 this.loadFile(path.resolve(__dirname, './dist/index.html'))
this.loadFile(path.resolve(__dirname, './dist/index.html'));
} }
this.once('ready-to-show', () => { this.once('ready-to-show', () => {
this.show(); this.show();
@ -73,10 +70,10 @@ function quit() {
} }
let tray; let tray;
function createTray() { function createTray() {
const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(envStr)}.png`; const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(env)}.png`;
const trayIcon = nativeImage.createFromPath(iconPath); const trayIcon = nativeImage.createFromPath(iconPath);
tray = new Tray(trayIcon); tray = new Tray(trayIcon);
tray.setToolTip(updateJs.getTitle(envStr)); tray.setToolTip(updateJs.getTitle(env));
tray.on('click', () => { tray.on('click', () => {
mainWindow.webContents.send('isOpenWindows'); mainWindow.webContents.send('isOpenWindows');
}); });
@ -103,7 +100,6 @@ app.on('ready', () => {
uploadToServer: false, uploadToServer: false,
ignoreSystemCrashHandler: false ignoreSystemCrashHandler: false
}) })
env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1];
if (env === 'development') { if (env === 'development') {
Object.defineProperty(app, 'isPackaged', { Object.defineProperty(app, 'isPackaged', {
get() { get() {
@ -149,8 +145,7 @@ app.on('ready', () => {
isMaximized = true; isMaximized = true;
} }
}); });
ipcMain.handle('setEnv', (event, str) => { ipcMain.handle('startLoad', (event) => {
envStr = str;
if (startNumber === 0) { if (startNumber === 0) {
updateHandle() // 检查更新 updateHandle() // 检查更新
setInterval(() => { setInterval(() => {
@ -616,10 +611,11 @@ app.on('ready', () => {
width: config.width, width: config.width,
height: config.height, height: config.height,
}) })
if (envStr === 'development') { if (env === 'development') {
// 开发 // 开发
if (buildStatus) { if (buildStatus) {
child.loadURL(`file://${path.join(__dirname, './dist/index.html')}#/${config.key}`); child.loadURL(`http://192.168.2.9:8827/#/${config.key}`);
// child.loadURL(`file://${path.join(__dirname, './dist/index.html')}#/${config.key}`);
} else { } else {
child.loadURL(config.url) child.loadURL(config.url)
} }
@ -734,7 +730,7 @@ function updateHandle() {
updateAva: '检测到新版本,正在下载……', updateAva: '检测到新版本,正在下载……',
updateNotAva: '已经是最新版本,不用更新' updateNotAva: '已经是最新版本,不用更新'
} }
autoUpdater.setFeedURL(updateJs.getUpdateUrl(envStr)) autoUpdater.setFeedURL(updateJs.getUpdateUrl(env))
autoUpdater.autoDownload = false // 不自动下载安装包 autoUpdater.autoDownload = false // 不自动下载安装包
autoUpdater.autoInstallOnAppQuit = false // 不自动安装 autoUpdater.autoInstallOnAppQuit = false // 不自动安装
autoUpdater.on('error', function (error) { autoUpdater.on('error', function (error) {
@ -821,7 +817,7 @@ function mainWindowCenter() {
const startSignalr = async (user) => { const startSignalr = async (user) => {
connection = new signalR.HubConnectionBuilder() connection = new signalR.HubConnectionBuilder()
.withUrl(`${envStr === 'development' ? 'http://192.168.2.9:5192' : 'https://meeting-api.23544.com/pc'}/session-manage`, { .withUrl(`${env === '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,9 +87,9 @@ window.electron = {
isOpenWindows: (callback) => { isOpenWindows: (callback) => {
ipcRenderer.on('isOpenWindows', callback) ipcRenderer.on('isOpenWindows', callback)
}, },
// 设置环境变量 // 首次加载
setEnv: (str) => { startLoad: () => {
ipcRenderer.invoke('setEnv', str) ipcRenderer.invoke('startLoad')
}, },
// 更新 // 更新
updateHandle: () => { updateHandle: () => {

View File

@ -58,7 +58,6 @@ const App: React.FC = () => {
} }
}) })
} }
window.electron.setEnv(import.meta.env.VITE_ENV);
if (userInfo && !userInfo.isAnonymous) { if (userInfo && !userInfo.isAnonymous) {
if (loginInfo && loginInfo.isAutoLogin) { if (loginInfo && loginInfo.isAutoLogin) {
GetCheckOnline(loginInfo.account).then(req => { GetCheckOnline(loginInfo.account).then(req => {
@ -105,6 +104,7 @@ const App: React.FC = () => {
}; };
}, []); }, []);
useEffect(() => { useEffect(() => {
window.electron.startLoad();
window.electron.downFile(async (_e: any, data: any) => { window.electron.downFile(async (_e: any, data: any) => {
const response = await fetch(data.filePath); const response = await fetch(data.filePath);
const arrayBuffer = await response.arrayBuffer(); const arrayBuffer = await response.arrayBuffer();

2
src/render.d.ts vendored
View File

@ -24,7 +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; startLoad: () => any;
updateHandle: () => any; updateHandle: () => any;
getVersion: () => Promise<string>; getVersion: () => Promise<string>;
isVisible: () => Promise<string>; isVisible: () => Promise<string>;