|
7 | 7 | clipboard, |
8 | 8 | session, |
9 | 9 | Menu, |
| 10 | + nativeImage, |
10 | 11 | } from "electron" |
11 | 12 | import { join } from "path" |
12 | 13 | import { readFileSync, existsSync } from "fs" |
@@ -63,15 +64,64 @@ function registerIpcHandlers(getWindow: () => BrowserWindow | null): void { |
63 | 64 | }) |
64 | 65 | // Note: Update checking is now handled by auto-updater module (lib/auto-updater.ts) |
65 | 66 | ipcMain.handle("app:set-badge", (_event, count: number | null) => { |
| 67 | + const win = getWindow() |
66 | 68 | if (process.platform === "darwin") { |
| 69 | + // macOS: Use dock badge |
67 | 70 | app.dock.setBadge(count ? String(count) : "") |
| 71 | + } else if (process.platform === "win32" && win) { |
| 72 | + // Windows: Use overlay icon with number badge |
| 73 | + if (count !== null && count > 0) { |
| 74 | + // Request badge icon from renderer (it will generate and send via IPC) |
| 75 | + // For now, show count in window title as fallback |
| 76 | + win.setTitle(`1Code (${count})`) |
| 77 | + // The actual overlay icon will be set when renderer sends the image data |
| 78 | + } else { |
| 79 | + win.setTitle("1Code") |
| 80 | + // Clear overlay icon |
| 81 | + win.setOverlayIcon(null, "") |
| 82 | + } |
| 83 | + } |
| 84 | + }) |
| 85 | + |
| 86 | + // Handle badge icon data from renderer (Windows overlay icon) |
| 87 | + ipcMain.handle("app:set-badge-icon", (_event, imageData: string | null) => { |
| 88 | + const win = getWindow() |
| 89 | + if (process.platform === "win32" && win) { |
| 90 | + if (imageData) { |
| 91 | + // Convert data URL to native image |
| 92 | + const image = nativeImage.createFromDataURL(imageData) |
| 93 | + win.setOverlayIcon(image, `${imageData ? "New messages" : ""}`) |
| 94 | + } else { |
| 95 | + win.setOverlayIcon(null, "") |
| 96 | + } |
68 | 97 | } |
69 | 98 | }) |
70 | 99 | ipcMain.handle( |
71 | 100 | "app:show-notification", |
72 | 101 | (_event, options: { title: string; body: string }) => { |
73 | 102 | const { Notification } = require("electron") |
74 | | - new Notification(options).show() |
| 103 | + // Electron Notification uses native Windows Notification API |
| 104 | + // This will show a standard Windows desktop notification |
| 105 | + const notification = new Notification({ |
| 106 | + title: options.title, |
| 107 | + body: options.body, |
| 108 | + // Windows-specific options |
| 109 | + ...(process.platform === "win32" && { |
| 110 | + // Use Windows 10+ action center |
| 111 | + silent: false, // Play notification sound |
| 112 | + }), |
| 113 | + }) |
| 114 | + notification.show() |
| 115 | + |
| 116 | + // Optional: Handle notification click |
| 117 | + notification.on("click", () => { |
| 118 | + // Focus the main window when notification is clicked |
| 119 | + const win = getWindow() |
| 120 | + if (win) { |
| 121 | + if (win.isMinimized()) win.restore() |
| 122 | + win.focus() |
| 123 | + } |
| 124 | + }) |
75 | 125 | }, |
76 | 126 | ) |
77 | 127 |
|
|
0 commit comments