aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-04-04 01:16:29 +0200
committerGitHub <noreply@github.com>2023-04-04 01:16:29 +0200
commit6b26c12bfa1f28d40834478b50d2f7b09c9f54fb (patch)
tree48687349f9bf6803ee8993b3eafa3ea1e4f3dff2 /src/utils
parent5bb08bdb6465eebc9dcf80ba2971d894b804abb8 (diff)
downloadVencord-6b26c12bfa1f28d40834478b50d2f7b09c9f54fb.tar.gz
Vencord-6b26c12bfa1f28d40834478b50d2f7b09c9f54fb.tar.bz2
Vencord-6b26c12bfa1f28d40834478b50d2f7b09c9f54fb.zip
Add additional build flavours for Vencord Desktop (#765)
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/native.ts24
-rw-r--r--src/utils/settingsSync.ts42
-rw-r--r--src/utils/updater.ts7
3 files changed, 50 insertions, 23 deletions
diff --git a/src/utils/native.ts b/src/utils/native.ts
new file mode 100644
index 0000000..70e4c0e
--- /dev/null
+++ b/src/utils/native.ts
@@ -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();
+}
diff --git a/src/utils/settingsSync.ts b/src/utils/settingsSync.ts
index 18e1854..781899f 100644
--- a/src/utils/settingsSync.ts
+++ b/src/utils/settingsSync.ts
@@ -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);
- }
- }
}
}
diff --git a/src/utils/updater.ts b/src/utils/updater.ts
index e13f5cf..d0b1fdc 100644
--- a/src/utils/updater.ts
+++ b/src/utils/updater.ts
@@ -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) {