From 6b26c12bfa1f28d40834478b50d2f7b09c9f54fb Mon Sep 17 00:00:00 2001 From: V Date: Tue, 4 Apr 2023 01:16:29 +0200 Subject: Add additional build flavours for Vencord Desktop (#765) --- src/utils/settingsSync.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/utils/settingsSync.ts') 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 { - 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 { 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); - } - } } } -- cgit