Skip to content

Commit 545c2f7

Browse files
authored
Apply proxy settings to the PO token web views (#6922)
1 parent 7584ae4 commit 545c2f7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ function runApp() {
289289
})
290290
}
291291

292+
let proxyUrl
293+
292294
app.on('ready', async (_, __) => {
293295
if (process.env.NODE_ENV === 'production') {
294296
protocol.handle('app', async (request) => {
@@ -402,8 +404,10 @@ function runApp() {
402404
}
403405

404406
if (useProxy) {
407+
proxyUrl = `${proxyProtocol}://${proxyHostname}:${proxyPort}`
408+
405409
session.defaultSession.setProxy({
406-
proxyRules: `${proxyProtocol}://${proxyHostname}:${proxyPort}`
410+
proxyRules: proxyUrl
407411
})
408412
}
409413

@@ -898,18 +902,20 @@ function runApp() {
898902
})
899903

900904
ipcMain.handle(IpcChannels.GENERATE_PO_TOKEN, (_, visitorData) => {
901-
return generatePoToken(visitorData)
905+
return generatePoToken(visitorData, proxyUrl)
902906
})
903907

904908
ipcMain.on(IpcChannels.ENABLE_PROXY, (_, url) => {
905909
session.defaultSession.setProxy({
906910
proxyRules: url
907911
})
912+
proxyUrl = url
908913
session.defaultSession.closeAllConnections()
909914
})
910915

911916
ipcMain.on(IpcChannels.DISABLE_PROXY, () => {
912917
session.defaultSession.setProxy({})
918+
proxyUrl = undefined
913919
session.defaultSession.closeAllConnections()
914920
})
915921

src/main/poTokenGenerator.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import { join } from 'path'
1010
* as the BotGuard stuff accesses the global `document` and `window` objects and also requires making some requests.
1111
* So we definitely don't want it running in the same places as the rest of the FreeTube code with the user data.
1212
* @param {string} visitorData
13+
* @param {string|undefined} proxyUrl
1314
* @returns {Promise<string>}
1415
*/
15-
export async function generatePoToken(visitorData) {
16+
export async function generatePoToken(visitorData, proxyUrl) {
1617
const sessionUuid = crypto.randomUUID()
1718

1819
const theSession = session.fromPartition(`potoken-${sessionUuid}`, { cache: false })
@@ -28,6 +29,12 @@ export async function generatePoToken(visitorData) {
2829
.join(' ')
2930
)
3031

32+
if (proxyUrl) {
33+
await theSession.setProxy({
34+
proxyRules: proxyUrl
35+
})
36+
}
37+
3138
const webContentsView = new WebContentsView({
3239
webPreferences: {
3340
backgroundThrottling: false,

0 commit comments

Comments
 (0)