From 8f73b9fd5f50e46b5fb60131b77f4c7c752bfd2e Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 20 Apr 2024 14:51:33 +0200 Subject: [PATCH] Make Updater slightly more future proof - Removes the option to disable update notifications. Users really should not be outdated, so this option was never good. To disable notifications, turn on auto update - Enables auto update by default. Users keep complaining about issues while being outdated, so this should help - Update Notification now opens Updater in a modal to remove dependency on Settings patch. This makes it slightly more failsafe, it's unlikely that both modals and our settings patch break --- src/Vencord.ts | 20 ++++----- src/api/Settings.ts | 4 +- src/components/VencordSettings/UpdaterTab.tsx | 41 ++++++++++++------- .../VencordSettings/settingsStyles.css | 8 ++++ src/components/VencordSettings/shared.tsx | 6 +-- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/Vencord.ts b/src/Vencord.ts index 29e965fa0..655e76c3d 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -27,6 +27,7 @@ export { PlainSettings, Settings }; import "./utils/quickCss"; import "./webpack/patchWebpack"; +import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab"; import { StartAt } from "@utils/types"; import { get as dsGet } from "./api/DataStore"; @@ -85,7 +86,7 @@ async function init() { syncSettings(); - if (!IS_WEB) { + if (!IS_WEB && !IS_UPDATER_DISABLED) { try { const isOutdated = await checkForUpdates(); if (!isOutdated) return; @@ -103,16 +104,13 @@ async function init() { return; } - if (Settings.notifyAboutUpdates) - setTimeout(() => showNotification({ - title: "A Vencord update is available!", - body: "Click here to view the update", - permanent: true, - noPersist: true, - onClick() { - SettingsRouter.open("VencordUpdater"); - } - }), 10_000); + setTimeout(() => showNotification({ + title: "A Vencord update is available!", + body: "Click here to view the update", + permanent: true, + noPersist: true, + onClick: openUpdaterModal! + }), 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 0b7975300..696c12c28 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -29,7 +29,6 @@ import plugins from "~plugins"; const logger = new Logger("Settings"); export interface Settings { - notifyAboutUpdates: boolean; autoUpdate: boolean; autoUpdateNotification: boolean, useQuickCss: boolean; @@ -78,8 +77,7 @@ export interface Settings { } const DefaultSettings: Settings = { - notifyAboutUpdates: true, - autoUpdate: false, + autoUpdate: true, autoUpdateNotification: true, useQuickCss: true, themeLinks: [], diff --git a/src/components/VencordSettings/UpdaterTab.tsx b/src/components/VencordSettings/UpdaterTab.tsx index 0a5d1f149..680e262d8 100644 --- a/src/components/VencordSettings/UpdaterTab.tsx +++ b/src/components/VencordSettings/UpdaterTab.tsx @@ -22,6 +22,7 @@ import { Flex } from "@components/Flex"; import { Link } from "@components/Link"; import { Margins } from "@utils/margins"; import { classes } from "@utils/misc"; +import { ModalCloseButton, ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { relaunch } from "@utils/native"; import { useAwaiter } from "@utils/react"; import { changes, checkForUpdates, getRepo, isNewer, update, updateError, UpdateLogger } from "@utils/updater"; @@ -29,7 +30,7 @@ import { Alerts, Button, Card, Forms, Parser, React, Switch, Toasts } from "@web import gitHash from "~git-hash"; -import { SettingsTab, wrapTab } from "./shared"; +import { handleSettingsTabError, SettingsTab, wrapTab } from "./shared"; function withDispatcher(dispatcher: React.Dispatch>, action: () => any) { return async () => { @@ -38,21 +39,24 @@ function withDispatcher(dispatcher: React.Dispatch await action(); } catch (e: any) { UpdateLogger.error("Failed to update", e); + + let err: string; if (!e) { - var err = "An unknown error occurred (error is undefined).\nPlease try again."; + err = "An unknown error occurred (error is undefined).\nPlease try again."; } else if (e.code && e.cmd) { const { code, path, cmd, stderr } = e; if (code === "ENOENT") - var err = `Command \`${path}\` not found.\nPlease install it and try again`; + err = `Command \`${path}\` not found.\nPlease install it and try again`; else { - var err = `An error occurred while running \`${cmd}\`:\n`; + err = `An error occurred while running \`${cmd}\`:\n`; err += stderr || `Code \`${code}\`. See the console for more info`; } } else { - var err = "An unknown error occurred. See the console for more info."; + err = "An unknown error occurred. See the console for more info."; } + Alerts.show({ title: "Oops!", body: ( @@ -186,7 +190,7 @@ function Newer(props: CommonProps) { } function Updater() { - const settings = useSettings(["notifyAboutUpdates", "autoUpdate", "autoUpdateNotification"]); + const settings = useSettings(["autoUpdate", "autoUpdateNotification"]); const [repo, err, repoPending] = useAwaiter(getRepo, { fallbackValue: "Loading..." }); @@ -203,14 +207,6 @@ function Updater() { return ( Updater Settings - settings.notifyAboutUpdates = v} - note="Shows a notification on startup" - disabled={settings.autoUpdate} - > - Get notified about new updates - settings.autoUpdate = v} @@ -253,3 +249,20 @@ function Updater() { } export default IS_UPDATER_DISABLED ? null : wrapTab(Updater, "Updater"); + +export const openUpdaterModal = IS_UPDATER_DISABLED ? null : function () { + const UpdaterTab = wrapTab(Updater, "Updater"); + + try { + openModal(wrapTab((modalProps: ModalProps) => ( + + + + + + + ), "UpdaterModal")); + } catch { + handleSettingsTabError(); + } +}; diff --git a/src/components/VencordSettings/settingsStyles.css b/src/components/VencordSettings/settingsStyles.css index 01cbcd557..310dba9af 100644 --- a/src/components/VencordSettings/settingsStyles.css +++ b/src/components/VencordSettings/settingsStyles.css @@ -65,3 +65,11 @@ /* discord also sets cursor: default which prevents the cursor from showing as text */ cursor: initial; } + +.vc-updater-modal { + padding: 1.5em !important; +} + +.vc-updater-modal-close-button { + float: right; +} diff --git a/src/components/VencordSettings/shared.tsx b/src/components/VencordSettings/shared.tsx index 6dd34c46f..1c5f37d82 100644 --- a/src/components/VencordSettings/shared.tsx +++ b/src/components/VencordSettings/shared.tsx @@ -42,11 +42,11 @@ export function SettingsTab({ title, children }: PropsWithChildren<{ title: stri ); } -const onError = onlyOnce(handleComponentFailed); +export const handleSettingsTabError = onlyOnce(handleComponentFailed); -export function wrapTab(component: ComponentType, tab: string) { +export function wrapTab(component: ComponentType, tab: string) { return ErrorBoundary.wrap(component, { message: `Failed to render the ${tab} tab. If this issue persists, try using the installer to reinstall!`, - onError, + onError: handleSettingsTabError, }); }