Skip to content

Commit 087158f

Browse files
committed
refactor: update notification utilities for Tauri environment
- Update native notification handling for Tauri - Update sound playback for Tauri asset loading
1 parent 200352c commit 087158f

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/utils/notifications/native.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
import { APPLICATION } from '../../shared/constants';
22

3-
import type { GitifyNotification } from '../../types';
3+
import type { Notification } from '../../typesGitHub';
4+
import { isTauriEnvironment } from '../environment';
45
import { generateGitHubWebUrl } from '../helpers';
56

6-
export async function raiseNativeNotification(
7-
notifications: GitifyNotification[],
8-
) {
7+
export async function raiseNativeNotification(notifications: Notification[]) {
8+
if (!isTauriEnvironment()) {
9+
// Browser fallback - use browser notifications
10+
if ('Notification' in window && Notification.permission === 'granted') {
11+
if (notifications.length === 1) {
12+
const notification = notifications[0];
13+
new Notification(notification.repository.full_name, {
14+
body: notification.subject.title,
15+
});
16+
} else {
17+
new Notification(APPLICATION.NAME, {
18+
body: `You have ${notifications.length} notifications`,
19+
});
20+
}
21+
}
22+
return;
23+
}
24+
925
let title: string;
1026
let body: string;
1127
let url: string | undefined;
@@ -14,7 +30,7 @@ export async function raiseNativeNotification(
1430
const notification = notifications[0];
1531
title = window.gitify.platform.isWindows()
1632
? ''
17-
: notification.repository.fullName;
33+
: notification.repository.full_name;
1834
body = notification.subject.title;
1935
url = await generateGitHubWebUrl(notification);
2036
} else {

src/utils/notifications/sound.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import type { Percentage } from '../../types';
2+
import { isTauriEnvironment } from '../environment';
23

34
const MINIMUM_VOLUME_PERCENTAGE = 0 as Percentage;
45
const MAXIMUM_VOLUME_PERCENTAGE = 100 as Percentage;
56
const VOLUME_STEP = 10 as Percentage;
67

78
export async function raiseSoundNotification(volume: Percentage) {
9+
if (!isTauriEnvironment()) {
10+
// Browser fallback - no sound notification
11+
return;
12+
}
13+
814
const path = await window.gitify.notificationSoundPath();
915

1016
const audio = new Audio(path);

0 commit comments

Comments
 (0)