From c0d397990db2293c4631452d401c89247a709b1f Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Wed, 30 Aug 2023 10:24:16 +0530 Subject: [PATCH] Add macOS window button --- electron/index.ts | 19 +++++++++++++++---- electron/preload.ts | 2 ++ renderer/components/Header.tsx | 2 +- .../settings-tab/ImageFormatSelect.tsx | 4 ++-- .../components/settings-tab/QualityInput.tsx | 9 ++++++--- .../settings-tab/ToggleOverwrite.tsx | 14 ++++++++++---- .../upscayl-tab/config/LeftPaneImageSteps.tsx | 5 +++-- renderer/pages/index.tsx | 19 ++++++++++++++++++- renderer/renderer.d.ts | 1 + renderer/styles/globals.css | 4 ++++ 10 files changed, 62 insertions(+), 17 deletions(-) diff --git a/electron/index.ts b/electron/index.ts index 917d232..a531d3c 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -78,6 +78,7 @@ app.on("ready", async () => { webSecurity: false, preload: join(__dirname, "preload.js"), }, + titleBarStyle: getPlatform() === "mac" ? "hiddenInset" : "default", }); const url = isDev ? "http://localhost:8000" @@ -159,9 +160,9 @@ app.on("ready", async () => { // GET IMAGE QUALITY (NUMBER) TO LOCAL STORAGE mainWindow.webContents .executeJavaScript('localStorage.getItem("quality");', true) - .then((overwriteToggle: string | null) => { - if (overwriteToggle !== null) { - quality = parseInt(overwriteToggle); + .then((lastSavedQuality: string | null) => { + if (lastSavedQuality !== null) { + quality = parseInt(lastSavedQuality); } }); // GET OVERWRITE SETTINGS FROM LOCAL STORAGE @@ -416,8 +417,18 @@ ipcMain.on(commands.UPSCAYL, 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); + overwrite = lastSavedOverwrite; + } + }); + // UPSCALE - if (fs.existsSync(outFile) && !overwrite) { + if (fs.existsSync(outFile) && overwrite === false) { // If already upscayled, just output that file logit("✅ Already upscayled at: ", outFile); mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile); diff --git a/electron/preload.ts b/electron/preload.ts index 8cad08d..9ebdddc 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -1,4 +1,5 @@ import { ipcRenderer, contextBridge } from "electron"; +import getPlatform from "./getPlatform"; // 'ipcRenderer' will be available in index.js with the method 'window.electron' contextBridge.exposeInMainWorld("electron", { @@ -9,4 +10,5 @@ contextBridge.exposeInMainWorld("electron", { }), invoke: (command: string, payload: any) => ipcRenderer.invoke(command, payload), + platform: getPlatform(), }); diff --git a/renderer/components/Header.tsx b/renderer/components/Header.tsx index 9d82234..1c8bb54 100644 --- a/renderer/components/Header.tsx +++ b/renderer/components/Header.tsx @@ -5,7 +5,7 @@ export default function Header({ version }: { version: string }) {
Upscayl Logo diff --git a/renderer/components/settings-tab/ImageFormatSelect.tsx b/renderer/components/settings-tab/ImageFormatSelect.tsx index 0c84ebb..f756705 100644 --- a/renderer/components/settings-tab/ImageFormatSelect.tsx +++ b/renderer/components/settings-tab/ImageFormatSelect.tsx @@ -42,14 +42,14 @@ export function ImageFormatSelect({ onClick={() => setExportType("jpg")}> JPG - {/* WEBP */} + {/* WEBP + */}
diff --git a/renderer/components/settings-tab/QualityInput.tsx b/renderer/components/settings-tab/QualityInput.tsx index 1cd17c2..0129be9 100644 --- a/renderer/components/settings-tab/QualityInput.tsx +++ b/renderer/components/settings-tab/QualityInput.tsx @@ -11,9 +11,12 @@ export function QualityInput({ }: QualityInputProps) { return (
-

- Image Compression ({quality}%) -

+
+

Image Compression ({quality}%)

+

+ EXPERIMENTAL +

+
{ if (!localStorage.getItem("overwrite")) { localStorage.setItem("overwrite", JSON.stringify(overwrite)); } else { - setOverwrite(localStorage.getItem("overwrite")); + const currentlySavedOverwrite = localStorage.getItem("overwrite"); + if (currentlySavedOverwrite) { + setOverwrite(JSON.parse(currentlySavedOverwrite)); + } } }, []); + return (

OVERWRITE PREVIOUS UPSCALE

@@ -21,11 +25,13 @@ const ToggleOverwrite = ({ overwrite, setOverwrite }: ToggleOverwriteProps) => { className="toggle" checked={overwrite} onClick={() => { - setOverwrite((oldValue) => { - if (oldValue === true) { + setOverwrite((oldValue: boolean) => { + if (oldValue) { localStorage.removeItem("overwrite"); + return false; + } else { + return true; } - return !oldValue; }); localStorage.setItem("overwrite", JSON.stringify(!overwrite)); }} diff --git a/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx b/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx index c9c7b1b..084cedc 100644 --- a/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx +++ b/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx @@ -130,7 +130,8 @@ function LeftPaneImageSteps({ }; return ( -
+
{/* BATCH OPTION */}
setBatchMode((oldValue) => !oldValue)}>

Batch Upscayl diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsx index 682e2ef..0692619 100644 --- a/renderer/pages/index.tsx +++ b/renderer/pages/index.tsx @@ -435,9 +435,22 @@ const Home = () => { const allowedFileTypes = ["png", "jpg", "jpeg", "webp"]; + if (typeof window === "undefined") { + return ( + Upscayl icon + ); + } + return (

-
+
+ {window.electron.platform === "mac" && ( +
+ )} {/* HEADER */}
@@ -492,6 +505,10 @@ const Home = () => { onDragEnter={(e) => handleDragEnter(e)} onDragLeave={(e) => handleDragLeave(e)} onPaste={(e) => handlePaste(e)}> + {window.electron.platform === "mac" && ( +
+ )} + {progress.length > 0 && upscaledImagePath.length === 0 && upscaledBatchFolderPath.length === 0 ? ( diff --git a/renderer/renderer.d.ts b/renderer/renderer.d.ts index 0f9f235..ab0bb02 100644 --- a/renderer/renderer.d.ts +++ b/renderer/renderer.d.ts @@ -4,6 +4,7 @@ export interface IElectronAPI { on: (command, func?) => IpcRenderer; send: (command, func?) => IpcRenderer; invoke: (command, func?) => any; + platform: "mac" | "win" | "linux"; } declare global { diff --git a/renderer/styles/globals.css b/renderer/styles/globals.css index da2bc6e..bca20a6 100644 --- a/renderer/styles/globals.css +++ b/renderer/styles/globals.css @@ -161,6 +161,10 @@ @apply rounded-btn h-10 ring-1 ring-slate-500 cursor-pointer !border-0 !border-none !border-transparent bg-primary shadow-none; } +.mac-titlebar { + -webkit-app-region: drag; +} + @keyframes animate-step-in { 0% { opacity: 0;