mirror of
https://github.com/everoddandeven/monerod-gui.git
synced 2024-12-22 19:49:27 +00:00
AutoLaunch
This commit is contained in:
parent
8ef7794f98
commit
08c0633579
6 changed files with 62 additions and 17 deletions
16
app/main.ts
16
app/main.ts
|
@ -8,8 +8,8 @@ import * as tar from 'tar';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as pidusage from 'pidusage';
|
import * as pidusage from 'pidusage';
|
||||||
|
|
||||||
const AutoLaunch = require('auto-launch');
|
import AutoLaunch from 'auto-launch';
|
||||||
|
//const AutoLaunch = require('auto-launch');
|
||||||
|
|
||||||
interface Stats {
|
interface Stats {
|
||||||
/**
|
/**
|
||||||
|
@ -61,9 +61,13 @@ if (!gotInstanceLock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const autoLauncher = new AutoLaunch({
|
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;
|
let win: BrowserWindow | null = null;
|
||||||
|
@ -581,6 +585,12 @@ try {
|
||||||
})
|
})
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
|
ipcMain.handle('is-auto-launched', (event: IpcMainInvokeEvent) => {
|
||||||
|
console.debug(event);
|
||||||
|
|
||||||
|
win?.webContents.send('on-is-auto-launched', isAutoLaunched);
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.handle('quit', (event) => {
|
ipcMain.handle('quit', (event) => {
|
||||||
isQuitting = true;
|
isQuitting = true;
|
||||||
app.quit();
|
app.quit();
|
||||||
|
|
|
@ -111,5 +111,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
},
|
},
|
||||||
onIsAppImage: (callback) => {
|
onIsAppImage: (callback) => {
|
||||||
ipcRenderer.on('on-is-app-image', 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
7
package-lock.json
generated
|
@ -45,6 +45,7 @@
|
||||||
"@ngx-translate/core": "15.0.0",
|
"@ngx-translate/core": "15.0.0",
|
||||||
"@ngx-translate/http-loader": "8.0.0",
|
"@ngx-translate/http-loader": "8.0.0",
|
||||||
"@playwright/test": "1.43.1",
|
"@playwright/test": "1.43.1",
|
||||||
|
"@types/auto-launch": "5.0.5",
|
||||||
"@types/bootstrap": "5.2.10",
|
"@types/bootstrap": "5.2.10",
|
||||||
"@types/chart.js": "2.9.41",
|
"@types/chart.js": "2.9.41",
|
||||||
"@types/jest": "29.5.13",
|
"@types/jest": "29.5.13",
|
||||||
|
@ -6261,6 +6262,12 @@
|
||||||
"url": "https://github.com/sponsors/isaacs"
|
"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": {
|
"node_modules/@types/babel__core": {
|
||||||
"version": "7.20.5",
|
"version": "7.20.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
"@ngx-translate/core": "15.0.0",
|
"@ngx-translate/core": "15.0.0",
|
||||||
"@ngx-translate/http-loader": "8.0.0",
|
"@ngx-translate/http-loader": "8.0.0",
|
||||||
"@playwright/test": "1.43.1",
|
"@playwright/test": "1.43.1",
|
||||||
|
"@types/auto-launch": "5.0.5",
|
||||||
"@types/bootstrap": "5.2.10",
|
"@types/bootstrap": "5.2.10",
|
||||||
"@types/chart.js": "2.9.41",
|
"@types/chart.js": "2.9.41",
|
||||||
"@types/jest": "29.5.13",
|
"@types/jest": "29.5.13",
|
||||||
|
|
|
@ -12,8 +12,8 @@ import { LogsService } from './pages/logs/logs.service';
|
||||||
styleUrls: ['./app.component.scss']
|
styleUrls: ['./app.component.scss']
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
public loading: boolean;
|
public loading: boolean = false;
|
||||||
public daemonRunning: boolean;
|
public daemonRunning: boolean = false;
|
||||||
|
|
||||||
public get initializing(): boolean {
|
public get initializing(): boolean {
|
||||||
return this.daemonData.initializing;
|
return this.daemonData.initializing;
|
||||||
|
@ -38,23 +38,42 @@ export class AppComponent {
|
||||||
console.log('Run in browser');
|
console.log('Run in browser');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = false;
|
|
||||||
this.daemonRunning = false;
|
|
||||||
this.load();
|
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.loading = true;
|
||||||
|
|
||||||
this.daemonService.isRunning().then((running: boolean) => {
|
try {
|
||||||
this.daemonRunning = running;
|
this.daemonRunning = await this.daemonService.isRunning(true);
|
||||||
this.loading;
|
|
||||||
}).catch((error) => {
|
const isAutoLaunched = await this.isAutoLaunched();
|
||||||
console.error(error);
|
|
||||||
|
if (isAutoLaunched) {
|
||||||
|
await this.daemonService.startDaemon();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch {
|
||||||
this.daemonRunning = false;
|
this.daemonRunning = false;
|
||||||
}).finally(() => {
|
}
|
||||||
this.loading = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,9 @@ declare global {
|
||||||
disableAutoLaunch: () => void;
|
disableAutoLaunch: () => void;
|
||||||
onDisableAutoLaunchError: (callback: (event: any, error: string) => void) => void;
|
onDisableAutoLaunchError: (callback: (event: any, error: string) => void) => void;
|
||||||
onDisableAutoLaunchSuccess: (callback: (event: any) => void) => void;
|
onDisableAutoLaunchSuccess: (callback: (event: any) => void) => void;
|
||||||
|
|
||||||
|
isAutoLaunched: () => void;
|
||||||
|
onIsAutoLaunched: (callback: (event: any, isAutoLaunched: boolean) => void) => void;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue