Make Windows Ctrl+Q feature optional; add opt-in auto update (#451)
This commit is contained in:
parent
25d32ce292
commit
b2ecb02335
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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: {}
|
||||
};
|
||||
|
||||
|
|
|
@ -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" : (
|
||||
|
|
|
@ -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>
|
||||
)}
|
||||
|
||||
|
|
|
@ -43,10 +43,16 @@ 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");
|
||||
|
||||
if (settings.winCtrlQ) {
|
||||
const originalBuild = Menu.buildFromTemplate;
|
||||
Menu.buildFromTemplate = function (template) {
|
||||
if (template[0]?.label === "&File") {
|
||||
|
@ -64,11 +70,7 @@ if (!process.argv.includes("--vanilla")) {
|
|||
return originalBuild.call(this, template);
|
||||
};
|
||||
}
|
||||
|
||||
let settings = {} as any;
|
||||
try {
|
||||
settings = JSON.parse(readSettings());
|
||||
} catch { }
|
||||
}
|
||||
|
||||
class BrowserWindow extends electron.BrowserWindow {
|
||||
constructor(options: BrowserWindowConstructorOptions) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue