diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-12-24 02:18:47 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-12-24 02:18:47 +0100 |
commit | b96cc8055d8beed39a615d60ebd2038be3e72994 (patch) | |
tree | ed584aa67b848fc8d49819ca78789d3fa3a18c32 /packages/main/src | |
parent | feat: Alternative background color workaround (diff) | |
download | sophie-b96cc8055d8beed39a615d60ebd2038be3e72994.tar.gz sophie-b96cc8055d8beed39a615d60ebd2038be3e72994.tar.zst sophie-b96cc8055d8beed39a615d60ebd2038be3e72994.zip |
refactor: Load ui and service in parallel
Diffstat (limited to 'packages/main/src')
-rw-r--r-- | packages/main/src/index.ts | 35 |
1 files changed, 18 insertions, 17 deletions
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 { | |||
40 | } from './devTools'; | 40 | } from './devTools'; |
41 | import { createRootStore } from './stores/RootStore'; | 41 | import { createRootStore } from './stores/RootStore'; |
42 | 42 | ||
43 | const isSingleInstance = app.requestSingleInstanceLock(); | ||
44 | const isDevelopment = import.meta.env.MODE === 'development'; | 43 | const isDevelopment = import.meta.env.MODE === 'development'; |
45 | 44 | ||
46 | // Use alternative directory when debugging to avoid clobbering the main installation. | 45 | // Use alternative directory when debugging to avoid clobbering the main installation. |
@@ -48,6 +47,8 @@ if (isDevelopment) { | |||
48 | app.setPath('userData', `${app.getPath('userData')}-dev`); | 47 | app.setPath('userData', `${app.getPath('userData')}-dev`); |
49 | } | 48 | } |
50 | 49 | ||
50 | // Only allow a single instance at a time. | ||
51 | const isSingleInstance = app.requestSingleInstanceLock(); | ||
51 | if (!isSingleInstance) { | 52 | if (!isSingleInstance) { |
52 | app.quit(); | 53 | app.quit(); |
53 | process.exit(0); | 54 | process.exit(0); |
@@ -56,6 +57,13 @@ if (!isSingleInstance) { | |||
56 | // Alwayse enable sandboxing. | 57 | // Alwayse enable sandboxing. |
57 | app.enableSandbox(); | 58 | app.enableSandbox(); |
58 | 59 | ||
60 | // Disable chromium's MPRIS integration, which is usually more annoying | ||
61 | // (triggered by random sounds played by websites) than useful. | ||
62 | app.commandLine.appendSwitch( | ||
63 | 'disable-features', | ||
64 | 'HardwareMediaKeyHandling,MediaSessionService', | ||
65 | ); | ||
66 | |||
59 | // Remove sophie and electron from the user-agent string to avoid detection. | 67 | // Remove sophie and electron from the user-agent string to avoid detection. |
60 | const originalUserAgent = app.userAgentFallback; | 68 | const originalUserAgent = app.userAgentFallback; |
61 | const userAgent = originalUserAgent.replaceAll(/ ([Ss]ophie|Electron)\/[0-9.]+/g, ''); | 69 | const userAgent = originalUserAgent.replaceAll(/ ([Ss]ophie|Electron)\/[0-9.]+/g, ''); |
@@ -64,13 +72,6 @@ if (!isDevelopment) { | |||
64 | app.userAgentFallback = userAgent; | 72 | app.userAgentFallback = userAgent; |
65 | } | 73 | } |
66 | 74 | ||
67 | // Disable chromium's MPRIS integration, which is usually more annoying | ||
68 | // (triggered by random sounds played by websites) than useful. | ||
69 | app.commandLine.appendSwitch( | ||
70 | 'disable-features', | ||
71 | 'HardwareMediaKeyHandling,MediaSessionService', | ||
72 | ); | ||
73 | |||
74 | if (isDevelopment) { | 75 | if (isDevelopment) { |
75 | installDevToolsExtensions(app); | 76 | installDevToolsExtensions(app); |
76 | } | 77 | } |
@@ -79,7 +80,7 @@ let mainWindow: BrowserWindow | null = null; | |||
79 | 80 | ||
80 | const store = createRootStore(); | 81 | const store = createRootStore(); |
81 | 82 | ||
82 | async function createWindow(): Promise<void> { | 83 | function createWindow(): Promise<unknown> { |
83 | mainWindow = new BrowserWindow({ | 84 | mainWindow = new BrowserWindow({ |
84 | show: false, | 85 | show: false, |
85 | autoHideMenuBar: true, | 86 | autoHideMenuBar: true, |
@@ -111,6 +112,10 @@ async function createWindow(): Promise<void> { | |||
111 | 112 | ||
112 | browserView.webContents.userAgent = userAgent; | 113 | browserView.webContents.userAgent = userAgent; |
113 | browserView.setBackgroundColor('#fff'); | 114 | browserView.setBackgroundColor('#fff'); |
115 | autorun(() => { | ||
116 | browserView.setBounds(store.shared.browserViewBounds); | ||
117 | }); | ||
118 | mainWindow.setBrowserView(browserView); | ||
114 | 119 | ||
115 | webContents.on('ipc-message', (_event, channel, ...args) => { | 120 | webContents.on('ipc-message', (_event, channel, ...args) => { |
116 | try { | 121 | try { |
@@ -166,18 +171,14 @@ async function createWindow(): Promise<void> { | |||
166 | ); | 171 | ); |
167 | }); | 172 | }); |
168 | 173 | ||
169 | autorun(() => { | ||
170 | browserView.setBounds(store.shared.browserViewBounds); | ||
171 | }); | ||
172 | |||
173 | const pageUrl = (isDevelopment && import.meta.env.VITE_DEV_SERVER_URL !== undefined) | 174 | const pageUrl = (isDevelopment && import.meta.env.VITE_DEV_SERVER_URL !== undefined) |
174 | ? import.meta.env.VITE_DEV_SERVER_URL | 175 | ? import.meta.env.VITE_DEV_SERVER_URL |
175 | : new URL('../renderer/dist/index.html', `file://${__dirname}`).toString(); | 176 | : new URL('../renderer/dist/index.html', `file://${__dirname}`).toString(); |
176 | await mainWindow.loadURL(pageUrl); | ||
177 | |||
178 | mainWindow.setBrowserView(browserView); | ||
179 | 177 | ||
180 | return browserView.webContents.loadURL('https://git.marussy.com/sophie/about'); | 178 | return Promise.all([ |
179 | mainWindow.loadURL(pageUrl), | ||
180 | browserView.webContents.loadURL('https://git.marussy.com/sophie/about'), | ||
181 | ]); | ||
181 | } | 182 | } |
182 | 183 | ||
183 | app.on('second-instance', () => { | 184 | app.on('second-instance', () => { |