Skip to content

Commit 687ceda

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 200f8a9 commit 687ceda

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/utils/notifications/native.ts

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

33
import type { Notification } from '../../typesGitHub';
4+
import { isTauriEnvironment } from '../environment';
45
import { generateGitHubWebUrl } from '../helpers';
56

67
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+
725
let title: string;
826
let body: string;
927
let url: string | undefined;

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)