Skip to content

Commit

Permalink
✨ feat: update taskbar progress
Browse files Browse the repository at this point in the history
Signed-off-by: SimonShiki <sinangentoo@gmail.com>
  • Loading branch information
SimonShiki committed Aug 12, 2024
1 parent ab0fdb4 commit c1c371c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"fs:write-all",
"core:path:default",
"core:path:allow-resolve",
"dialog:default"
"dialog:default",
"core:window:allow-set-progress-bar"
]
}
14 changes: 14 additions & 0 deletions src/utils/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { transformChunk } from './chunk-transformer';
import { focusAtom } from 'jotai-optics';
import { WritableAtom } from 'jotai';
import { SetStateAction } from 'react';
import { webviewWindow } from '@tauri-apps/api';
import { ProgressBarStatus } from '@tauri-apps/api/window';

type MediaControlPayload = 'play' | 'pause' | 'toggle' | 'next' | 'previous';
type UpdateDurationPayload = number;
Expand Down Expand Up @@ -46,6 +48,9 @@ async function updateMediaMetadata (song: Song<string>) {

async function updatePlaybackStatus (isPlaying: boolean) {
await invoke('update_playback_status', { isPlaying });
webviewWindow.WebviewWindow.getCurrent().setProgressBar({
status: isPlaying ? ProgressBarStatus.Normal : ProgressBarStatus.Paused
});
}

async function playCurrentSong () {
Expand Down Expand Up @@ -165,6 +170,15 @@ function setupEventListeners () {
}
});

sharedStore.sub(progressJotai, () => {
const progress = sharedStore.get(progressJotai);
const currentSong = sharedStore.get(currentSongJotai);
if (!currentSong || !currentSong.duration) return;
webviewWindow.WebviewWindow.getCurrent().setProgressBar({
progress: Math.ceil(progress / currentSong.duration * 100000)
});
});

sharedStore.sub(playingJotai, async () => {
const backendPlaying = sharedStore.get(backendPlayingJotai);
const playing = sharedStore.get(playingJotai);
Expand Down

0 comments on commit c1c371c

Please sign in to comment.