mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Merge pull request #595 from Araxeus/useragent-option
make useragent override optional
This commit is contained in:
45
index.js
45
index.js
@ -221,30 +221,31 @@ function createMainWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.once("browser-window-created", (event, win) => {
|
app.once("browser-window-created", (event, win) => {
|
||||||
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
|
if (config.get("options.overrideUserAgent")) {
|
||||||
const originalUserAgent = win.webContents.userAgent;
|
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
|
||||||
const userAgents = {
|
const originalUserAgent = win.webContents.userAgent;
|
||||||
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; rv:95.0) Gecko/20100101 Firefox/95.0",
|
const userAgents = {
|
||||||
windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; rv:95.0) Gecko/20100101 Firefox/95.0",
|
||||||
linux: "Mozilla/5.0 (Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
||||||
}
|
linux: "Mozilla/5.0 (Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
||||||
|
|
||||||
const updatedUserAgent =
|
|
||||||
is.macOS() ? userAgents.mac :
|
|
||||||
is.windows() ? userAgents.windows :
|
|
||||||
userAgents.linux;
|
|
||||||
|
|
||||||
win.webContents.userAgent = updatedUserAgent;
|
|
||||||
app.userAgentFallback = updatedUserAgent;
|
|
||||||
|
|
||||||
win.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => {
|
|
||||||
// this will only happen if login failed, and "retry" was pressed
|
|
||||||
if (win.webContents.getURL().startsWith("https://accounts.google.com") && details.url.startsWith("https://accounts.google.com")){
|
|
||||||
details.requestHeaders["User-Agent"] = originalUserAgent;
|
|
||||||
}
|
}
|
||||||
cb({ requestHeaders: details.requestHeaders });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
const updatedUserAgent =
|
||||||
|
is.macOS() ? userAgents.mac :
|
||||||
|
is.windows() ? userAgents.windows :
|
||||||
|
userAgents.linux;
|
||||||
|
|
||||||
|
win.webContents.userAgent = updatedUserAgent;
|
||||||
|
app.userAgentFallback = updatedUserAgent;
|
||||||
|
|
||||||
|
win.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => {
|
||||||
|
// this will only happen if login failed, and "retry" was pressed
|
||||||
|
if (win.webContents.getURL().startsWith("https://accounts.google.com") && details.url.startsWith("https://accounts.google.com")) {
|
||||||
|
details.requestHeaders["User-Agent"] = originalUserAgent;
|
||||||
|
}
|
||||||
|
cb({ requestHeaders: details.requestHeaders });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setupSongInfo(win);
|
setupSongInfo(win);
|
||||||
loadPlugins(win);
|
loadPlugins(win);
|
||||||
|
|||||||
8
menu.js
8
menu.js
@ -187,6 +187,14 @@ const mainMenuTemplate = (win) => {
|
|||||||
setProxy(item, win);
|
setProxy(item, win);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Override useragent",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: config.get("options.overrideUserAgent"),
|
||||||
|
click: (item) => {
|
||||||
|
config.setMenuOption("options.overrideUserAgent", item.checked);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "Disable hardware acceleration",
|
label: "Disable hardware acceleration",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
|
|||||||
Reference in New Issue
Block a user