Add additional build flavours for Vencord Desktop (#765)

This commit is contained in:
V 2023-04-04 01:16:29 +02:00 committed by GitHub
parent 5bb08bdb64
commit 6b26c12bfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 264 additions and 127 deletions

24
src/utils/native.ts Normal file
View file

@ -0,0 +1,24 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export function relaunch() {
if (IS_DISCORD_DESKTOP)
window.DiscordNative.app.relaunch();
else
window.VencordDesktop.app.relaunch();
}

View file

@ -47,7 +47,9 @@ export async function downloadSettingsBackup() {
const backup = await exportSettings();
const data = new TextEncoder().encode(backup);
if (IS_WEB) {
if (IS_DISCORD_DESKTOP) {
DiscordNative.fileManager.saveWithDialog(data, filename);
} else {
const file = new File([data], filename, { type: "application/json" });
const a = document.createElement("a");
a.href = URL.createObjectURL(file);
@ -59,8 +61,6 @@ export async function downloadSettingsBackup() {
URL.revokeObjectURL(a.href);
document.body.removeChild(a);
});
} else {
DiscordNative.fileManager.saveWithDialog(data, filename);
}
}
@ -77,7 +77,24 @@ const toastFailure = (err: any) => Toasts.show({
});
export async function uploadSettingsBackup(showToast = true): Promise<void> {
if (IS_WEB) {
if (IS_DISCORD_DESKTOP) {
const [file] = await DiscordNative.fileManager.openFiles({
filters: [
{ name: "Vencord Settings Backup", extensions: ["json"] },
{ name: "all", extensions: ["*"] }
]
});
if (file) {
try {
await importSettings(new TextDecoder().decode(file.data));
if (showToast) toastSuccess();
} catch (err) {
new Logger("SettingsSync").error(err);
if (showToast) toastFailure(err);
}
}
} else {
const input = document.createElement("input");
input.type = "file";
input.style.display = "none";
@ -102,22 +119,5 @@ export async function uploadSettingsBackup(showToast = true): Promise<void> {
document.body.appendChild(input);
input.click();
setImmediate(() => document.body.removeChild(input));
} else {
const [file] = await DiscordNative.fileManager.openFiles({
filters: [
{ name: "Vencord Settings Backup", extensions: ["json"] },
{ name: "all", extensions: ["*"] }
]
});
if (file) {
try {
await importSettings(new TextDecoder().decode(file.data));
if (showToast) toastSuccess();
} catch (err) {
new Logger("SettingsSync").error(err);
if (showToast) toastFailure(err);
}
}
}
}

View file

@ -20,6 +20,7 @@ import gitHash from "~git-hash";
import IpcEvents from "./IpcEvents";
import Logger from "./Logger";
import { relaunch } from "./native";
import { IpcRes } from "./types";
export const UpdateLogger = /* #__PURE__*/ new Logger("Updater", "white");
@ -90,8 +91,10 @@ export async function maybePromptToUpdate(confirmMessage: string, checkForDev =
if (wantsUpdate) {
await update();
const needFullRestart = await rebuild();
if (needFullRestart) DiscordNative.app.relaunch();
else location.reload();
if (needFullRestart)
relaunch();
else
location.reload();
}
}
} catch (err) {