From 3a459b835c05220d8fa882c51d9f47051e2597a8 Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:03:43 +0530 Subject: [PATCH] Add turn off notifications feature --- electron/utils/config-variables.ts | 15 ++++++++++ electron/utils/show-notification.ts | 3 ++ renderer/atoms/userSettingsAtom.ts | 5 ++++ .../settings-tab/CustomModelsFolderSelect.tsx | 11 +++++++- .../TurnOffNotificationsToggle.tsx | 28 +++++++++++++++++++ renderer/components/settings-tab/index.tsx | 2 ++ renderer/pages/index.tsx | 5 +--- 7 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 renderer/components/settings-tab/TurnOffNotificationsToggle.tsx diff --git a/electron/utils/config-variables.ts b/electron/utils/config-variables.ts index 5ccd65c..a36fb47 100644 --- a/electron/utils/config-variables.ts +++ b/electron/utils/config-variables.ts @@ -14,6 +14,7 @@ export let childProcesses: { kill: () => boolean; }[] = []; export let noImageProcessing: boolean = false; +export let turnOffNotifications: boolean = false; export function setImagePath(value: string | undefined): void { imagePath = value; @@ -70,6 +71,11 @@ export function setNoImageProcessing(value: boolean): void { logit("🖼️ Updating No Image Processing: ", noImageProcessing); } +export function setTurnOffNotifications(value: boolean): void { + turnOffNotifications = value; + logit("🔕 Updating Turn Off Notifications: ", turnOffNotifications); +} + // LOCAL STORAGE export function fetchLocalStorage(): void { const mainWindow = getMainWindow(); @@ -134,4 +140,13 @@ export function fetchLocalStorage(): void { setNoImageProcessing(lastSaved === "true"); } }); + + // GET TURN OFF NOTIFICATIONS (BOOLEAN) FROM LOCAL STORAGE + mainWindow.webContents + .executeJavaScript('localStorage.getItem("turnOffNotifications");', true) + .then((lastSaved: string | null) => { + if (lastSaved !== null) { + setTurnOffNotifications(lastSaved === "true"); + } + }); } diff --git a/electron/utils/show-notification.ts b/electron/utils/show-notification.ts index cb35ef9..00e80b8 100644 --- a/electron/utils/show-notification.ts +++ b/electron/utils/show-notification.ts @@ -1,6 +1,9 @@ import { Notification } from "electron/main"; +import { fetchLocalStorage, turnOffNotifications } from "./config-variables"; export default function showNotification(title: string, body: string) { + fetchLocalStorage(); + if (turnOffNotifications) return; new Notification({ title, body, diff --git a/renderer/atoms/userSettingsAtom.ts b/renderer/atoms/userSettingsAtom.ts index c695a98..3679366 100644 --- a/renderer/atoms/userSettingsAtom.ts +++ b/renderer/atoms/userSettingsAtom.ts @@ -28,3 +28,8 @@ export const noImageProcessingAtom = atomWithStorage( export const compressionAtom = atomWithStorage("compression", 0); export const overwriteAtom = atomWithStorage("overwrite", false); + +export const turnOffNotificationsAtom = atomWithStorage( + "turnOffNotifications", + false +); diff --git a/renderer/components/settings-tab/CustomModelsFolderSelect.tsx b/renderer/components/settings-tab/CustomModelsFolderSelect.tsx index 6d29f72..8f814bb 100644 --- a/renderer/components/settings-tab/CustomModelsFolderSelect.tsx +++ b/renderer/components/settings-tab/CustomModelsFolderSelect.tsx @@ -1,5 +1,5 @@ import React from "react"; -import commands from "../../../electron/constants/commands"; +import commands from "../../../common/commands"; type CustomModelsFolderSelectProps = { customModelsPath: string; @@ -13,6 +13,15 @@ export function CustomModelsFolderSelect({ return (

ADD CUSTOM MODELS

+

+ You can add your own models easily. For more details:{" "} + + Custom Models Repository + +

{customModelsPath}