Skip to content

Commit 1f5f597

Browse files
committed
Prepare migration for sandboxing (path.join in preload)
1 parent 91e4433 commit 1f5f597

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ function createMainWindow() {
136136
preload: path.join(__dirname, "preload.js"),
137137
nodeIntegrationInSubFrames: true,
138138
affinity: "main-window", // main window, and addition windows should work in one process
139-
...(isTesting()
139+
...(!isTesting()
140140
? {
141-
// Only necessary when testing with Spectron
142-
contextIsolation: false,
143-
nodeIntegration: true,
144-
}
141+
// Sandbox is only enabled in tests for now
142+
// See https://www.electronjs.org/docs/latest/tutorial/sandbox#preload-scripts
143+
sandbox: false,
144+
}
145145
: undefined),
146146
},
147147
frame: !is.macOS() && !useInlineMenu,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
}
6868
},
6969
"scripts": {
70-
"test": "playwright test",
71-
"test:debug": "DEBUG=pw:browser* playwright test",
70+
"test": "NODE_ENV=test playwright test",
71+
"test:debug": "DEBUG=pw:browser* NODE_ENV=test playwright test",
7272
"start": "electron .",
7373
"start:debug": "ELECTRON_ENABLE_LOGGING=1 electron .",
7474
"icon": "rimraf assets/generated && electron-icon-maker --input=assets/youtube-music.png --output=assets/generated",

preload.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const path = require("path");
21
require("./providers/front-logger")();
32
const config = require("./config");
43
const { fileExists } = require("./plugins/utils");
@@ -10,14 +9,26 @@ const plugins = config.plugins.getEnabled();
109

1110
let api;
1211

13-
plugins.forEach(([plugin, options]) => {
14-
const preloadPath = path.join(__dirname, "plugins", plugin, "preload.js");
12+
plugins.forEach(async ([plugin, options]) => {
13+
const preloadPath = await ipcRenderer.invoke(
14+
"getPath",
15+
__dirname,
16+
"plugins",
17+
plugin,
18+
"preload.js"
19+
);
1520
fileExists(preloadPath, () => {
1621
const run = require(preloadPath);
1722
run(options);
1823
});
1924

20-
const actionPath = path.join(__dirname, "plugins", plugin, "actions.js");
25+
const actionPath = await ipcRenderer.invoke(
26+
"getPath",
27+
__dirname,
28+
"plugins",
29+
plugin,
30+
"actions.js"
31+
);
2132
fileExists(actionPath, () => {
2233
const actions = require(actionPath).actions || {};
2334

@@ -30,8 +41,14 @@ plugins.forEach(([plugin, options]) => {
3041
});
3142

3243
document.addEventListener("DOMContentLoaded", () => {
33-
plugins.forEach(([plugin, options]) => {
34-
const pluginPath = path.join(__dirname, "plugins", plugin, "front.js");
44+
plugins.forEach(async ([plugin, options]) => {
45+
const pluginPath = await ipcRenderer.invoke(
46+
"getPath",
47+
__dirname,
48+
"plugins",
49+
plugin,
50+
"front.js"
51+
);
3552
fileExists(pluginPath, () => {
3653
const run = require(pluginPath);
3754
run(options);

providers/app-controls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require("path");
2+
13
const is = require("electron-is");
24

35
const { app, BrowserWindow, ipcMain, ipcRenderer } = require("electron");
@@ -11,6 +13,7 @@ module.exports.setupAppControls = () => {
1113
ipcMain.on('restart', restart);
1214
ipcMain.handle('getDownloadsFolder', () => app.getPath("downloads"));
1315
ipcMain.on('reload', () => BrowserWindow.getFocusedWindow().webContents.loadURL(config.get("url")));
16+
ipcMain.handle('getPath', (_, ...args) => path.join(...args));
1417
}
1518

1619
function restart() {

0 commit comments

Comments
 (0)