Skip to content

Commit 55222f2

Browse files
committed
Windows: Prevent Notifications from Showing on Lock Screen
This update ensures that notifications are not displayed when the system is locked on Windows. Using Electron's powerMonitor, the app detects when the screen is locked and blocks notifications to prevent potential leaks of sensitive information.
1 parent 3d6ea80 commit 55222f2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

app/renderer/js/electron-bridge.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type ElectronBridge = {
1717
title: string,
1818
options: NotificationOptions,
1919
dispatch: (type: string, eventInit: EventInit) => boolean,
20-
) => NotificationData;
20+
) => NotificationData | null;
2121
get_idle_on_system: () => boolean;
2222
get_last_active_on_system: () => number;
2323
get_send_notification_reply_message_supported: () => boolean;
@@ -47,7 +47,7 @@ const electron_bridge: ElectronBridge = {
4747
title: string,
4848
options: NotificationOptions,
4949
dispatch: (type: string, eventInit: EventInit) => boolean,
50-
): NotificationData => newNotification(title, options, dispatch),
50+
): NotificationData | null => newNotification(title, options, dispatch),
5151

5252
get_idle_on_system: (): boolean => idle,
5353

app/renderer/js/notification/index.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
import {powerMonitor} from "electron/main";
2+
13
import {ipcRenderer} from "../typed-ipc-renderer.js";
24

5+
let isLocked = false;
6+
7+
powerMonitor.on("lock-screen", () => {
8+
isLocked = true;
9+
});
10+
powerMonitor.on("unlock-screen", () => {
11+
isLocked = false;
12+
});
13+
314
export type NotificationData = {
415
close: () => void;
516
title: string;
@@ -15,7 +26,12 @@ export function newNotification(
1526
title: string,
1627
options: NotificationOptions,
1728
dispatch: (type: string, eventInit: EventInit) => boolean,
18-
): NotificationData {
29+
): NotificationData | null {
30+
if (isLocked) {
31+
console.log("Notification blocked: Screen is locked.");
32+
return null; // Prevent showing notification when the screen is locked
33+
}
34+
1935
const notification = new Notification(title, {...options, silent: true});
2036
for (const type of ["click", "close", "error", "show"]) {
2137
notification.addEventListener(type, (event) => {

0 commit comments

Comments
 (0)