mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-04-24 15:07:05 -05:00
Prevent multiple instances and don't quit when all windows are closed
This commit is contained in:
parent
d54ba360cf
commit
7e5988685d
|
|
@ -2,4 +2,4 @@ const electron = require('electron');
|
|||
|
||||
// Do anything that must be run before the app is ready...
|
||||
|
||||
electron.app.whenReady().then(() => import('./index.js'));
|
||||
electron.app.whenReady().then(() => import('./index.js')).then(m => m.init.call(null));
|
||||
|
|
|
|||
|
|
@ -57,7 +57,14 @@ export class App {
|
|||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
export async function init() {
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
debug('Failed to acquire single instance lock');
|
||||
console.warn('Failed to acquire single instance lock. Another instance of the app is running and will be focused.');
|
||||
setTimeout(() => app.quit(), 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
dotenvExpand.expand(dotenv.config({
|
||||
path: path.join(paths.data, '.env'),
|
||||
}));
|
||||
|
|
@ -80,7 +87,15 @@ app.whenReady().then(async () => {
|
|||
const menu = new MenuApp(appinstance);
|
||||
appinstance.menu = menu;
|
||||
|
||||
app.on('second-instance', (event, command_line, working_directory, additional_data) => {
|
||||
debug('Second instance', command_line, working_directory, additional_data);
|
||||
|
||||
appinstance.showMainWindow();
|
||||
});
|
||||
|
||||
app.on('open-url', (event, url) => {
|
||||
debug('Open URL', url);
|
||||
|
||||
if (url.match(/^com\.nintendo\.znca:\/\/(znca\/)game\/(\d+)\/?($|\?|\#)/i)) {
|
||||
handleOpenWebServiceUri(appinstance.store, url);
|
||||
event.preventDefault();
|
||||
|
|
@ -95,11 +110,7 @@ app.whenReady().then(async () => {
|
|||
debug('App started');
|
||||
|
||||
appinstance.showMainWindow();
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit();
|
||||
});
|
||||
}
|
||||
|
||||
class Updater {
|
||||
private _cache: UpdateCacheData | null = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user