feat(qbzd): guard all stores/services for remote mode override
cc
This commit is contained in:
16 files changed
+139
-4
No files matched your search
@@ -20,6 +20,15 @@ export function isRemote(): boolean {
|
||||
return getTarget().type === 'qbzd';
|
||||
}
|
||||
|
||||
/**
|
||||
* Guard for local-only operations. Returns true if we should skip.
|
||||
* Use at the start of any function that only makes sense locally
|
||||
* (offline cache, window settings, visualizer, etc.)
|
||||
*/
|
||||
export function skipIfRemote(): boolean {
|
||||
return getTarget().type === 'qbzd';
|
||||
}
|
||||
|
||||
/** Fetch from remote API (GET), or null if local */
|
||||
export async function remoteGetOrNull<T>(path: string): Promise<T | null> {
|
||||
if (!isRemote()) return null;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { get } from 'svelte/store';
|
||||
import { t } from '$lib/i18n';
|
||||
import { cmdStop, cmdPlayTrack } from '$lib/services/commandRouter';
|
||||
import { cmdStop, cmdPlayTrack, skipIfRemote } from '$lib/services/commandRouter';
|
||||
import { getTarget } from '$lib/stores/playbackTargetStore';
|
||||
import { remotePost } from '$lib/services/remoteApi';
|
||||
import { getUserItem, setUserItem } from '$lib/utils/userStorage';
|
||||
@@ -488,6 +488,7 @@ export async function playTrack(
|
||||
* Update system media controls metadata (V2)
|
||||
*/
|
||||
export async function updateMediaMetadata(metadata: MediaMetadata): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
const coverUrl = normalizeCoverUrlForMetadata(metadata.coverUrl);
|
||||
await invoke('v2_set_media_metadata', {
|
||||
@@ -569,6 +570,7 @@ export async function showTrackNotification(
|
||||
bitDepth?: number,
|
||||
sampleRate?: number
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
// Skip if system notifications are disabled
|
||||
if (!systemNotificationsEnabled) {
|
||||
return;
|
||||
@@ -659,6 +661,7 @@ export async function updateListenBrainzNowPlaying(
|
||||
trackId: number,
|
||||
isrc?: string
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
// Check if ListenBrainz is connected and enabled
|
||||
const status = await getListenBrainzStatus();
|
||||
if (!status?.connected || !status?.enabled) return;
|
||||
@@ -750,6 +753,7 @@ export async function updateListenBrainzNowPlaying(
|
||||
* Call this when transitioning from offline to online
|
||||
*/
|
||||
export async function flushListenBrainzQueue(): Promise<number> {
|
||||
if (skipIfRemote()) return 0;
|
||||
// Check if ListenBrainz is connected and enabled
|
||||
const status = await getListenBrainzStatus();
|
||||
if (!status?.connected || !status?.enabled) return 0;
|
||||
@@ -782,6 +786,7 @@ export async function updateLastfmNowPlaying(
|
||||
durationSecs: number,
|
||||
trackId: number
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
// Check if scrobbling is enabled
|
||||
const scrobblingEnabled = getUserItem('qbz-lastfm-scrobbling') !== 'false';
|
||||
const sessionKey = getUserItem('qbz-lastfm-session-key');
|
||||
@@ -848,6 +853,7 @@ export async function updateLastfmNowPlaying(
|
||||
* Call this when transitioning from offline to online
|
||||
*/
|
||||
export async function flushScrobbleQueue(): Promise<{ sent: number; failed: number }> {
|
||||
if (skipIfRemote()) return { sent: 0, failed: 0 };
|
||||
// Check if scrobbling is enabled
|
||||
const scrobblingEnabled = getUserItem('qbz-lastfm-scrobbling') !== 'false';
|
||||
const sessionKey = getUserItem('qbz-lastfm-session-key');
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
export interface PersistedQueueTrack {
|
||||
id: number;
|
||||
@@ -51,6 +52,7 @@ export async function saveSessionState(
|
||||
viewContextId?: string | null,
|
||||
viewContextType?: string | null
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_save_session_state', {
|
||||
queueTracks,
|
||||
@@ -74,6 +76,7 @@ export async function saveSessionState(
|
||||
* Load the persisted session state
|
||||
*/
|
||||
export async function loadSessionState(): Promise<PersistedSession | null> {
|
||||
if (skipIfRemote()) return null;
|
||||
try {
|
||||
const session = await invoke<PersistedSession>('v2_load_session_state');
|
||||
console.log('[Session] State loaded:', {
|
||||
@@ -93,6 +96,7 @@ export async function loadSessionState(): Promise<PersistedSession | null> {
|
||||
* Quick save of just the playback position (debounced during playback)
|
||||
*/
|
||||
export async function saveSessionPosition(positionSecs: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_save_session_position', { positionSecs });
|
||||
} catch (err) {
|
||||
@@ -104,6 +108,7 @@ export async function saveSessionPosition(positionSecs: number): Promise<void> {
|
||||
* Quick save of volume
|
||||
*/
|
||||
export async function saveSessionVolume(volume: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_save_session_volume', { volume });
|
||||
} catch (err) {
|
||||
@@ -118,6 +123,7 @@ export async function saveSessionPlaybackMode(
|
||||
shuffle: boolean,
|
||||
repeatMode: string
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_save_session_playback_mode', { shuffle, repeatMode });
|
||||
} catch (err) {
|
||||
@@ -129,6 +135,7 @@ export async function saveSessionPlaybackMode(
|
||||
* Clear the session (e.g., on logout)
|
||||
*/
|
||||
export async function clearSession(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_clear_session');
|
||||
console.log('[Session] Session cleared');
|
||||
@@ -173,6 +180,7 @@ export async function saveCurrentSession(
|
||||
getPlayerState: () => { currentTime: number; volume: number; isPlaying: boolean },
|
||||
getPlaybackMode: () => { shuffle: boolean; repeat: string }
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
const queueState = getQueueState();
|
||||
const playerState = getPlayerState();
|
||||
const playbackMode = getPlaybackMode();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
import { logRecoEvent } from '$lib/services/recoService';
|
||||
|
||||
let favoriteAlbumIds = new Set<string>();
|
||||
@@ -50,6 +51,7 @@ export function isFavoritesLoaded(): boolean {
|
||||
* Load album favorites from local cache first, then sync from API
|
||||
*/
|
||||
export async function loadAlbumFavorites(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (isLoading) return;
|
||||
|
||||
isLoading = true;
|
||||
@@ -86,6 +88,7 @@ export async function loadAlbumFavorites(): Promise<void> {
|
||||
* Sync album favorites from Qobuz API to local cache
|
||||
*/
|
||||
export async function syncFromApi(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
const allAlbumIds: string[] = [];
|
||||
let offset = 0;
|
||||
@@ -128,6 +131,7 @@ export async function syncFromApi(): Promise<void> {
|
||||
* API call first → on success → update local cache → notify UI
|
||||
*/
|
||||
export async function toggleAlbumFavorite(albumId: string): Promise<boolean> {
|
||||
if (skipIfRemote()) return favoriteAlbumIds.has(albumId);
|
||||
if (togglingAlbumIds.has(albumId)) {
|
||||
return favoriteAlbumIds.has(albumId);
|
||||
}
|
||||
@@ -169,6 +173,7 @@ export async function toggleAlbumFavorite(albumId: string): Promise<boolean> {
|
||||
* Used by FavoritesView after fetching from API
|
||||
*/
|
||||
export async function syncCache(albumIds: string[]): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_sync_cached_favorite_albums', { albumIds });
|
||||
favoriteAlbumIds = new Set(albumIds);
|
||||
@@ -179,6 +184,7 @@ export async function syncCache(albumIds: string[]): Promise<void> {
|
||||
}
|
||||
|
||||
export function markAsFavorite(albumId: string): void {
|
||||
if (skipIfRemote()) return;
|
||||
if (!favoriteAlbumIds.has(albumId)) {
|
||||
favoriteAlbumIds.add(albumId);
|
||||
invoke('v2_cache_favorite_album', { albumId }).catch(() => {});
|
||||
@@ -187,6 +193,7 @@ export function markAsFavorite(albumId: string): void {
|
||||
}
|
||||
|
||||
export function unmarkAsFavorite(albumId: string): void {
|
||||
if (skipIfRemote()) return;
|
||||
if (favoriteAlbumIds.has(albumId)) {
|
||||
favoriteAlbumIds.delete(albumId);
|
||||
invoke('v2_uncache_favorite_album', { albumId }).catch(() => {});
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
// ============ Types ============
|
||||
|
||||
@@ -45,6 +46,7 @@ function updateIdSet(): void {
|
||||
* Load blacklist from backend
|
||||
*/
|
||||
export async function loadBlacklist(): Promise<BlacklistedArtist[]> {
|
||||
if (skipIfRemote()) return [];
|
||||
const [list, settings] = await Promise.all([
|
||||
invoke<BlacklistedArtist[]>('v2_get_artist_blacklist'),
|
||||
invoke<BlacklistSettings>('v2_get_blacklist_settings')
|
||||
@@ -64,6 +66,7 @@ export async function addToBlacklist(
|
||||
artistName: string,
|
||||
notes?: string
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_add_to_artist_blacklist', {
|
||||
artistId,
|
||||
artistName,
|
||||
@@ -77,6 +80,7 @@ export async function addToBlacklist(
|
||||
* Remove an artist from the blacklist
|
||||
*/
|
||||
export async function removeFromBlacklist(artistId: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_remove_from_artist_blacklist', { artistId });
|
||||
// Update local state
|
||||
blacklist = blacklist.filter(a => a.artist_id !== artistId);
|
||||
@@ -96,6 +100,7 @@ export function isBlacklisted(artistId: number): boolean {
|
||||
* Set the enabled state
|
||||
*/
|
||||
export async function setEnabled(value: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_set_blacklist_enabled', { enabled: value });
|
||||
enabled = value;
|
||||
notifyListeners();
|
||||
@@ -126,6 +131,7 @@ export function getCount(): number {
|
||||
* Clear all blacklisted artists
|
||||
*/
|
||||
export async function clearBlacklist(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_clear_artist_blacklist');
|
||||
blacklist = [];
|
||||
updateIdSet();
|
||||
@@ -146,5 +152,6 @@ export function subscribe(listener: () => void): () => void {
|
||||
* Initialize blacklist store (call on app startup)
|
||||
*/
|
||||
export async function initBlacklistStore(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await loadBlacklist();
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
import { logRecoEvent } from '$lib/services/recoService';
|
||||
|
||||
let favoriteArtistIds = new Set<number>();
|
||||
@@ -50,6 +51,7 @@ export function isFavoritesLoaded(): boolean {
|
||||
* Load artist favorites from local cache first, then sync from API
|
||||
*/
|
||||
export async function loadArtistFavorites(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (isLoading) return;
|
||||
|
||||
isLoading = true;
|
||||
@@ -86,6 +88,7 @@ export async function loadArtistFavorites(): Promise<void> {
|
||||
* Sync artist favorites from Qobuz API to local cache
|
||||
*/
|
||||
export async function syncFromApi(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
const allArtistIds: number[] = [];
|
||||
let offset = 0;
|
||||
@@ -128,6 +131,7 @@ export async function syncFromApi(): Promise<void> {
|
||||
* API call first → on success → update local cache → notify UI
|
||||
*/
|
||||
export async function toggleArtistFavorite(artistId: number): Promise<boolean> {
|
||||
if (skipIfRemote()) return favoriteArtistIds.has(artistId);
|
||||
if (togglingArtistIds.has(artistId)) {
|
||||
return favoriteArtistIds.has(artistId);
|
||||
}
|
||||
@@ -169,6 +173,7 @@ export async function toggleArtistFavorite(artistId: number): Promise<boolean> {
|
||||
* Used by FavoritesView after fetching from API
|
||||
*/
|
||||
export async function syncCache(artistIds: number[]): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_sync_cached_favorite_artists', { artistIds });
|
||||
favoriteArtistIds = new Set(artistIds);
|
||||
@@ -179,6 +184,7 @@ export async function syncCache(artistIds: number[]): Promise<void> {
|
||||
}
|
||||
|
||||
export function markAsFavorite(artistId: number): void {
|
||||
if (skipIfRemote()) return;
|
||||
if (!favoriteArtistIds.has(artistId)) {
|
||||
favoriteArtistIds.add(artistId);
|
||||
invoke('v2_cache_favorite_artist', { artistId }).catch(() => {});
|
||||
@@ -187,6 +193,7 @@ export function markAsFavorite(artistId: number): void {
|
||||
}
|
||||
|
||||
export function unmarkAsFavorite(artistId: number): void {
|
||||
if (skipIfRemote()) return;
|
||||
if (favoriteArtistIds.has(artistId)) {
|
||||
favoriteArtistIds.delete(artistId);
|
||||
invoke('v2_uncache_favorite_artist', { artistId }).catch(() => {});
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
import {
|
||||
getCurrentTrack,
|
||||
getIsPlaying,
|
||||
@@ -120,6 +121,7 @@ export function getConnectedProtocol(): CastProtocol | null {
|
||||
* stop local playback, establish the cast connection, then resume on the cast device.
|
||||
*/
|
||||
export async function connectToDevice(device: CastDevice, protocol: CastProtocol): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
// Capture current playback state BEFORE stopping
|
||||
const wasPlaying = getIsPlaying();
|
||||
const currentTrack = getCurrentTrack();
|
||||
@@ -211,6 +213,7 @@ export async function connectToDevice(device: CastDevice, protocol: CastProtocol
|
||||
* If a track was playing, asks user if they want to continue locally.
|
||||
*/
|
||||
export async function disconnect(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!state.isConnected || !state.protocol) return;
|
||||
|
||||
// Capture current state BEFORE disconnecting
|
||||
@@ -314,6 +317,7 @@ export async function castTrack(
|
||||
durationSecs?: number;
|
||||
}
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!state.isConnected || !state.protocol) {
|
||||
throw new Error('Not connected to any cast device');
|
||||
}
|
||||
@@ -381,6 +385,7 @@ export async function castTrack(
|
||||
* Play/resume on cast device
|
||||
*/
|
||||
export async function castPlay(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!state.isConnected || !state.protocol) return;
|
||||
|
||||
try {
|
||||
@@ -406,6 +411,7 @@ export async function castPlay(): Promise<void> {
|
||||
* Pause on cast device
|
||||
*/
|
||||
export async function castPause(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!state.isConnected || !state.protocol) return;
|
||||
|
||||
try {
|
||||
@@ -431,6 +437,7 @@ export async function castPause(): Promise<void> {
|
||||
* Stop on cast device
|
||||
*/
|
||||
export async function castStop(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!state.isConnected || !state.protocol) return;
|
||||
|
||||
try {
|
||||
@@ -456,6 +463,7 @@ export async function castStop(): Promise<void> {
|
||||
* Seek on cast device
|
||||
*/
|
||||
export async function castSeek(positionSecs: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!state.isConnected || !state.protocol) return;
|
||||
|
||||
try {
|
||||
@@ -479,6 +487,7 @@ export async function castSeek(positionSecs: number): Promise<void> {
|
||||
* Set volume on cast device
|
||||
*/
|
||||
export async function castSetVolume(volume: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!state.isConnected || !state.protocol) return;
|
||||
|
||||
const normalizedVolume = Math.max(0, Math.min(1, volume / 100));
|
||||
@@ -521,6 +530,7 @@ export function setOnCastTrackEnded(callback: (() => Promise<void>) | null): voi
|
||||
* Start polling for cast position updates (DLNA and Chromecast)
|
||||
*/
|
||||
export function startPositionPolling(): void {
|
||||
if (skipIfRemote()) return;
|
||||
if (positionPollInterval) return;
|
||||
if (state.protocol !== 'dlna' && state.protocol !== 'chromecast') return;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
import { logRecoEvent } from '$lib/services/recoService';
|
||||
|
||||
// State
|
||||
@@ -104,6 +105,7 @@ export function isFavoritesLoaded(): boolean {
|
||||
* Call once on app init/login
|
||||
*/
|
||||
export async function loadFavorites(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (isLoading) return;
|
||||
|
||||
isLoading = true;
|
||||
@@ -142,6 +144,7 @@ export async function loadFavorites(): Promise<void> {
|
||||
* Called on login and when FavoritesView loads
|
||||
*/
|
||||
export async function syncFromApi(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
// Fetch all favorites from API (paginated)
|
||||
const allTrackIds: number[] = [];
|
||||
@@ -187,6 +190,7 @@ export async function syncFromApi(): Promise<void> {
|
||||
* Returns the new favorite state
|
||||
*/
|
||||
export async function toggleTrackFavorite(trackId: number): Promise<boolean> {
|
||||
if (skipIfRemote()) return favoriteTrackIds.has(trackId);
|
||||
// Prevent double-toggling while API call is in progress
|
||||
if (togglingTrackIds.has(trackId)) {
|
||||
return favoriteTrackIds.has(trackId);
|
||||
@@ -237,6 +241,7 @@ export async function toggleTrackFavorite(trackId: number): Promise<boolean> {
|
||||
* Add a track to favorites (used when we know it's not already favorite)
|
||||
*/
|
||||
export async function addTrackFavorite(trackId: number): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
if (favoriteTrackIds.has(trackId)) return true;
|
||||
return toggleTrackFavorite(trackId);
|
||||
}
|
||||
@@ -245,6 +250,7 @@ export async function addTrackFavorite(trackId: number): Promise<boolean> {
|
||||
* Remove a track from favorites
|
||||
*/
|
||||
export async function removeTrackFavorite(trackId: number): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
if (!favoriteTrackIds.has(trackId)) return true;
|
||||
const result = await toggleTrackFavorite(trackId);
|
||||
return !result; // Returns true if successfully removed
|
||||
@@ -255,6 +261,7 @@ export async function removeTrackFavorite(trackId: number): Promise<boolean> {
|
||||
* Used by FavoritesView after fetching from API
|
||||
*/
|
||||
export async function syncCache(trackIds: number[]): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_sync_cached_favorite_tracks', { trackIds });
|
||||
favoriteTrackIds = new Set(trackIds);
|
||||
@@ -268,6 +275,7 @@ export async function syncCache(trackIds: number[]): Promise<void> {
|
||||
* Reset store (for logout)
|
||||
*/
|
||||
export async function reset(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_clear_favorites_cache');
|
||||
} catch (err) {
|
||||
@@ -282,6 +290,7 @@ export async function reset(): Promise<void> {
|
||||
|
||||
// Legacy functions for backwards compatibility
|
||||
export function markAsFavorite(trackId: number): void {
|
||||
if (skipIfRemote()) return;
|
||||
if (!favoriteTrackIds.has(trackId)) {
|
||||
favoriteTrackIds.add(trackId);
|
||||
// Also update cache
|
||||
@@ -291,6 +300,7 @@ export function markAsFavorite(trackId: number): void {
|
||||
}
|
||||
|
||||
export function unmarkAsFavorite(trackId: number): void {
|
||||
if (skipIfRemote()) return;
|
||||
if (favoriteTrackIds.has(trackId)) {
|
||||
favoriteTrackIds.delete(trackId);
|
||||
// Also update cache
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
export type OfflineCacheStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
|
||||
|
||||
@@ -89,6 +90,7 @@ function notifyListeners(): void {
|
||||
|
||||
// Initialize offline cache states from backend
|
||||
export async function initOfflineCacheStates(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
const tracks = await invoke<CachedTrackInfo[]>('v2_get_cached_tracks');
|
||||
for (const track of tracks) {
|
||||
@@ -106,6 +108,7 @@ export async function initOfflineCacheStates(): Promise<void> {
|
||||
|
||||
// Start listening for offline cache events
|
||||
export async function startOfflineCacheEventListeners(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
// Idempotency guard: prevent duplicate listeners on HMR/remount
|
||||
if (unlisteners.length > 0) {
|
||||
return;
|
||||
@@ -178,6 +181,7 @@ export async function cacheTrackForOffline(track: {
|
||||
bitDepth?: number;
|
||||
sampleRate?: number;
|
||||
}): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
setOfflineCacheState(track.id, { status: 'queued', progress: 0 });
|
||||
await invoke('v2_cache_track_for_offline', {
|
||||
@@ -210,6 +214,7 @@ export async function cacheTracksForOfflineBatch(tracks: Array<{
|
||||
bitDepth?: number;
|
||||
sampleRate?: number;
|
||||
}>): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (tracks.length === 0) return;
|
||||
|
||||
// Mark all as queued immediately
|
||||
@@ -242,6 +247,7 @@ export async function cacheTracksForOfflineBatch(tracks: Array<{
|
||||
|
||||
// Remove a track from offline cache
|
||||
export async function removeCachedTrack(trackId: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_remove_cached_track', { trackId });
|
||||
offlineCacheStates.delete(trackId);
|
||||
@@ -254,11 +260,13 @@ export async function removeCachedTrack(trackId: number): Promise<void> {
|
||||
|
||||
// Get offline cache stats
|
||||
export async function getOfflineCacheStats(): Promise<OfflineCacheStats> {
|
||||
if (skipIfRemote()) return { totalTracks: 0, readyTracks: 0, downloadingTracks: 0, failedTracks: 0, totalSizeBytes: 0, cachePath: '' };
|
||||
return invoke<OfflineCacheStats>('v2_get_offline_cache_stats');
|
||||
}
|
||||
|
||||
// Clear all offline cache
|
||||
export async function clearOfflineCache(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_clear_offline_cache');
|
||||
offlineCacheStates.clear();
|
||||
notifyListeners();
|
||||
@@ -266,21 +274,25 @@ export async function clearOfflineCache(): Promise<void> {
|
||||
|
||||
// Open offline cache folder
|
||||
export async function openOfflineCacheFolder(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_open_offline_cache_folder');
|
||||
}
|
||||
|
||||
// Set offline cache limit
|
||||
export async function setOfflineCacheLimit(limitMb: number | null): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_set_offline_cache_limit', { limitMb });
|
||||
}
|
||||
|
||||
// Open containing folder for a specific album
|
||||
export async function openAlbumFolder(albumId: string): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_open_album_folder', { albumId });
|
||||
}
|
||||
|
||||
// Open containing folder for a specific track
|
||||
export async function openTrackFolder(trackId: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_open_track_folder', { trackId });
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
import { showToast } from './toastStore';
|
||||
|
||||
// Types matching Rust backend
|
||||
@@ -113,6 +114,7 @@ export function getOfflineReason(): OfflineReason | null {
|
||||
* Fetch current offline status from backend
|
||||
*/
|
||||
async function fetchStatus(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
const wasOffline = status.isOffline;
|
||||
const newStatus = await invoke<OfflineStatus>('v2_get_offline_status');
|
||||
@@ -148,6 +150,7 @@ async function fetchStatus(): Promise<void> {
|
||||
* Fetch offline settings from backend
|
||||
*/
|
||||
async function fetchSettings(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
settings = await invoke<OfflineSettings>('v2_get_offline_settings');
|
||||
notifyListeners();
|
||||
@@ -165,6 +168,7 @@ async function fetchSettings(): Promise<void> {
|
||||
* Check network connectivity
|
||||
*/
|
||||
export async function checkNetwork(): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
try {
|
||||
return await invoke<boolean>('v2_check_network');
|
||||
} catch (error) {
|
||||
@@ -177,6 +181,7 @@ export async function checkNetwork(): Promise<boolean> {
|
||||
* Toggle manual offline mode
|
||||
*/
|
||||
export async function setManualOffline(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
const wasOffline = status.isOffline;
|
||||
console.log('[Offline] ========================================');
|
||||
@@ -213,6 +218,7 @@ export async function setManualOffline(enabled: boolean): Promise<void> {
|
||||
* Set whether to show playlists with partial local content
|
||||
*/
|
||||
export async function setShowPartialPlaylists(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_set_show_partial_playlists', { enabled });
|
||||
settings.showPartialPlaylists = enabled;
|
||||
@@ -227,6 +233,7 @@ export async function setShowPartialPlaylists(enabled: boolean): Promise<void> {
|
||||
* Set whether to allow Chromecast while in manual offline mode
|
||||
*/
|
||||
export async function setAllowCastWhileOffline(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_set_allow_cast_while_offline', { enabled });
|
||||
settings.allowCastWhileOffline = enabled;
|
||||
@@ -241,6 +248,7 @@ export async function setAllowCastWhileOffline(enabled: boolean): Promise<void>
|
||||
* Set whether to allow immediate scrobbling to Last.fm in manual offline mode
|
||||
*/
|
||||
export async function setAllowImmediateScrobbling(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_set_allow_immediate_scrobbling', { enabled });
|
||||
settings.allowImmediateScrobbling = enabled;
|
||||
@@ -255,6 +263,7 @@ export async function setAllowImmediateScrobbling(enabled: boolean): Promise<voi
|
||||
* Set whether to queue scrobbles for later submission when back online
|
||||
*/
|
||||
export async function setAllowAccumulatedScrobbling(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_set_allow_accumulated_scrobbling', { enabled });
|
||||
settings.allowAccumulatedScrobbling = enabled;
|
||||
@@ -269,6 +278,7 @@ export async function setAllowAccumulatedScrobbling(enabled: boolean): Promise<v
|
||||
* Set whether to show network folder content in manual offline mode
|
||||
*/
|
||||
export async function setShowNetworkFoldersInManualOffline(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_set_show_network_folders_in_manual_offline', { enabled });
|
||||
settings.showNetworkFoldersInManualOffline = enabled;
|
||||
@@ -295,6 +305,7 @@ export async function refreshStatus(): Promise<void> {
|
||||
* - Listens for backend events
|
||||
*/
|
||||
export async function initOfflineStore(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (initialized) return;
|
||||
|
||||
// Fetch initial state
|
||||
@@ -351,6 +362,7 @@ export async function createPendingPlaylist(
|
||||
trackIds: number[],
|
||||
localTrackPaths: string[]
|
||||
): Promise<number> {
|
||||
if (skipIfRemote()) return 0;
|
||||
return invoke<number>('v2_create_pending_playlist', {
|
||||
name,
|
||||
description,
|
||||
@@ -364,6 +376,7 @@ export async function createPendingPlaylist(
|
||||
* Get all playlists pending sync
|
||||
*/
|
||||
export async function getPendingPlaylists(): Promise<PendingPlaylist[]> {
|
||||
if (skipIfRemote()) return [];
|
||||
return invoke<PendingPlaylist[]>('v2_get_pending_playlists');
|
||||
}
|
||||
|
||||
@@ -371,6 +384,7 @@ export async function getPendingPlaylists(): Promise<PendingPlaylist[]> {
|
||||
* Get count of pending playlists
|
||||
*/
|
||||
export async function getPendingPlaylistCount(): Promise<number> {
|
||||
if (skipIfRemote()) return 0;
|
||||
return invoke<number>('v2_get_pending_playlist_count');
|
||||
}
|
||||
|
||||
@@ -381,6 +395,7 @@ export async function markPendingPlaylistSynced(
|
||||
pendingId: number,
|
||||
qobuzPlaylistId: number
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_mark_pending_playlist_synced', { pendingId, qobuzPlaylistId });
|
||||
}
|
||||
|
||||
@@ -388,6 +403,7 @@ export async function markPendingPlaylistSynced(
|
||||
* Delete a pending playlist
|
||||
*/
|
||||
export async function deletePendingPlaylist(pendingId: number): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_delete_pending_playlist', { pendingId });
|
||||
}
|
||||
|
||||
@@ -412,6 +428,7 @@ export async function queueScrobble(
|
||||
album: string | null,
|
||||
timestamp: number
|
||||
): Promise<number> {
|
||||
if (skipIfRemote()) return 0;
|
||||
return invoke<number>('v2_queue_scrobble', {
|
||||
artist,
|
||||
track,
|
||||
@@ -424,6 +441,7 @@ export async function queueScrobble(
|
||||
* Get queued scrobbles (up to limit)
|
||||
*/
|
||||
export async function getQueuedScrobbles(limit?: number): Promise<QueuedScrobble[]> {
|
||||
if (skipIfRemote()) return [];
|
||||
return invoke<QueuedScrobble[]>('v2_get_queued_scrobbles', { limit });
|
||||
}
|
||||
|
||||
@@ -431,6 +449,7 @@ export async function getQueuedScrobbles(limit?: number): Promise<QueuedScrobble
|
||||
* Mark scrobbles as sent after successful Last.fm submission
|
||||
*/
|
||||
export async function markScrobblesSent(ids: number[]): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_mark_scrobbles_sent', { ids });
|
||||
}
|
||||
|
||||
@@ -438,6 +457,7 @@ export async function markScrobblesSent(ids: number[]): Promise<void> {
|
||||
* Get count of queued (unsent) scrobbles
|
||||
*/
|
||||
export async function getQueuedScrobbleCount(): Promise<number> {
|
||||
if (skipIfRemote()) return 0;
|
||||
return invoke<number>('v2_get_queued_scrobble_count');
|
||||
}
|
||||
|
||||
@@ -445,6 +465,7 @@ export async function getQueuedScrobbleCount(): Promise<number> {
|
||||
* Cleanup old sent scrobbles
|
||||
*/
|
||||
export async function cleanupSentScrobbles(olderThanDays?: number): Promise<number> {
|
||||
if (skipIfRemote()) return 0;
|
||||
return invoke<number>('v2_cleanup_sent_scrobbles', { olderThanDays });
|
||||
}
|
||||
|
||||
@@ -452,6 +473,7 @@ export async function cleanupSentScrobbles(olderThanDays?: number): Promise<numb
|
||||
* Sync all pending playlists to Qobuz when back online
|
||||
*/
|
||||
export async function syncPendingPlaylists(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
console.log('[Offline] Syncing pending playlists...');
|
||||
const pending = await getPendingPlaylists();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
// ============ Types ============
|
||||
|
||||
@@ -46,6 +47,7 @@ export async function setPlaybackContext(
|
||||
trackIds: number[],
|
||||
startPosition: number
|
||||
): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
console.log('[PlaybackContext] Setting context:', { contextType, id, label, trackIds: trackIds.length, startPosition });
|
||||
|
||||
await invoke('v2_set_playback_context', {
|
||||
@@ -75,6 +77,7 @@ export async function setPlaybackContext(
|
||||
* Clear the playback context (e.g., when playing single track)
|
||||
*/
|
||||
export async function clearPlaybackContext(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
console.log('[PlaybackContext] Clearing context');
|
||||
await invoke('v2_clear_playback_context');
|
||||
currentContext = null;
|
||||
@@ -86,6 +89,7 @@ export async function clearPlaybackContext(): Promise<void> {
|
||||
* Get the current playback context
|
||||
*/
|
||||
export async function getPlaybackContext(): Promise<PlaybackContext | null> {
|
||||
if (skipIfRemote()) return null;
|
||||
const context = await invoke<PlaybackContext | null>('v2_get_playback_context');
|
||||
currentContext = context;
|
||||
notifyListeners();
|
||||
@@ -96,6 +100,7 @@ export async function getPlaybackContext(): Promise<PlaybackContext | null> {
|
||||
* Check if a context is active
|
||||
*/
|
||||
export async function hasPlaybackContext(): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
return await invoke<boolean>('v2_has_playback_context');
|
||||
}
|
||||
|
||||
@@ -168,6 +173,7 @@ export function subscribe(listener: () => void): () => void {
|
||||
* Initialize context store (call on app startup)
|
||||
*/
|
||||
export async function initPlaybackContextStore(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
// Sync initial state from backend
|
||||
await getPlaybackContext();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
// ============ Types ============
|
||||
|
||||
@@ -38,6 +39,7 @@ function notifyListeners(): void {
|
||||
* Get current playback preferences
|
||||
*/
|
||||
export async function getPlaybackPreferences(): Promise<PlaybackPreferences> {
|
||||
if (skipIfRemote()) return preferences;
|
||||
const prefs = await invoke<PlaybackPreferences>('v2_get_playback_preferences');
|
||||
preferences = prefs;
|
||||
notifyListeners();
|
||||
@@ -48,6 +50,7 @@ export async function getPlaybackPreferences(): Promise<PlaybackPreferences> {
|
||||
* Set autoplay mode
|
||||
*/
|
||||
export async function setAutoplayMode(mode: AutoplayMode): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_set_autoplay_mode', { mode });
|
||||
preferences.autoplay_mode = mode;
|
||||
notifyListeners();
|
||||
@@ -66,6 +69,7 @@ export async function setAutoplayMode(mode: AutoplayMode): Promise<void> {
|
||||
* Set whether to show context icon in player
|
||||
*/
|
||||
export async function setShowContextIcon(show: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_set_show_context_icon', { show });
|
||||
preferences.show_context_icon = show;
|
||||
notifyListeners();
|
||||
@@ -75,6 +79,7 @@ export async function setShowContextIcon(show: boolean): Promise<void> {
|
||||
* Set whether to persist session on close/restart
|
||||
*/
|
||||
export async function setPersistSession(persist: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_set_persist_session', { persist });
|
||||
preferences.persist_session = persist;
|
||||
notifyListeners();
|
||||
@@ -108,5 +113,6 @@ export function subscribe(listener: () => void): () => void {
|
||||
* Initialize preferences store (call on app startup)
|
||||
*/
|
||||
export async function initPlaybackPreferences(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await getPlaybackPreferences();
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
// Types matching the Rust backend
|
||||
export interface PlaylistFolder {
|
||||
@@ -134,12 +135,13 @@ export function getLastError(): string | null {
|
||||
* Load folders from backend
|
||||
*/
|
||||
export async function loadFolders(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
isLoading = true;
|
||||
lastError = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
const result = await invoke<PlaylistFolder[]>('v2_get_playlist_folders');
|
||||
const result = await invoke<PlaylistFolder[]>('v2_get_playlist_folders');
|
||||
folders = result;
|
||||
lastError = null;
|
||||
} catch (err) {
|
||||
@@ -160,8 +162,9 @@ export async function createFolder(
|
||||
iconPreset?: string,
|
||||
iconColor?: string
|
||||
): Promise<PlaylistFolder | null> {
|
||||
if (skipIfRemote()) return null;
|
||||
try {
|
||||
const folder = await invoke<PlaylistFolder>('v2_create_playlist_folder', {
|
||||
const folder = await invoke<PlaylistFolder>('v2_create_playlist_folder', {
|
||||
name,
|
||||
iconType,
|
||||
iconPreset,
|
||||
@@ -192,8 +195,9 @@ export async function updateFolder(
|
||||
isHidden?: boolean;
|
||||
}
|
||||
): Promise<PlaylistFolder | null> {
|
||||
if (skipIfRemote()) return null;
|
||||
try {
|
||||
const folder = await invoke<PlaylistFolder>('v2_update_playlist_folder', {
|
||||
const folder = await invoke<PlaylistFolder>('v2_update_playlist_folder', {
|
||||
id,
|
||||
name: updates.name,
|
||||
iconType: updates.iconType,
|
||||
@@ -222,6 +226,7 @@ export async function updateFolder(
|
||||
* Delete a folder (playlists return to root)
|
||||
*/
|
||||
export async function deleteFolder(id: string): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
try {
|
||||
await invoke('v2_delete_playlist_folder', { id });
|
||||
folders = folders.filter(f => f.id !== id);
|
||||
@@ -240,6 +245,7 @@ export async function deleteFolder(id: string): Promise<boolean> {
|
||||
* Reorder folders
|
||||
*/
|
||||
export async function reorderFolders(folderIds: string[]): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
try {
|
||||
await invoke('v2_reorder_playlist_folders', { folderIds });
|
||||
|
||||
@@ -279,6 +285,7 @@ export async function movePlaylistToFolder(
|
||||
playlistId: number,
|
||||
folderId: string | null
|
||||
): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
try {
|
||||
await invoke('v2_move_playlist_to_folder', {
|
||||
playlistId,
|
||||
@@ -298,6 +305,7 @@ export async function movePlaylistToFolder(
|
||||
* Toggle folder hidden status
|
||||
*/
|
||||
export async function toggleFolderHidden(id: string): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
const folder = folders.find(f => f.id === id);
|
||||
if (!folder) return false;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { writable, get } from 'svelte/store';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
// Store for ToS acceptance - persisted in Rust (survives app updates)
|
||||
export const qobuzTosAccepted = writable<boolean>(false);
|
||||
@@ -13,6 +14,7 @@ let initialized = false;
|
||||
* Should be called early in app initialization.
|
||||
*/
|
||||
export async function loadTosAcceptance(): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
if (!browser) return false;
|
||||
|
||||
try {
|
||||
@@ -45,6 +47,7 @@ export async function loadTosAcceptance(): Promise<boolean> {
|
||||
* Set ToS acceptance state in Rust backend.
|
||||
*/
|
||||
export async function setTosAcceptance(accepted: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
if (!browser) return;
|
||||
|
||||
try {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
import { platform } from '$lib/utils/platform';
|
||||
|
||||
const STORAGE_KEY_HIDE = 'qbz-hide-titlebar';
|
||||
@@ -33,6 +34,7 @@ function notifyListeners(): void {
|
||||
* Initialize the store from localStorage
|
||||
*/
|
||||
export function initTitleBarStore(): void {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
const savedHide = localStorage.getItem(STORAGE_KEY_HIDE);
|
||||
if (savedHide !== null) {
|
||||
@@ -142,6 +144,7 @@ export function setHideTitleBar(value: boolean): void {
|
||||
* decoration state — runtime toggling doesn't work reliably on Linux/Wayland.
|
||||
*/
|
||||
export async function setUseSystemTitleBar(value: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
useSystemTitleBar = value;
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY_SYSTEM, String(value));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { skipIfRemote } from '$lib/services/commandRouter';
|
||||
|
||||
export interface UpdatePreferences {
|
||||
checkOnLaunch: boolean;
|
||||
@@ -63,6 +64,7 @@ export function getCurrentVersion(): string {
|
||||
}
|
||||
|
||||
export async function initUpdatesStore(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
// get_current_version never needs a session (compile-time value).
|
||||
// Only fetch once.
|
||||
if (!versionLoaded) {
|
||||
@@ -90,6 +92,7 @@ export async function initUpdatesStore(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function refreshUpdatePreferences(): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
preferences = await invoke<UpdatePreferences>('v2_get_update_preferences');
|
||||
notify();
|
||||
@@ -99,6 +102,7 @@ export async function refreshUpdatePreferences(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function setCheckOnLaunch(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_set_update_check_on_launch', { enabled });
|
||||
preferences.checkOnLaunch = enabled;
|
||||
@@ -110,6 +114,7 @@ export async function setCheckOnLaunch(enabled: boolean): Promise<void> {
|
||||
}
|
||||
|
||||
export async function setShowWhatsNewOnLaunch(enabled: boolean): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_set_show_whats_new_on_launch', { enabled });
|
||||
preferences.showWhatsNewOnLaunch = enabled;
|
||||
@@ -121,6 +126,7 @@ export async function setShowWhatsNewOnLaunch(enabled: boolean): Promise<void> {
|
||||
}
|
||||
|
||||
export async function checkForUpdates(mode: 'launch' | 'manual'): Promise<UpdateCheckResult> {
|
||||
if (skipIfRemote()) return { status: 'no_updates', currentVersion: '', release: null };
|
||||
const result = await invoke<UpdateCheckResult>('v2_check_for_updates', { mode });
|
||||
return {
|
||||
...result,
|
||||
@@ -129,6 +135,7 @@ export async function checkForUpdates(mode: 'launch' | 'manual'): Promise<Update
|
||||
}
|
||||
|
||||
export async function fetchReleaseForVersion(version: string): Promise<ReleaseInfo | null> {
|
||||
if (skipIfRemote()) return null;
|
||||
try {
|
||||
const release = await invoke<ReleaseInfo | null>('v2_fetch_release_for_version', { version });
|
||||
return release ?? null;
|
||||
@@ -139,14 +146,17 @@ export async function fetchReleaseForVersion(version: string): Promise<ReleaseIn
|
||||
}
|
||||
|
||||
export async function acknowledgeRelease(version: string): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_acknowledge_release', { version });
|
||||
}
|
||||
|
||||
export async function ignoreRelease(version: string): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
await invoke('v2_ignore_release', { version });
|
||||
}
|
||||
|
||||
export async function hasWhatsNewBeenShown(version: string): Promise<boolean> {
|
||||
if (skipIfRemote()) return false;
|
||||
try {
|
||||
return await invoke<boolean>('v2_has_whats_new_been_shown', { version });
|
||||
} catch (error) {
|
||||
@@ -156,6 +166,7 @@ export async function hasWhatsNewBeenShown(version: string): Promise<boolean> {
|
||||
}
|
||||
|
||||
export async function markWhatsNewShown(version: string): Promise<void> {
|
||||
if (skipIfRemote()) return;
|
||||
try {
|
||||
await invoke('v2_mark_whats_new_shown', { version });
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user