mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 20:01:47 +00:00
Prepare migration for sandboxing (path.join in preload)
This commit is contained in:
10
index.js
10
index.js
@ -136,12 +136,12 @@ function createMainWindow() {
|
|||||||
preload: path.join(__dirname, "preload.js"),
|
preload: path.join(__dirname, "preload.js"),
|
||||||
nodeIntegrationInSubFrames: true,
|
nodeIntegrationInSubFrames: true,
|
||||||
affinity: "main-window", // main window, and addition windows should work in one process
|
affinity: "main-window", // main window, and addition windows should work in one process
|
||||||
...(isTesting()
|
...(!isTesting()
|
||||||
? {
|
? {
|
||||||
// Only necessary when testing with Spectron
|
// Sandbox is only enabled in tests for now
|
||||||
contextIsolation: false,
|
// See https://www.electronjs.org/docs/latest/tutorial/sandbox#preload-scripts
|
||||||
nodeIntegration: true,
|
sandbox: false,
|
||||||
}
|
}
|
||||||
: undefined),
|
: undefined),
|
||||||
},
|
},
|
||||||
frame: !is.macOS() && !useInlineMenu,
|
frame: !is.macOS() && !useInlineMenu,
|
||||||
|
|||||||
@ -67,8 +67,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "playwright test",
|
"test": "NODE_ENV=test playwright test",
|
||||||
"test:debug": "DEBUG=pw:browser* playwright test",
|
"test:debug": "DEBUG=pw:browser* NODE_ENV=test playwright test",
|
||||||
"start": "electron .",
|
"start": "electron .",
|
||||||
"start:debug": "ELECTRON_ENABLE_LOGGING=1 electron .",
|
"start:debug": "ELECTRON_ENABLE_LOGGING=1 electron .",
|
||||||
"icon": "rimraf assets/generated && electron-icon-maker --input=assets/youtube-music.png --output=assets/generated",
|
"icon": "rimraf assets/generated && electron-icon-maker --input=assets/youtube-music.png --output=assets/generated",
|
||||||
|
|||||||
29
preload.js
29
preload.js
@ -1,4 +1,3 @@
|
|||||||
const path = require("path");
|
|
||||||
require("./providers/front-logger")();
|
require("./providers/front-logger")();
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
const { fileExists } = require("./plugins/utils");
|
const { fileExists } = require("./plugins/utils");
|
||||||
@ -10,14 +9,26 @@ const plugins = config.plugins.getEnabled();
|
|||||||
|
|
||||||
let api;
|
let api;
|
||||||
|
|
||||||
plugins.forEach(([plugin, options]) => {
|
plugins.forEach(async ([plugin, options]) => {
|
||||||
const preloadPath = path.join(__dirname, "plugins", plugin, "preload.js");
|
const preloadPath = await ipcRenderer.invoke(
|
||||||
|
"getPath",
|
||||||
|
__dirname,
|
||||||
|
"plugins",
|
||||||
|
plugin,
|
||||||
|
"preload.js"
|
||||||
|
);
|
||||||
fileExists(preloadPath, () => {
|
fileExists(preloadPath, () => {
|
||||||
const run = require(preloadPath);
|
const run = require(preloadPath);
|
||||||
run(options);
|
run(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
const actionPath = path.join(__dirname, "plugins", plugin, "actions.js");
|
const actionPath = await ipcRenderer.invoke(
|
||||||
|
"getPath",
|
||||||
|
__dirname,
|
||||||
|
"plugins",
|
||||||
|
plugin,
|
||||||
|
"actions.js"
|
||||||
|
);
|
||||||
fileExists(actionPath, () => {
|
fileExists(actionPath, () => {
|
||||||
const actions = require(actionPath).actions || {};
|
const actions = require(actionPath).actions || {};
|
||||||
|
|
||||||
@ -30,8 +41,14 @@ plugins.forEach(([plugin, options]) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
plugins.forEach(([plugin, options]) => {
|
plugins.forEach(async ([plugin, options]) => {
|
||||||
const pluginPath = path.join(__dirname, "plugins", plugin, "front.js");
|
const pluginPath = await ipcRenderer.invoke(
|
||||||
|
"getPath",
|
||||||
|
__dirname,
|
||||||
|
"plugins",
|
||||||
|
plugin,
|
||||||
|
"front.js"
|
||||||
|
);
|
||||||
fileExists(pluginPath, () => {
|
fileExists(pluginPath, () => {
|
||||||
const run = require(pluginPath);
|
const run = require(pluginPath);
|
||||||
run(options);
|
run(options);
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
const path = require("path");
|
||||||
|
|
||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
|
|
||||||
const { app, BrowserWindow, ipcMain, ipcRenderer } = require("electron");
|
const { app, BrowserWindow, ipcMain, ipcRenderer } = require("electron");
|
||||||
@ -11,6 +13,7 @@ module.exports.setupAppControls = () => {
|
|||||||
ipcMain.on('restart', restart);
|
ipcMain.on('restart', restart);
|
||||||
ipcMain.handle('getDownloadsFolder', () => app.getPath("downloads"));
|
ipcMain.handle('getDownloadsFolder', () => app.getPath("downloads"));
|
||||||
ipcMain.on('reload', () => BrowserWindow.getFocusedWindow().webContents.loadURL(config.get("url")));
|
ipcMain.on('reload', () => BrowserWindow.getFocusedWindow().webContents.loadURL(config.get("url")));
|
||||||
|
ipcMain.handle('getPath', (_, ...args) => path.join(...args));
|
||||||
}
|
}
|
||||||
|
|
||||||
function restart() {
|
function restart() {
|
||||||
|
|||||||
Reference in New Issue
Block a user