@@ -6,66 +6,150 @@ import { isLinux, isMacOS, isWindows } from '../shared/platform';
66
77import { invokeMainEvent , onRendererEvent , sendMainEvent } from './utils' ;
88
9+ /**
10+ * The Gitify Bridge API exposed to the renderer via `contextBridge`.
11+ *
12+ * All renderer↔main IPC communication must go through this object.
13+ * It is available on `window.gitify` inside the renderer process.
14+ */
915export const api = {
16+ /**
17+ * Open a URL in the user's default browser.
18+ *
19+ * @param url - The URL to open.
20+ * @param openInForeground - When `true`, brings the browser to the foreground.
21+ */
1022 openExternalLink : ( url : string , openInForeground : boolean ) => {
1123 sendMainEvent ( EVENTS . OPEN_EXTERNAL , {
1224 url : url ,
1325 activate : openInForeground ,
1426 } ) ;
1527 } ,
1628
29+ /**
30+ * Encrypt a plaintext string using Electron's safe storage.
31+ *
32+ * @param value - The plaintext string to encrypt.
33+ * @returns A promise resolving to the encrypted string.
34+ */
1735 encryptValue : ( value : string ) =>
1836 invokeMainEvent ( EVENTS . SAFE_STORAGE_ENCRYPT , value ) ,
1937
38+ /**
39+ * Decrypt an encrypted string using Electron's safe storage.
40+ *
41+ * @param value - The encrypted string to decrypt.
42+ * @returns A promise resolving to the plaintext string.
43+ */
2044 decryptValue : ( value : string ) =>
2145 invokeMainEvent ( EVENTS . SAFE_STORAGE_DECRYPT , value ) ,
2246
47+ /**
48+ * Enable or disable launching the application at system login.
49+ *
50+ * @param value - `true` to enable auto-launch, `false` to disable.
51+ */
2352 setAutoLaunch : ( value : boolean ) =>
2453 sendMainEvent ( EVENTS . UPDATE_AUTO_LAUNCH , {
2554 openAtLogin : value ,
2655 openAsHidden : value ,
2756 } ) ,
2857
58+ /**
59+ * Register or unregister the global keyboard shortcut for toggling the app window.
60+ *
61+ * @param keyboardShortcut - `true` to register the shortcut, `false` to unregister.
62+ */
2963 setKeyboardShortcut : ( keyboardShortcut : boolean ) => {
3064 sendMainEvent ( EVENTS . UPDATE_KEYBOARD_SHORTCUT , {
3165 enabled : keyboardShortcut ,
3266 keyboardShortcut : APPLICATION . DEFAULT_KEYBOARD_SHORTCUT ,
3367 } ) ;
3468 } ,
3569
70+ /** Tray icon controls. */
3671 tray : {
72+ /**
73+ * Update the tray icon color based on unread notification count.
74+ *
75+ * Pass a negative number to set the error state color.
76+ *
77+ * @param notificationsCount - Number of unread notifications.
78+ */
3779 updateColor : ( notificationsCount = 0 ) => {
3880 sendMainEvent ( EVENTS . UPDATE_ICON_COLOR , notificationsCount ) ;
3981 } ,
4082
83+ /**
84+ * Update the tray icon title (the text shown next to the icon).
85+ *
86+ * @param title - The title string to display. Pass an empty string to clear it.
87+ */
4188 updateTitle : ( title = '' ) => sendMainEvent ( EVENTS . UPDATE_ICON_TITLE , title ) ,
4289
90+ /**
91+ * Switch the tray icon to an alternate idle icon variant.
92+ *
93+ * @param value - `true` to use the alternate idle icon, `false` for the default.
94+ */
4395 useAlternateIdleIcon : ( value : boolean ) =>
4496 sendMainEvent ( EVENTS . USE_ALTERNATE_IDLE_ICON , value ) ,
4597
98+ /**
99+ * Switch the tray icon to an "active" variant when there are unread notifications.
100+ *
101+ * @param value - `true` to use the unread-active icon, `false` for the default.
102+ */
46103 useUnreadActiveIcon : ( value : boolean ) =>
47104 sendMainEvent ( EVENTS . USE_UNREAD_ACTIVE_ICON , value ) ,
48105 } ,
49106
107+ /**
108+ * Resolve the absolute file path of the notification sound asset.
109+ *
110+ * @returns A promise resolving to the sound file path.
111+ */
50112 notificationSoundPath : ( ) => invokeMainEvent ( EVENTS . NOTIFICATION_SOUND_PATH ) ,
51113
114+ /**
115+ * Resolve the absolute directory path of the bundled Twemoji assets.
116+ *
117+ * @returns A promise resolving to the Twemoji directory path.
118+ */
52119 twemojiDirectory : ( ) => invokeMainEvent ( EVENTS . TWEMOJI_DIRECTORY ) ,
53120
121+ /** Platform detection helpers. */
122+ /** Platform detection helpers. */
54123 platform : {
124+ /** Returns `true` when running on Linux. */
55125 isLinux : ( ) => isLinux ( ) ,
56126
127+ /** Returns `true` when running on macOS. */
57128 isMacOS : ( ) => isMacOS ( ) ,
58129
130+ /** Returns `true` when running on Windows. */
59131 isWindows : ( ) => isWindows ( ) ,
60132 } ,
61133
134+ /** Application window and lifecycle controls. */
62135 app : {
136+ /** Hide the application window. */
63137 hide : ( ) => sendMainEvent ( EVENTS . WINDOW_HIDE ) ,
64138
139+ /** Show and focus the application window. */
65140 show : ( ) => sendMainEvent ( EVENTS . WINDOW_SHOW ) ,
66141
142+ /** Quit the application. */
67143 quit : ( ) => sendMainEvent ( EVENTS . QUIT ) ,
68144
145+ /**
146+ * Return the application version string.
147+ *
148+ * Returns `"dev"` in development mode; otherwise returns `"v<semver>"`
149+ * retrieved from the main process.
150+ *
151+ * @returns A promise resolving to the version string.
152+ */
69153 version : async ( ) => {
70154 if ( process . env . NODE_ENV === 'development' ) {
71155 return 'dev' ;
@@ -77,24 +161,61 @@ export const api = {
77161 } ,
78162 } ,
79163
164+ /** Electron web frame zoom controls. */
80165 zoom : {
166+ /**
167+ * Return the current Electron zoom level.
168+ *
169+ * @returns The current zoom level (0 = 100%).
170+ */
81171 getLevel : ( ) => webFrame . getZoomLevel ( ) ,
82172
173+ /**
174+ * Set the Electron zoom level.
175+ *
176+ * @param zoomLevel - The zoom level to apply (0 = 100%).
177+ */
83178 setLevel : ( zoomLevel : number ) => webFrame . setZoomLevel ( zoomLevel ) ,
84179 } ,
85180
181+ /**
182+ * Register a callback invoked when the main process requests an app reset.
183+ *
184+ * @param callback - Called when the reset event is received.
185+ */
86186 onResetApp : ( callback : ( ) => void ) => {
87187 onRendererEvent ( EVENTS . RESET_APP , ( ) => callback ( ) ) ;
88188 } ,
89189
190+ /**
191+ * Register a callback invoked when the main process delivers an OAuth callback URL.
192+ *
193+ * @param callback - Called with the full callback URL (e.g. `gitify://oauth?code=...`).
194+ */
90195 onAuthCallback : ( callback : ( url : string ) => void ) => {
91196 onRendererEvent ( EVENTS . AUTH_CALLBACK , ( _ , url ) => callback ( url ) ) ;
92197 } ,
93198
199+ /**
200+ * Register a callback invoked when the OS system theme changes.
201+ *
202+ * @param callback - Called with the new theme string (`"light"` or `"dark"`).
203+ */
94204 onSystemThemeUpdate : ( callback : ( theme : string ) => void ) => {
95205 onRendererEvent ( EVENTS . UPDATE_THEME , ( _ , theme ) => callback ( theme ) ) ;
96206 } ,
97207
208+ /**
209+ * Display a native OS notification.
210+ *
211+ * Clicking the notification opens `url` in the browser (hiding the app window),
212+ * or shows the app window if no URL is provided.
213+ *
214+ * @param title - The notification title.
215+ * @param body - The notification body text.
216+ * @param url - Optional URL to open when the notification is clicked.
217+ * @returns The created `Notification` instance.
218+ */
98219 raiseNativeNotification : ( title : string , body : string , url ?: string ) => {
99220 const notification = new Notification ( title , { body : body , silent : true } ) ;
100221 notification . onclick = ( ) => {
0 commit comments