diff --git a/app/main/index.ts b/app/main/index.ts index 3a4da14c0..40a3b405d 100644 --- a/app/main/index.ts +++ b/app/main/index.ts @@ -185,6 +185,7 @@ function createMainWindow(): BrowserWindow { mainWindow.show(); } // Handle deep link when opened from protocol + const url = commandLine.find((argument) => argument.startsWith("zulip://")); if (url) { mainWindow.webContents.send("open-url", url); diff --git a/app/renderer/js/electron-bridge.ts b/app/renderer/js/electron-bridge.ts index 76aac16ec..88f1faf63 100644 --- a/app/renderer/js/electron-bridge.ts +++ b/app/renderer/js/electron-bridge.ts @@ -17,7 +17,7 @@ export type ElectronBridge = { title: string, options: NotificationOptions, dispatch: (type: string, eventInit: EventInit) => boolean, - ) => NotificationData; + ) => NotificationData | null; get_idle_on_system: () => boolean; get_last_active_on_system: () => number; get_send_notification_reply_message_supported: () => boolean; @@ -47,7 +47,7 @@ const electron_bridge: ElectronBridge = { title: string, options: NotificationOptions, dispatch: (type: string, eventInit: EventInit) => boolean, - ): NotificationData => newNotification(title, options, dispatch), + ): NotificationData | null => newNotification(title, options, dispatch), get_idle_on_system: (): boolean => idle, diff --git a/app/renderer/js/notification/index.ts b/app/renderer/js/notification/index.ts index 988ae4f50..3429bf018 100644 --- a/app/renderer/js/notification/index.ts +++ b/app/renderer/js/notification/index.ts @@ -1,5 +1,16 @@ +import {powerMonitor} from "electron/main"; + import {ipcRenderer} from "../typed-ipc-renderer.js"; +let isLocked = false; + +powerMonitor.on("lock-screen", () => { + isLocked = true; +}); +powerMonitor.on("unlock-screen", () => { + isLocked = false; +}); + export type NotificationData = { close: () => void; title: string; @@ -15,7 +26,12 @@ export function newNotification( title: string, options: NotificationOptions, dispatch: (type: string, eventInit: EventInit) => boolean, -): NotificationData { +): NotificationData | null { + if (isLocked) { + console.log("Notification blocked: Screen is locked."); + return null; // Prevent showing notification when the screen is locked + } + const notification = new Notification(title, {...options, silent: true}); for (const type of ["click", "close", "error", "show"]) { notification.addEventListener(type, (event) => {