From b96cc8055d8beed39a615d60ebd2038be3e72994 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 24 Dec 2021 02:18:47 +0100 Subject: refactor: Load ui and service in parallel --- packages/main/src/index.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'packages/main') diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index 617a8dd..4308d55 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -40,7 +40,6 @@ import { } from './devTools'; import { createRootStore } from './stores/RootStore'; -const isSingleInstance = app.requestSingleInstanceLock(); const isDevelopment = import.meta.env.MODE === 'development'; // Use alternative directory when debugging to avoid clobbering the main installation. @@ -48,6 +47,8 @@ if (isDevelopment) { app.setPath('userData', `${app.getPath('userData')}-dev`); } +// Only allow a single instance at a time. +const isSingleInstance = app.requestSingleInstanceLock(); if (!isSingleInstance) { app.quit(); process.exit(0); @@ -56,6 +57,13 @@ if (!isSingleInstance) { // Alwayse enable sandboxing. app.enableSandbox(); +// Disable chromium's MPRIS integration, which is usually more annoying +// (triggered by random sounds played by websites) than useful. +app.commandLine.appendSwitch( + 'disable-features', + 'HardwareMediaKeyHandling,MediaSessionService', +); + // Remove sophie and electron from the user-agent string to avoid detection. const originalUserAgent = app.userAgentFallback; const userAgent = originalUserAgent.replaceAll(/ ([Ss]ophie|Electron)\/[0-9.]+/g, ''); @@ -64,13 +72,6 @@ if (!isDevelopment) { app.userAgentFallback = userAgent; } -// Disable chromium's MPRIS integration, which is usually more annoying -// (triggered by random sounds played by websites) than useful. -app.commandLine.appendSwitch( - 'disable-features', - 'HardwareMediaKeyHandling,MediaSessionService', -); - if (isDevelopment) { installDevToolsExtensions(app); } @@ -79,7 +80,7 @@ let mainWindow: BrowserWindow | null = null; const store = createRootStore(); -async function createWindow(): Promise { +function createWindow(): Promise { mainWindow = new BrowserWindow({ show: false, autoHideMenuBar: true, @@ -111,6 +112,10 @@ async function createWindow(): Promise { browserView.webContents.userAgent = userAgent; browserView.setBackgroundColor('#fff'); + autorun(() => { + browserView.setBounds(store.shared.browserViewBounds); + }); + mainWindow.setBrowserView(browserView); webContents.on('ipc-message', (_event, channel, ...args) => { try { @@ -166,18 +171,14 @@ async function createWindow(): Promise { ); }); - autorun(() => { - browserView.setBounds(store.shared.browserViewBounds); - }); - const pageUrl = (isDevelopment && import.meta.env.VITE_DEV_SERVER_URL !== undefined) ? import.meta.env.VITE_DEV_SERVER_URL : new URL('../renderer/dist/index.html', `file://${__dirname}`).toString(); - await mainWindow.loadURL(pageUrl); - - mainWindow.setBrowserView(browserView); - return browserView.webContents.loadURL('https://git.marussy.com/sophie/about'); + return Promise.all([ + mainWindow.loadURL(pageUrl), + browserView.webContents.loadURL('https://git.marussy.com/sophie/about'), + ]); } app.on('second-instance', () => { -- cgit v1.2.3-54-g00ecf