Skip to content

Commit 3710723

Browse files
Apply proxy settings to the PO token web views (#6922)
1 parent 3de74bd commit 3710723

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
@@ -287,6 +287,8 @@ function runApp() {
287287
})
288288
}
289289

290+
let proxyUrl
291+
290292
app.on('ready', async (_, __) => {
291293
if (process.env.NODE_ENV === 'production') {
292294
protocol.handle('app', async (request) => {
@@ -400,8 +402,10 @@ function runApp() {
400402
}
401403

402404
if (useProxy) {
405+
proxyUrl = `${proxyProtocol}://${proxyHostname}:${proxyPort}`
406+
403407
session.defaultSession.setProxy({
404-
proxyRules: `${proxyProtocol}://${proxyHostname}:${proxyPort}`
408+
proxyRules: proxyUrl
405409
})
406410
}
407411

@@ -884,18 +888,20 @@ function runApp() {
884888
})
885889

886890
ipcMain.handle(IpcChannels.GENERATE_PO_TOKEN, (_, visitorData) => {
887-
return generatePoToken(visitorData)
891+
return generatePoToken(visitorData, proxyUrl)
888892
})
889893

890894
ipcMain.on(IpcChannels.ENABLE_PROXY, (_, url) => {
891895
session.defaultSession.setProxy({
892896
proxyRules: url
893897
})
898+
proxyUrl = url
894899
session.defaultSession.closeAllConnections()
895900
})
896901

897902
ipcMain.on(IpcChannels.DISABLE_PROXY, () => {
898903
session.defaultSession.setProxy({})
904+
proxyUrl = undefined
899905
session.defaultSession.closeAllConnections()
900906
})
901907

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)