diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Vencord.ts | 26 | ||||
-rw-r--r-- | src/api/settings.ts | 4 | ||||
-rw-r--r-- | src/components/VencordSettings/Updater.tsx | 22 | ||||
-rw-r--r-- | src/components/VencordSettings/VencordTab.tsx | 21 | ||||
-rw-r--r-- | src/patcher.ts | 42 | ||||
-rw-r--r-- | src/utils/updater.ts | 2 |
6 files changed, 84 insertions, 33 deletions
diff --git a/src/Vencord.ts b/src/Vencord.ts index 48e628f..82d5af0 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -30,7 +30,7 @@ import "./webpack/patchWebpack"; import { popNotice, showNotice } from "./api/Notices"; import { PlainSettings, Settings } from "./api/settings"; import { patches, PMLogger, startAllPlugins } from "./plugins"; -import { checkForUpdates, UpdateLogger } from "./utils/updater"; +import { checkForUpdates, rebuild, update, UpdateLogger } from "./utils/updater"; import { onceReady } from "./webpack"; import { Router } from "./webpack/common"; @@ -44,7 +44,27 @@ async function init() { if (!IS_WEB) { try { const isOutdated = await checkForUpdates(); - if (isOutdated && Settings.notifyAboutUpdates) + if (!isOutdated) return; + + if (Settings.autoUpdate) { + await update(); + const needsFullRestart = await rebuild(); + setTimeout(() => { + showNotice( + "Vencord has been updated!", + "Restart", + () => { + if (needsFullRestart) + window.DiscordNative.app.relaunch(); + else + location.reload(); + } + ); + }, 10_000); + return; + } + + if (Settings.notifyAboutUpdates) setTimeout(() => { showNotice( "A Vencord update is available!", @@ -54,7 +74,7 @@ async function init() { Router.open("VencordUpdater"); } ); - }, 10000); + }, 10_000); } catch (err) { UpdateLogger.error("Failed to check for updates", err); } diff --git a/src/api/settings.ts b/src/api/settings.ts index 9bae8b7..4cdb24b 100644 --- a/src/api/settings.ts +++ b/src/api/settings.ts @@ -27,10 +27,12 @@ import plugins from "~plugins"; const logger = new Logger("Settings"); export interface Settings { notifyAboutUpdates: boolean; + autoUpdate: boolean; useQuickCss: boolean; enableReactDevtools: boolean; themeLinks: string[]; frameless: boolean; + winCtrlQ: boolean; plugins: { [plugin: string]: { enabled: boolean; @@ -41,10 +43,12 @@ export interface Settings { const DefaultSettings: Settings = { notifyAboutUpdates: true, + autoUpdate: false, useQuickCss: true, themeLinks: [], enableReactDevtools: false, frameless: false, + winCtrlQ: false, plugins: {} }; diff --git a/src/components/VencordSettings/Updater.tsx b/src/components/VencordSettings/Updater.tsx index dea8766..8a126a8 100644 --- a/src/components/VencordSettings/Updater.tsx +++ b/src/components/VencordSettings/Updater.tsx @@ -16,6 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { useSettings } from "@api/settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { ErrorCard } from "@components/ErrorCard"; import { Flex } from "@components/Flex"; @@ -23,7 +24,7 @@ import { handleComponentFailed } from "@components/handleComponentFailed"; import { Link } from "@components/Link"; import { classes, useAwaiter } from "@utils/misc"; import { changes, checkForUpdates, getRepo, isNewer, rebuild, update, updateError, UpdateLogger } from "@utils/updater"; -import { Alerts, Button, Card, Forms, Margins, Parser, React, Toasts } from "@webpack/common"; +import { Alerts, Button, Card, Forms, Margins, Parser, React, Switch, Toasts } from "@webpack/common"; import gitHash from "~git-hash"; @@ -183,6 +184,8 @@ function Newer(props: CommonProps) { } function Updater() { + const settings = useSettings(["notifyAboutUpdates", "autoUpdate"]); + const [repo, err, repoPending] = useAwaiter(getRepo, { fallbackValue: "Loading..." }); React.useEffect(() => { @@ -197,6 +200,23 @@ function Updater() { return ( <Forms.FormSection> + <Forms.FormTitle tag="h5">Updater Settings</Forms.FormTitle> + <Switch + value={settings.notifyAboutUpdates} + onChange={(v: boolean) => settings.notifyAboutUpdates = v} + note="Shows a toast on startup" + disabled={settings.autoUpdate} + > + Get notified about new updates + </Switch> + <Switch + value={settings.autoUpdate} + onChange={(v: boolean) => settings.autoUpdate = v} + note="Automatically update Vencord without confirmation prompt" + > + Automatically update + </Switch> + <Forms.FormTitle tag="h5">Repo</Forms.FormTitle> <Forms.FormText>{repoPending ? repo : err ? "Failed to retrieve - check console" : ( diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index 9429cdd..5da4442 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -97,21 +97,26 @@ function VencordSettings() { <Switch value={settings.enableReactDevtools} onChange={(v: boolean) => settings.enableReactDevtools = v} - note="Requires a full restart"> + note="Requires a full restart" + > Enable React Developer Tools </Switch> <Switch - value={settings.notifyAboutUpdates} - onChange={(v: boolean) => settings.notifyAboutUpdates = v} - note="Shows a toast on startup"> - Get notified about new updates - </Switch> - <Switch value={settings.frameless} onChange={(v: boolean) => settings.frameless = v} - note="Requires a full restart"> + note="Requires a full restart" + > Disable the window frame </Switch> + {navigator.platform.toLowerCase().startsWith("win") && ( + <Switch + value={settings.winCtrlQ} + onChange={(v: boolean) => settings.winCtrlQ = v} + note="Requires a full restart" + > + Register Ctrl+Q as shortcut to close Discord (Alternative to Alt+F4) + </Switch> + )} </React.Fragment> )} diff --git a/src/patcher.ts b/src/patcher.ts index 82fc233..2da404f 100644 --- a/src/patcher.ts +++ b/src/patcher.ts @@ -43,33 +43,35 @@ require.main!.filename = join(asarPath, discordPkg.main); app.setAppPath(asarPath); if (!process.argv.includes("--vanilla")) { + let settings: typeof import("@api/settings").Settings = {} as any; + try { + settings = JSON.parse(readSettings()); + } catch { } + // Repatch after host updates on Windows if (process.platform === "win32") { require("./patchWin32Updater"); - const originalBuild = Menu.buildFromTemplate; - Menu.buildFromTemplate = function (template) { - if (template[0]?.label === "&File") { - const { submenu } = template[0]; - if (Array.isArray(submenu)) { - submenu.push({ - label: "Quit (Hidden)", - visible: false, - acceleratorWorksWhenHidden: true, - accelerator: "Control+Q", - click: () => app.quit() - }); + if (settings.winCtrlQ) { + const originalBuild = Menu.buildFromTemplate; + Menu.buildFromTemplate = function (template) { + if (template[0]?.label === "&File") { + const { submenu } = template[0]; + if (Array.isArray(submenu)) { + submenu.push({ + label: "Quit (Hidden)", + visible: false, + acceleratorWorksWhenHidden: true, + accelerator: "Control+Q", + click: () => app.quit() + }); + } } - } - return originalBuild.call(this, template); - }; + return originalBuild.call(this, template); + }; + } } - let settings = {} as any; - try { - settings = JSON.parse(readSettings()); - } catch { } - class BrowserWindow extends electron.BrowserWindow { constructor(options: BrowserWindowConstructorOptions) { if (options?.webPreferences?.preload && options.title) { diff --git a/src/utils/updater.ts b/src/utils/updater.ts index 04205a5..9fdec47 100644 --- a/src/utils/updater.ts +++ b/src/utils/updater.ts @@ -22,7 +22,7 @@ import IpcEvents from "./IpcEvents"; import Logger from "./Logger"; import { IpcRes } from "./types"; -export const UpdateLogger = new Logger("Updater", "white"); +export const UpdateLogger = /* #__PURE__*/ new Logger("Updater", "white"); export let isOutdated = false; export let isNewer = false; export let updateError: any; |