Skip to content

Commit ee248b8

Browse files
authored
chore: update jsdocs (#2684)
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 4e1c9e7 commit ee248b8

17 files changed

Lines changed: 581 additions & 43 deletions

File tree

src/preload/index.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,150 @@ import { isLinux, isMacOS, isWindows } from '../shared/platform';
66

77
import { 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+
*/
915
export 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 = () => {

src/preload/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
import type { api } from '.';
22

3+
/**
4+
* The type of the Gitify Bridge API exposed to the renderer via `contextBridge`.
5+
*
6+
* Mirrors the shape of `window.gitify` as declared in `preload.d.ts`.
7+
*/
38
export type GitifyAPI = typeof api;

src/preload/utils.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ import { ipcRenderer } from 'electron';
33
import type { EventData, EventType } from '../shared/events';
44

55
/**
6-
* Send renderer event without expecting a response
7-
* @param event the type of event to send
8-
* @param data the data to send with the event
6+
* Send a fire-and-forget IPC message from the renderer to the main process.
7+
*
8+
* @param event - The IPC event type to send.
9+
* @param data - Optional payload to include with the event.
910
*/
1011
export function sendMainEvent(event: EventType, data?: EventData): void {
1112
ipcRenderer.send(event, data);
1213
}
1314

1415
/**
15-
* Send renderer event and expect a response
16-
* @param event the type of event to send
17-
* @param data the data to send with the event
18-
* @returns
16+
* Send an IPC message from the renderer to the main process and await a response.
17+
*
18+
* @param event - The IPC event type to invoke.
19+
* @param data - Optional string payload to include with the event.
20+
* @returns A promise that resolves to the string response from the main process.
1921
*/
2022
export function invokeMainEvent(
2123
event: EventType,
@@ -25,7 +27,10 @@ export function invokeMainEvent(
2527
}
2628

2729
/**
28-
* Handle renderer event without expecting a response
30+
* Register a listener for an IPC event sent from the main process to the renderer.
31+
*
32+
* @param event - The IPC event type to listen for.
33+
* @param listener - The callback invoked when the event is received.
2934
*/
3035
export function onRendererEvent(
3136
event: EventType,

src/renderer/hooks/timers/useInactivityTimer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const events = ['mousedown', 'keypress', 'click'];
66

77
/**
88
* Hook that triggers a callback after a specified period of user inactivity.
9-
* User activity as defined in `events` will reset the timer.
9+
* User activity (mousedown, keypress, click) resets the timer.
10+
*
11+
* @param callback - The function to call once inactivity exceeds `delay`.
12+
* @param delay - Inactivity timeout in milliseconds.
1013
*/
1114
export const useInactivityTimer = (callback: () => void, delay: number) => {
1215
const savedCallback = useRef<(() => void) | null>(null);

src/renderer/hooks/timers/useIntervalTimer.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { useEffect, useRef } from 'react';
22

3-
import { isOnline } from '../../utils/system/network';
4-
53
/**
6-
* Hook that triggers a callback after a specified period of time.
4+
* Hook that triggers a callback on a recurring interval.
75
*
86
* Thanks to https://overreacted.io/making-setinterval-declarative-with-react-hooks/
7+
*
8+
* @param callback - Function to call on each interval tick. Always uses the latest reference.
9+
* @param delay - Interval duration in milliseconds. Pass `null` to disable.
910
*/
1011
export const useIntervalTimer = (callback: () => void, delay: number) => {
1112
const savedCallback = useRef<(() => void) | null>(null);
@@ -18,9 +19,7 @@ export const useIntervalTimer = (callback: () => void, delay: number) => {
1819
// Set up the interval.
1920
useEffect(() => {
2021
function tick() {
21-
if (savedCallback.current && isOnline()) {
22-
savedCallback.current();
23-
}
22+
savedCallback.current();
2423
}
2524

2625
if (delay !== null) {

src/renderer/hooks/useNotifications.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ interface NotificationsState {
5858
) => Promise<void>;
5959
}
6060

61+
/**
62+
* Hook that manages all notification state and actions for the application.
63+
*
64+
* Handles fetching, filtering, sound/native notification triggering,
65+
* mark-as-read, mark-as-done, and unsubscribe operations across all accounts.
66+
*
67+
* @returns The current notifications state and action callbacks.
68+
*/
6169
export const useNotifications = (): NotificationsState => {
6270
const [status, setStatus] = useState<Status>('success');
6371
const [globalError, setGlobalError] = useState<GitifyError>();

src/renderer/utils/api/request.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import type { TypedDocumentString } from './graphql/generated/graphql';
77
import { createOctokitClient } from './octokit';
88

99
/**
10-
* Perform a GraphQL API request with typed operation document
10+
* Perform a GraphQL API request with typed operation document.
1111
*
12-
* @param url The API url
13-
* @param query The GraphQL operation/query statement
14-
* @param variables The GraphQL operation variables
15-
* @returns Resolves to a GitHub GraphQL response
12+
* @param account - The authenticated account to make the request with.
13+
* @param query - The typed GraphQL operation document.
14+
* @param variables - The GraphQL operation variables.
15+
* @returns Resolves to a typed GitHub GraphQL response.
1616
*/
1717
export async function performGraphQLRequest<TResult, TVariables>(
1818
account: Account,
@@ -35,13 +35,12 @@ export async function performGraphQLRequest<TResult, TVariables>(
3535
/**
3636
* Perform a GraphQL API request using a raw query string instead of a TypedDocumentString.
3737
*
38-
* Useful for dynamically composed queries (e.g: merged queries built at runtime).
38+
* Useful for dynamically composed queries (e.g. merged queries built at runtime).
3939
*
40-
* @param url The API url
41-
* @param token The GitHub token (decrypted)
42-
* @param query The GraphQL operation/query statement
43-
* @param variables The GraphQL operation variables
44-
* @returns Resolves to a GitHub GraphQL response
40+
* @param account - The authenticated account to make the request with.
41+
* @param query - The raw GraphQL operation/query string.
42+
* @param variables - The GraphQL operation variables.
43+
* @returns Resolves to a typed GitHub GraphQL response.
4544
*/
4645
export async function performGraphQLRequestString<TResult>(
4746
account: Account,

0 commit comments

Comments
 (0)