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