Replace update notices with notifications (#558)

This commit is contained in:
Xinto 2023-03-19 13:21:26 +04:00 committed by GitHub
parent ea642d9e90
commit 4aff11421f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 20 deletions

View file

@ -27,7 +27,7 @@ export { PlainSettings, Settings };
import "./utils/quickCss"; import "./utils/quickCss";
import "./webpack/patchWebpack"; import "./webpack/patchWebpack";
import { popNotice, showNotice } from "./api/Notices"; import { showNotification } from "./api/Notifications";
import { PlainSettings, Settings } from "./api/settings"; import { PlainSettings, Settings } from "./api/settings";
import { patches, PMLogger, startAllPlugins } from "./plugins"; import { patches, PMLogger, startAllPlugins } from "./plugins";
import { checkForUpdates, rebuild, update, UpdateLogger } from "./utils/updater"; import { checkForUpdates, rebuild, update, UpdateLogger } from "./utils/updater";
@ -49,32 +49,30 @@ async function init() {
if (Settings.autoUpdate) { if (Settings.autoUpdate) {
await update(); await update();
const needsFullRestart = await rebuild(); const needsFullRestart = await rebuild();
setTimeout(() => { if (Settings.autoUpdateNotification)
showNotice( showNotification({
"Vencord has been updated!", title: "Vencord has been updated!",
"Restart", body: "Click here to restart",
() => { permanent: true,
onClick() {
if (needsFullRestart) if (needsFullRestart)
window.DiscordNative.app.relaunch(); window.DiscordNative.app.relaunch();
else else
location.reload(); location.reload();
} }
); });
}, 10_000);
return; return;
} }
if (Settings.notifyAboutUpdates) if (Settings.notifyAboutUpdates)
setTimeout(() => { showNotification({
showNotice( title: "A Vencord update is available!",
"A Vencord update is available!", body: "Click here to view the update",
"View Update", permanent: true,
() => { onClick() {
popNotice();
SettingsRouter.open("VencordUpdater"); SettingsRouter.open("VencordUpdater");
} }
); });
}, 10_000);
} catch (err) { } catch (err) {
UpdateLogger.error("Failed to check for updates", err); UpdateLogger.error("Failed to check for updates", err);
} }

View file

@ -28,6 +28,7 @@ const logger = new Logger("Settings");
export interface Settings { export interface Settings {
notifyAboutUpdates: boolean; notifyAboutUpdates: boolean;
autoUpdate: boolean; autoUpdate: boolean;
autoUpdateNotification: boolean,
useQuickCss: boolean; useQuickCss: boolean;
enableReactDevtools: boolean; enableReactDevtools: boolean;
themeLinks: string[]; themeLinks: string[];
@ -52,6 +53,7 @@ export interface Settings {
const DefaultSettings: Settings = { const DefaultSettings: Settings = {
notifyAboutUpdates: true, notifyAboutUpdates: true,
autoUpdate: false, autoUpdate: false,
autoUpdateNotification: true,
useQuickCss: true, useQuickCss: true,
themeLinks: [], themeLinks: [],
enableReactDevtools: false, enableReactDevtools: false,

View file

@ -185,7 +185,7 @@ function Newer(props: CommonProps) {
} }
function Updater() { function Updater() {
const settings = useSettings(["notifyAboutUpdates", "autoUpdate"]); const settings = useSettings(["notifyAboutUpdates", "autoUpdate", "autoUpdateNotification"]);
const [repo, err, repoPending] = useAwaiter(getRepo, { fallbackValue: "Loading..." }); const [repo, err, repoPending] = useAwaiter(getRepo, { fallbackValue: "Loading..." });
@ -205,7 +205,7 @@ function Updater() {
<Switch <Switch
value={settings.notifyAboutUpdates} value={settings.notifyAboutUpdates}
onChange={(v: boolean) => settings.notifyAboutUpdates = v} onChange={(v: boolean) => settings.notifyAboutUpdates = v}
note="Shows a toast on startup" note="Shows a notification on startup"
disabled={settings.autoUpdate} disabled={settings.autoUpdate}
> >
Get notified about new updates Get notified about new updates
@ -217,6 +217,14 @@ function Updater() {
> >
Automatically update Automatically update
</Switch> </Switch>
<Switch
value={settings.autoUpdateNotification}
onChange={(v: boolean) => settings.autoUpdateNotification = v}
note="Shows a notification when Vencord automatically updates"
disabled={!settings.autoUpdate}
>
Get notified when an automatic update completes
</Switch>
<Forms.FormTitle tag="h5">Repo</Forms.FormTitle> <Forms.FormTitle tag="h5">Repo</Forms.FormTitle>