Skip to content

Commit 2ef79d7

Browse files
committed
Merge branch 'fix/open-input-url-in-new-window' into custom-builds/current
* fix/open-input-url-in-new-window: ! Fix opening URL in a new window restores main window (in Windows) Translated using Weblate (Danish) Translated using Weblate (Japanese) Fix parsing grid channels without a subscriber count (FreeTubeApp#7486) Local API: Add PO tokens to the caption URLs (FreeTubeApp#7484) Add preload script and disable node integration in renderer processes (FreeTubeApp#7424)
2 parents d3c6d95 + e94b746 commit 2ef79d7

File tree

29 files changed

+595
-394
lines changed

29 files changed

+595
-394
lines changed

_scripts/dev-runner.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ const web = process.argv.indexOf('--web') !== -1
1818

1919
let mainConfig
2020
let rendererConfig
21+
let preloadConfig
2122
let botGuardScriptConfig
2223
let webConfig
2324
let SHAKA_LOCALES_TO_BE_BUNDLED
2425

2526
if (!web) {
2627
mainConfig = require('./webpack.main.config')
2728
rendererConfig = require('./webpack.renderer.config')
29+
preloadConfig = require('./webpack.preload.config.js')
2830
botGuardScriptConfig = require('./webpack.botGuardScript.config')
2931

3032
SHAKA_LOCALES_TO_BE_BUNDLED = rendererConfig.SHAKA_LOCALES_TO_BE_BUNDLED
@@ -132,6 +134,36 @@ function startMain() {
132134
})
133135
}
134136

137+
function startPreload() {
138+
const compiler = webpack(preloadConfig)
139+
const { name } = compiler
140+
141+
let firstTime = true
142+
143+
compiler.hooks.afterEmit.tap('afterEmit', async () => {
144+
console.log(`\nCompiled ${name} script!`)
145+
146+
if (firstTime) {
147+
firstTime = false
148+
} else {
149+
manualRestart = true
150+
await restartElectron()
151+
setTimeout(() => {
152+
manualRestart = false
153+
}, 2500)
154+
}
155+
156+
console.log(`\nWatching file changes for ${name} script...`)
157+
})
158+
159+
compiler.watch({
160+
aggregateTimeout: 500,
161+
},
162+
err => {
163+
if (err) console.error(err)
164+
})
165+
}
166+
135167
function startRenderer(callback) {
136168
const compiler = webpack(rendererConfig)
137169
const { name } = compiler
@@ -208,6 +240,7 @@ function startWeb () {
208240
if (!web) {
209241
startRenderer(() => {
210242
startBotGuardScript()
243+
startPreload()
211244
startMain()
212245
})
213246
} else {

_scripts/injectAllowedPaths.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const paths = readdirSync(distDirectory, {
2121
// disallow the renderer process/browser windows to read the main.js file
2222
dirent.name !== 'main.js' &&
2323
dirent.name !== 'main.js.LICENSE.txt' &&
24+
// disallow the renderer process/browser windows to read the preload.js file
25+
dirent.name !== 'preload.js' &&
2426
// disallow the renderer process/browser windows to read the botGuardScript.js file
2527
dirent.name !== 'botGuardScript.js' &&
2628
// filter out any web build files, in case the dist directory contains a web build

_scripts/webpack.preload.config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const path = require('path')
2+
3+
const isDevMode = process.env.NODE_ENV === 'development'
4+
5+
/** @type {import('webpack').Configuration} */
6+
const config = {
7+
name: 'preload',
8+
mode: process.env.NODE_ENV,
9+
devtool: isDevMode ? 'eval-cheap-module-source-map' : false,
10+
entry: {
11+
preload: path.join(__dirname, '../src/preload/main.js'),
12+
},
13+
infrastructureLogging: {
14+
// Only warnings and errors
15+
// level: 'none' disable logging
16+
// Please read https://webpack.js.org/configuration/other-options/#infrastructurelogginglevel
17+
level: isDevMode ? 'info' : 'none'
18+
},
19+
output: {
20+
path: path.join(__dirname, '../dist'),
21+
filename: '[name].js'
22+
},
23+
externals: [
24+
'electron/renderer'
25+
],
26+
externalsType: 'commonjs',
27+
node: {
28+
__dirname: false,
29+
__filename: false
30+
},
31+
target: 'electron-preload',
32+
}
33+
34+
module.exports = config

_scripts/webpack.renderer.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const config = {
3939
level: isDevMode ? 'info' : 'none'
4040
},
4141
output: {
42-
libraryTarget: 'commonjs2',
42+
scriptType: 'text/javascript',
4343
path: path.join(__dirname, '../dist'),
4444
filename: '[name].js',
4545
},
@@ -191,7 +191,7 @@ const config = {
191191
},
192192
extensions: ['.js', '.vue']
193193
},
194-
target: 'electron-renderer',
194+
target: 'web',
195195
}
196196

197197
if (isDevMode) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
"lint-style": "stylelint \"src/**/*.{css,scss}\"",
4444
"lint-style-fix": "stylelint --fix \"src/**/*.{css,scss}\"",
4545
"lint-yml": "eslint --config eslint.config.mjs \"**/*.yml\" \"**/*.yaml\"",
46-
"pack": "run-p pack:main pack:renderer pack:botGuardScript && node _scripts/injectAllowedPaths.mjs",
46+
"pack": "run-p pack:main pack:renderer pack:preload pack:botGuardScript && node _scripts/injectAllowedPaths.mjs",
4747
"pack:main": "webpack --mode=production --node-env=production --config _scripts/webpack.main.config.js",
4848
"pack:renderer": "webpack --mode=production --node-env=production --config _scripts/webpack.renderer.config.js",
49+
"pack:preload": "webpack --mode=production --node-env=production --config _scripts/webpack.preload.config.js",
4950
"pack:web": "webpack --mode=production --node-env=production --config _scripts/webpack.web.config.js",
5051
"pack:botGuardScript": "webpack --config _scripts/webpack.botGuardScript.config.js",
5152
"postinstall": "yarn run --silent patch-shaka",

src/constants.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ const IpcChannels = {
1212
APP_READY: 'app-ready',
1313
RELAUNCH_REQUEST: 'relaunch-request',
1414

15-
REQUEST_FULLSCREEN: 'request-fullscreen',
16-
REQUEST_PIP: 'request-pip',
17-
1815
SEARCH_INPUT_HANDLING_READY: 'search-input-handling-ready',
1916
UPDATE_SEARCH_INPUT_TEXT: 'update-search-input-text',
2017

0 commit comments

Comments
 (0)