aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/index.ts')
-rw-r--r--packages/main/src/index.ts38
1 files changed, 21 insertions, 17 deletions
diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts
index 7c7be35..f8b6787 100644
--- a/packages/main/src/index.ts
+++ b/packages/main/src/index.ts
@@ -50,6 +50,9 @@ import { createMainStore } from './stores/MainStore';
50 50
51const isDevelopment = import.meta.env.MODE === 'development'; 51const isDevelopment = import.meta.env.MODE === 'development';
52 52
53// Alwayse enable sandboxing.
54app.enableSandbox();
55
53// Use alternative directory when debugging to avoid clobbering the main installation. 56// Use alternative directory when debugging to avoid clobbering the main installation.
54if (isDevelopment) { 57if (isDevelopment) {
55 app.setPath('userData', `${app.getPath('userData')}-dev`); 58 app.setPath('userData', `${app.getPath('userData')}-dev`);
@@ -62,9 +65,6 @@ if (!isSingleInstance) {
62 process.exit(0); 65 process.exit(0);
63} 66}
64 67
65// Alwayse enable sandboxing.
66app.enableSandbox();
67
68// Disable chromium's MPRIS integration, which is usually more annoying 68// Disable chromium's MPRIS integration, which is usually more annoying
69// (triggered by random sounds played by websites) than useful. 69// (triggered by random sounds played by websites) than useful.
70app.commandLine.appendSwitch( 70app.commandLine.appendSwitch(
@@ -90,17 +90,13 @@ function getResourceUrl(relativePath: string): string {
90 return new URL(relativePath, baseUrl).toString(); 90 return new URL(relativePath, baseUrl).toString();
91} 91}
92 92
93let serviceInjectRelativePath = '../../service-inject/dist/index.cjs'; 93let serviceInjectRelativePath = '../../service-inject/dist/index.js';
94let serviceInjectPath = getResourcePath(serviceInjectRelativePath); 94let serviceInjectPath = getResourcePath(serviceInjectRelativePath);
95let serviceInject: WebSource = { 95let serviceInject: WebSource = {
96 code: readFileSync(serviceInjectPath, 'utf8'), 96 code: readFileSync(serviceInjectPath, 'utf8'),
97 url: getResourceUrl(serviceInjectRelativePath), 97 url: getResourceUrl(serviceInjectRelativePath),
98}; 98};
99 99
100if (isDevelopment) {
101 installDevToolsExtensions(app);
102}
103
104let mainWindow: BrowserWindow | null = null; 100let mainWindow: BrowserWindow | null = null;
105 101
106const store = createMainStore(); 102const store = createMainStore();
@@ -134,13 +130,13 @@ function shouldCancelMainWindowRequest(url: string, method: string): boolean {
134 return !normalizedUrl.startsWith(getResourceUrl(rendererBaseUrl)); 130 return !normalizedUrl.startsWith(getResourceUrl(rendererBaseUrl));
135} 131}
136 132
137function createWindow(): Promise<unknown> { 133async function createWindow(): Promise<unknown> {
138 mainWindow = new BrowserWindow({ 134 mainWindow = new BrowserWindow({
139 show: false, 135 show: false,
140 autoHideMenuBar: true, 136 autoHideMenuBar: true,
141 webPreferences: { 137 webPreferences: {
142 devTools: isDevelopment,
143 sandbox: true, 138 sandbox: true,
139 devTools: isDevelopment,
144 preload: getResourcePath('../../preload/dist/index.cjs'), 140 preload: getResourcePath('../../preload/dist/index.cjs'),
145 }, 141 },
146 }); 142 });
@@ -159,8 +155,14 @@ function createWindow(): Promise<unknown> {
159 }) 155 })
160 }); 156 });
161 157
162 webContents.on('will-navigate', (event) => { 158 const pageUrl = (isDevelopment && import.meta.env.VITE_DEV_SERVER_URL !== undefined)
163 event.preventDefault(); 159 ? import.meta.env.VITE_DEV_SERVER_URL
160 : getResourceUrl('../renderer/dist/index.html');
161
162 webContents.on('will-navigate', (event, url) => {
163 if (url !== pageUrl) {
164 event.preventDefault();
165 }
164 }); 166 });
165 167
166 webContents.setWindowOpenHandler(() => ({ action: 'deny' })); 168 webContents.setWindowOpenHandler(() => ({ action: 'deny' }));
@@ -279,10 +281,6 @@ function createWindow(): Promise<unknown> {
279 callback({ requestHeaders }); 281 callback({ requestHeaders });
280 }); 282 });
281 283
282 const pageUrl = (isDevelopment && import.meta.env.VITE_DEV_SERVER_URL !== undefined)
283 ? import.meta.env.VITE_DEV_SERVER_URL
284 : getResourceUrl('../renderer/dist/index.html');
285
286 return Promise.all([ 284 return Promise.all([
287 mainWindow.loadURL(pageUrl), 285 mainWindow.loadURL(pageUrl),
288 browserView.webContents.loadURL('https://git.marussy.com/sophie/about'), 286 browserView.webContents.loadURL('https://git.marussy.com/sophie/about'),
@@ -307,7 +305,13 @@ app.on('window-all-closed', () => {
307 } 305 }
308}); 306});
309 307
310app.whenReady().then(createWindow).catch((err) => { 308app.whenReady().then(async () => {
309 if (isDevelopment) {
310 await installDevToolsExtensions();
311 }
312
313 return createWindow();
314}).catch((err) => {
311 console.error('Failed to create window', err); 315 console.error('Failed to create window', err);
312 process.exit(1); 316 process.exit(1);
313}); 317});