Feat: Supplemented restart events

This commit is contained in:
anmengweilai 2024-01-19 15:06:18 +08:00 committed by lizhihong
parent f1dcb8ffe6
commit 31ad1e1c1b
3 changed files with 26 additions and 1 deletions

View File

@ -4,6 +4,8 @@ export const ALAS_CONFIG_TEST_TEMPLATE_YAML = 'deploy.test.template.yaml';
export const ALAS_INSTR_FILE = 'installer.py';
export const ALAS_RELAUNCH_ARGV = '--relaunch';
export const UPDATE_APP = 'Update app.asar';
export const RepositoryMap = {
china: 'cn',
global: 'global',

View File

@ -1,7 +1,8 @@
import configInfo from '@/config';
import {PyShell} from '@/pyshell';
import {ServiceModule, event} from '@/services/index';
import {ALAS_RELAUNCH_ARGV, BrowserWindowsIdentifier} from '@alas/common';
import {ALAS_RELAUNCH_ARGV, UPDATE_APP, BrowserWindowsIdentifier} from '@alas/common';
import relaunchApp from '@/utils/relaunchApp';
const {installerArgs, installerPath} = configInfo;
@ -26,6 +27,10 @@ export default class ScriptService extends ServiceModule {
// 把服务挂在到app上
this.app.initScriptService(alas);
const restApp = (message: string) => {
message?.includes(UPDATE_APP) && relaunchApp();
};
/**
*
*/
@ -40,13 +45,16 @@ export default class ScriptService extends ServiceModule {
dispatchEvent('scriptLog', err.message);
});
alas?.on('stdout', function (message) {
restApp(message);
dispatchEvent('scriptLog', message);
});
alas?.on('message', function (message) {
restApp(message);
dispatchEvent('scriptLog', message);
});
alas?.on('stderr', function (message: string) {
restApp(message);
dispatchEvent('scriptLog', message);
/**
* Receive logs, judge if Alas is ready

View File

@ -0,0 +1,15 @@
import {app} from 'electron';
import {ALAS_RELAUNCH_ARGV} from '@alas/common';
export const isRelaunch = process.argv.includes(ALAS_RELAUNCH_ARGV);
function relaunchApp() {
/**
* TODO Some events need to be rehandled for restart operations
*/
if (!isRelaunch) {
app.relaunch({args: process.argv.slice(1).concat([ALAS_RELAUNCH_ARGV])});
}
}
export default relaunchApp;