Skip to content

Commit

Permalink
pass the protocol in the package.json in build section
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
avijitdas126 committed Feb 22, 2025
1 parent 58206cb commit 5b5c380
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/renderer/js/electron-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,

Expand Down
18 changes: 17 additions & 1 deletion app/renderer/js/notification/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) => {
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
"build": {
"appId": "org.zulip.zulip-electron",
"asar": true,
"protocols": [
{
"name": "Zulip",
"schemes": [
"zulip"
]
}
],
"asarUnpack": [
"**/*.node"
],
Expand Down

0 comments on commit 5b5c380

Please sign in to comment.