Skip to content

Commit

Permalink
Merge pull request #595 from Araxeus/useragent-option
Browse files Browse the repository at this point in the history
make useragent override optional
  • Loading branch information
th-ch authored Feb 9, 2022
2 parents 621c5de + 465e8e1 commit 5c7d612
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
43 changes: 22 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,30 +221,31 @@ function createMainWindow() {
}

app.once("browser-window-created", (event, win) => {
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
const originalUserAgent = win.webContents.userAgent;
const userAgents = {
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; 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;
if (config.get("options.overrideUserAgent")) {
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
const originalUserAgent = win.webContents.userAgent;
const userAgents = {
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; 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",
}

win.webContents.userAgent = updatedUserAgent;
app.userAgentFallback = updatedUserAgent;
const updatedUserAgent =
is.macOS() ? userAgents.mac :
is.windows() ? userAgents.windows :
userAgents.linux;

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 });
});
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);
loadPlugins(win);
Expand Down
8 changes: 8 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ const mainMenuTemplate = (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",
type: "checkbox",
Expand Down

0 comments on commit 5c7d612

Please sign in to comment.