From c1c371c4f02d372aec54b8aca13bfb84d1aee896 Mon Sep 17 00:00:00 2001 From: SimonShiki Date: Mon, 12 Aug 2024 18:08:12 +0800 Subject: [PATCH] :sparkles: feat: update taskbar progress Signed-off-by: SimonShiki --- src-tauri/capabilities/default.json | 3 ++- src/utils/player.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index e5c67f6..f72ff2c 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -29,6 +29,7 @@ "fs:write-all", "core:path:default", "core:path:allow-resolve", - "dialog:default" + "dialog:default", + "core:window:allow-set-progress-bar" ] } \ No newline at end of file diff --git a/src/utils/player.ts b/src/utils/player.ts index 1d2f26e..99ac397 100644 --- a/src/utils/player.ts +++ b/src/utils/player.ts @@ -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; @@ -46,6 +48,9 @@ async function updateMediaMetadata (song: Song) { async function updatePlaybackStatus (isPlaying: boolean) { await invoke('update_playback_status', { isPlaying }); + webviewWindow.WebviewWindow.getCurrent().setProgressBar({ + status: isPlaying ? ProgressBarStatus.Normal : ProgressBarStatus.Paused + }); } async function playCurrentSong () { @@ -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);