This commit is contained in:
parent
fce3209e59
commit
caba67da14
26
main.js
26
main.js
|
|
@ -24,10 +24,9 @@ app.allowRendererProcessReuse = false;
|
|||
let mainWindow = null;
|
||||
let childWindow = {}
|
||||
let isMaximized = false;
|
||||
let env;
|
||||
let env = 'development'; //development production
|
||||
let regKey;
|
||||
let connection = null;
|
||||
let envStr;
|
||||
let startNumber = 0;
|
||||
let buildStatus = false; //true 打包开发版本 false 本地开发
|
||||
powerSaveBlocker.start('prevent-display-sleep')
|
||||
|
|
@ -53,15 +52,13 @@ class AppWindow extends BrowserWindow {
|
|||
const finalConfig = { ...basicConfig, ...config };
|
||||
super(finalConfig);
|
||||
if (env === 'development') {
|
||||
// 开发
|
||||
if (buildStatus) {
|
||||
this.loadFile(path.resolve(__dirname, './dist/index.html'));
|
||||
this.loadURL('http://192.168.2.9:8827/');
|
||||
} else {
|
||||
this.loadURL('http://localhost:3000');
|
||||
}
|
||||
} else {
|
||||
// 测试 | 生产
|
||||
this.loadFile(path.resolve(__dirname, './dist/index.html'));
|
||||
this.loadFile(path.resolve(__dirname, './dist/index.html'))
|
||||
}
|
||||
this.once('ready-to-show', () => {
|
||||
this.show();
|
||||
|
|
@ -73,10 +70,10 @@ function quit() {
|
|||
}
|
||||
let tray;
|
||||
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);
|
||||
tray = new Tray(trayIcon);
|
||||
tray.setToolTip(updateJs.getTitle(envStr));
|
||||
tray.setToolTip(updateJs.getTitle(env));
|
||||
tray.on('click', () => {
|
||||
mainWindow.webContents.send('isOpenWindows');
|
||||
});
|
||||
|
|
@ -103,7 +100,6 @@ app.on('ready', () => {
|
|||
uploadToServer: false,
|
||||
ignoreSystemCrashHandler: false
|
||||
})
|
||||
env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1];
|
||||
if (env === 'development') {
|
||||
Object.defineProperty(app, 'isPackaged', {
|
||||
get() {
|
||||
|
|
@ -149,8 +145,7 @@ app.on('ready', () => {
|
|||
isMaximized = true;
|
||||
}
|
||||
});
|
||||
ipcMain.handle('setEnv', (event, str) => {
|
||||
envStr = str;
|
||||
ipcMain.handle('startLoad', (event) => {
|
||||
if (startNumber === 0) {
|
||||
updateHandle() // 检查更新
|
||||
setInterval(() => {
|
||||
|
|
@ -616,10 +611,11 @@ app.on('ready', () => {
|
|||
width: config.width,
|
||||
height: config.height,
|
||||
})
|
||||
if (envStr === 'development') {
|
||||
if (env === 'development') {
|
||||
// 开发
|
||||
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 {
|
||||
child.loadURL(config.url)
|
||||
}
|
||||
|
|
@ -734,7 +730,7 @@ function updateHandle() {
|
|||
updateAva: '检测到新版本,正在下载……',
|
||||
updateNotAva: '已经是最新版本,不用更新'
|
||||
}
|
||||
autoUpdater.setFeedURL(updateJs.getUpdateUrl(envStr))
|
||||
autoUpdater.setFeedURL(updateJs.getUpdateUrl(env))
|
||||
autoUpdater.autoDownload = false // 不自动下载安装包
|
||||
autoUpdater.autoInstallOnAppQuit = false // 不自动安装
|
||||
autoUpdater.on('error', function (error) {
|
||||
|
|
@ -821,7 +817,7 @@ function mainWindowCenter() {
|
|||
|
||||
const startSignalr = async (user) => {
|
||||
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,
|
||||
transport: signalR.HttpTransportType.WebSockets,
|
||||
accessTokenFactory: () => user.token
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ window.electron = {
|
|||
isOpenWindows: (callback) => {
|
||||
ipcRenderer.on('isOpenWindows', callback)
|
||||
},
|
||||
// 设置环境变量
|
||||
setEnv: (str) => {
|
||||
ipcRenderer.invoke('setEnv', str)
|
||||
// 首次加载
|
||||
startLoad: () => {
|
||||
ipcRenderer.invoke('startLoad')
|
||||
},
|
||||
// 更新
|
||||
updateHandle: () => {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ const App: React.FC = () => {
|
|||
}
|
||||
})
|
||||
}
|
||||
window.electron.setEnv(import.meta.env.VITE_ENV);
|
||||
if (userInfo && !userInfo.isAnonymous) {
|
||||
if (loginInfo && loginInfo.isAutoLogin) {
|
||||
GetCheckOnline(loginInfo.account).then(req => {
|
||||
|
|
@ -105,6 +104,7 @@ const App: React.FC = () => {
|
|||
};
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
window.electron.startLoad();
|
||||
window.electron.downFile(async (_e: any, data: any) => {
|
||||
const response = await fetch(data.filePath);
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export interface IElectronAPI {
|
|||
downFile: (callBack: Function) => void;
|
||||
quitAndInstall: (callBack: Function) => void;
|
||||
isOpenWindows: (callBack: Function) => void;
|
||||
setEnv: (str: string) => any;
|
||||
startLoad: () => any;
|
||||
updateHandle: () => any;
|
||||
getVersion: () => Promise<string>;
|
||||
isVisible: () => Promise<string>;
|
||||
|
|
|
|||
Loading…
Reference in New Issue