diff --git a/src/main/constants.ts b/src/main/constants.ts index d5c5fa6..4ba59d3 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -25,3 +25,12 @@ export const MIN_WIDTH = 940; export const MIN_HEIGHT = 500; export const DEFAULT_WIDTH = 1280; export const DEFAULT_HEIGHT = 720; + +const UserAgents = { + darwin: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36", + linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36", + windows: + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" +}; + +export const UserAgent = UserAgents[process.platform] || UserAgents.windows; diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 829ae4b..7685b89 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -24,7 +24,15 @@ import type { SettingsStore } from "shared/utils/SettingsStore"; import { ICON_PATH } from "../shared/paths"; import { createAboutWindow } from "./about"; import { initArRPC } from "./arrpc"; -import { DATA_DIR, DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH, VENCORD_FILES_DIR } from "./constants"; +import { + DATA_DIR, + DEFAULT_HEIGHT, + DEFAULT_WIDTH, + MIN_HEIGHT, + MIN_WIDTH, + UserAgent, + VENCORD_FILES_DIR +} from "./constants"; import { Settings, VencordSettings } from "./settings"; import { createSplashWindow } from "./splash"; import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; @@ -416,9 +424,7 @@ function createMainWindow() { initSettingsListeners(win); initSpellCheck(win); - win.webContents.setUserAgent( - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" - ); + win.webContents.setUserAgent(UserAgent); const subdomain = Settings.store.discordBranch === "canary" || Settings.store.discordBranch === "ptb" diff --git a/src/renderer/fixes.ts b/src/renderer/fixes.ts index 4e1b1cd..ed0134f 100644 --- a/src/renderer/fixes.ts +++ b/src/renderer/fixes.ts @@ -8,7 +8,7 @@ import "./hideGarbage.css"; import { waitFor } from "@vencord/types/webpack"; -import { isFirstRun, localStorage } from "./utils"; +import { isFirstRun, isWindows, localStorage } from "./utils"; // Make clicking Notifications focus the window const originalSetOnClick = Object.getOwnPropertyDescriptor(Notification.prototype, "onclick")!.set!; @@ -31,3 +31,14 @@ if (isFirstRun) { m.setDesktopType("all"); }); } + +// FIXME: Remove eventually. +// Originally, Vencord always used a Windows user agent. This seems to cause captchas +// Now, we use a platform specific UA - HOWEVER, discord FOR SOME REASON????? caches +// device props in localStorage. This code fixes their cache to properly update the platform in SuperProps +if (!isWindows) + try { + const deviceProperties = localStorage.getItem("deviceProperties"); + if (deviceProperties && JSON.parse(deviceProperties).os === "Windows") + localStorage.removeItem("deviceProperties"); + } catch {}