From 9e7c9c20d8097656338aea279133f474b0a6ed48 Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Sun, 10 Sep 2023 23:29:35 +0530 Subject: [PATCH] Fix overwrite --- electron/commands/image-upscayl.ts | 14 ++------------ .../components/settings-tab/ToggleOverwrite.tsx | 2 +- renderer/pages/index.tsx | 10 ++++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/electron/commands/image-upscayl.ts b/electron/commands/image-upscayl.ts index 763384e..5f44b3a 100644 --- a/electron/commands/image-upscayl.ts +++ b/electron/commands/image-upscayl.ts @@ -28,11 +28,12 @@ const imageUpscayl = async (event, payload) => { console.log("No main window"); return; } + + setOverwrite(payload.overwrite); console.log({ overwrite: payload.overwrite, }); - setOverwrite(payload.overwrite); const model = payload.model as string; const gpuId = payload.gpuId as string; const saveImageAs = payload.saveImageAs as string; @@ -71,17 +72,6 @@ const imageUpscayl = async (event, payload) => { "." + saveImageAs; - // GET OVERWRITE SETTINGS FROM LOCAL STORAGE - mainWindow.webContents - .executeJavaScript('localStorage.getItem("overwrite");', true) - .then((lastSavedOverwrite: boolean | null) => { - if (lastSavedOverwrite !== null) { - console.log("Overwrite: ", lastSavedOverwrite); - setOverwrite(lastSavedOverwrite); - console.log("NEW OVERWRITE: ", overwrite); - } - }); - // UPSCALE if (fs.existsSync(outFile) && !overwrite) { // If already upscayled, just output that file diff --git a/renderer/components/settings-tab/ToggleOverwrite.tsx b/renderer/components/settings-tab/ToggleOverwrite.tsx index eae61f9..98cf5ce 100644 --- a/renderer/components/settings-tab/ToggleOverwrite.tsx +++ b/renderer/components/settings-tab/ToggleOverwrite.tsx @@ -12,7 +12,7 @@ const ToggleOverwrite = ({ overwrite, setOverwrite }: ToggleOverwriteProps) => { } else { const currentlySavedOverwrite = localStorage.getItem("overwrite"); if (currentlySavedOverwrite) { - setOverwrite(JSON.parse(currentlySavedOverwrite)); + setOverwrite(currentlySavedOverwrite === "true"); } } }, []); diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsx index 0e5b4da..b14ff69 100644 --- a/renderer/pages/index.tsx +++ b/renderer/pages/index.tsx @@ -207,6 +207,16 @@ const Home = () => { const rememberOutputFolder = localStorage.getItem("rememberOutputFolder"); const lastOutputFolderPath = localStorage.getItem("lastOutputFolderPath"); + // GET OVERWRITE + if (!localStorage.getItem("overwrite")) { + localStorage.setItem("overwrite", JSON.stringify(overwrite)); + } else { + const currentlySavedOverwrite = localStorage.getItem("overwrite"); + if (currentlySavedOverwrite) { + setOverwrite(currentlySavedOverwrite === "true"); + } + } + if (rememberOutputFolder === "true") { setOutputPath(lastOutputFolderPath); } else {