AutoLaunch

This commit is contained in:
everoddandeven 2024-10-23 19:01:24 +02:00
parent 8ef7794f98
commit 08c0633579
6 changed files with 62 additions and 17 deletions

View file

@ -8,8 +8,8 @@ import * as tar from 'tar';
import * as os from 'os';
import * as pidusage from 'pidusage';
const AutoLaunch = require('auto-launch');
import AutoLaunch from 'auto-launch';
//const AutoLaunch = require('auto-launch');
interface Stats {
/**
@ -61,9 +61,13 @@ if (!gotInstanceLock) {
}
const autoLauncher = new AutoLaunch({
name: 'Monero Daemon'
name: 'Monero Daemon',
path: `${process.execPath} --auto-launch`
});
const isAutoLaunched: boolean = process.argv.includes('--auto-launch');
dialog.showErrorBox(`Info`, `is auto launched: ${isAutoLaunched}, process.argv: ${process.argv.join(' ')}`)
let win: BrowserWindow | null = null;
@ -581,6 +585,12 @@ try {
})
// #endregion
ipcMain.handle('is-auto-launched', (event: IpcMainInvokeEvent) => {
console.debug(event);
win?.webContents.send('on-is-auto-launched', isAutoLaunched);
});
ipcMain.handle('quit', (event) => {
isQuitting = true;
app.quit();

View file

@ -111,5 +111,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
},
onIsAppImage: (callback) => {
ipcRenderer.on('on-is-app-image', callback);
},
isAutoLaunched: () => {
ipcRenderer.invoke('is-auto-launched');
},
onIsAutoLaunched: (callback) => {
ipcRenderer.on('on-is-auto-launched', callback);
}
});

7
package-lock.json generated
View file

@ -45,6 +45,7 @@
"@ngx-translate/core": "15.0.0",
"@ngx-translate/http-loader": "8.0.0",
"@playwright/test": "1.43.1",
"@types/auto-launch": "5.0.5",
"@types/bootstrap": "5.2.10",
"@types/chart.js": "2.9.41",
"@types/jest": "29.5.13",
@ -6261,6 +6262,12 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/@types/auto-launch": {
"version": "5.0.5",
"resolved": "https://registry.npmjs.org/@types/auto-launch/-/auto-launch-5.0.5.tgz",
"integrity": "sha512-/nGvQZSzM/pvCMCh4Gt2kIeiUmOP/cKGJbjlInI+A+5MoV/7XmT56DJ6EU8bqc3+ItxEe4UC2GVspmPzcCc8cg==",
"dev": true
},
"node_modules/@types/babel__core": {
"version": "7.20.5",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",

View file

@ -91,6 +91,7 @@
"@ngx-translate/core": "15.0.0",
"@ngx-translate/http-loader": "8.0.0",
"@playwright/test": "1.43.1",
"@types/auto-launch": "5.0.5",
"@types/bootstrap": "5.2.10",
"@types/chart.js": "2.9.41",
"@types/jest": "29.5.13",

View file

@ -12,8 +12,8 @@ import { LogsService } from './pages/logs/logs.service';
styleUrls: ['./app.component.scss']
})
export class AppComponent {
public loading: boolean;
public daemonRunning: boolean;
public loading: boolean = false;
public daemonRunning: boolean = false;
public get initializing(): boolean {
return this.daemonData.initializing;
@ -38,23 +38,42 @@ export class AppComponent {
console.log('Run in browser');
}
this.loading = false;
this.daemonRunning = false;
this.load();
}
private load(): void {
private async isAutoLaunched(): Promise<boolean> {
try {
const promise = new Promise<boolean>((resolve) => {
window.electronAPI.onIsAutoLaunched((event: any, isAutoLaunched: boolean) => {
console.debug(event);
resolve(isAutoLaunched);
});
});
window.electronAPI.isAutoLaunched();
return await promise;
} catch(error: any) {
console.error(error);
return false;
}
}
private async load(): Promise<void> {
this.loading = true;
this.daemonService.isRunning().then((running: boolean) => {
this.daemonRunning = running;
this.loading;
}).catch((error) => {
console.error(error);
try {
this.daemonRunning = await this.daemonService.isRunning(true);
const isAutoLaunched = await this.isAutoLaunched();
if (isAutoLaunched) {
await this.daemonService.startDaemon();
}
} catch {
this.daemonRunning = false;
}).finally(() => {
this.loading = false;
});
}
this.loading = false;
}

View file

@ -108,6 +108,8 @@ declare global {
onDisableAutoLaunchError: (callback: (event: any, error: string) => void) => void;
onDisableAutoLaunchSuccess: (callback: (event: any) => void) => void;
isAutoLaunched: () => void;
onIsAutoLaunched: (callback: (event: any, isAutoLaunched: boolean) => void) => void;
};
}
}