Skip to content

Commit 5b5c380

Browse files
committed
pass the protocol in the package.json in build section
To register a custom protocol for your Electron application across all platforms (Windows, macOS, and Linux), you can define it in the build section of your package.json file using the protocols property provided by electron-builder.
1 parent 58206cb commit 5b5c380

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-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) => {

package.json

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
"build": {
4242
"appId": "org.zulip.zulip-electron",
4343
"asar": true,
44+
"protocols": [
45+
{
46+
"name": "Zulip",
47+
"schemes": [
48+
"zulip"
49+
]
50+
}
51+
],
4452
"asarUnpack": [
4553
"**/*.node"
4654
],

0 commit comments

Comments
 (0)