feat(offline): disable external services when offline

- DownloadButton: show CloudOff icon and disable when offline
- LyricsStore: skip fetching and show "unavailable offline" message
- LocalLibraryView: skip artist image fetching from Qobuz/Discogs
- PlaylistImportModal: disable import with warning when offline
This commit is contained in:
vicrodh committed 2026-01-15 23:07:16 -06:00
1 parent 6e0d7486b0
commit 4891b9bcbc
4 files changed
+112 -5

No files matched your search

+39 -2
View File
@@ -1,5 +1,10 @@
<script lang="ts">
import { Download, Check, Loader, AlertCircle } from 'lucide-svelte';
import { Download, Check, Loader, AlertCircle, CloudOff } from 'lucide-svelte';
import { t } from '$lib/i18n';
import {
subscribe as subscribeOffline,
isOffline as checkIsOffline
} from '$lib/stores/offlineStore';
type DownloadStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
@@ -19,9 +24,24 @@
onRemove
}: Props = $props();
// Offline state
let isOffline = $state(checkIsOffline());
$effect(() => {
const unsubscribe = subscribeOffline(() => {
isOffline = checkIsOffline();
});
return unsubscribe;
});
function handleClick(e: MouseEvent) {
e.stopPropagation();
// Don't allow new downloads when offline
if (isOffline && (status === 'none' || status === 'failed')) {
return;
}
if (status === 'none' || status === 'failed') {
onDownload?.();
} else if (status === 'ready') {
@@ -30,6 +50,10 @@
}
const title = $derived(() => {
// Show offline message when trying to download while offline
if (isOffline && (status === 'none' || status === 'failed')) {
return $t('offline.featureDisabled');
}
switch (status) {
case 'none': return 'Download for offline';
case 'queued': return 'Queued for download';
@@ -39,6 +63,11 @@
default: return '';
}
});
// Disable button when offline and not already downloaded
const isDisabled = $derived(
status === 'queued' || (isOffline && status !== 'ready')
);
</script>
<button
@@ -46,9 +75,10 @@
class:downloading={status === 'downloading' || status === 'queued'}
class:ready={status === 'ready'}
class:failed={status === 'failed'}
class:offline={isOffline && status !== 'ready'}
onclick={handleClick}
title={title()}
disabled={status === 'queued'}
disabled={isDisabled}
>
{#if status === 'ready'}
<Check {size} />
@@ -58,6 +88,8 @@
</div>
{:else if status === 'failed'}
<AlertCircle {size} />
{:else if isOffline}
<CloudOff {size} />
{:else}
<Download {size} />
{/if}
@@ -105,6 +137,11 @@
color: var(--accent-primary);
}
.download-button.offline {
color: var(--text-muted);
opacity: 0.5;
}
.progress-ring {
position: relative;
display: flex;
+36 -2
View File
@@ -1,7 +1,12 @@
<script lang="ts">
import { invoke } from '@tauri-apps/api/core';
import { X } from 'lucide-svelte';
import { X, CloudOff } from 'lucide-svelte';
import { showToast } from '$lib/stores/toastStore';
import { t } from '$lib/i18n';
import {
subscribe as subscribeOffline,
isOffline as checkIsOffline
} from '$lib/stores/offlineStore';
type ProviderKey = 'spotify' | 'apple' | 'tidal' | 'deezer';
@@ -42,6 +47,15 @@
let summary = $state<ImportSummary | null>(null);
let lockedProvider = $state<ProviderKey | null>(null);
let logEntries = $state<{ message: string; status: 'info' | 'success' | 'error' }[]>([]);
let isOffline = $state(checkIsOffline());
// Subscribe to offline state changes
$effect(() => {
const unsubscribe = subscribeOffline(() => {
isOffline = checkIsOffline();
});
return unsubscribe;
});
const providers: { key: ProviderKey; label: string; logo: string; color: string }[] = [
{ key: 'spotify', label: 'Spotify', logo: '/spotify-logo.svg', color: '#1DB954' },
@@ -52,7 +66,7 @@
const detectedProvider = $derived(detectProvider(url));
const activeProvider = $derived(lockedProvider ?? detectedProvider);
const isValid = $derived(!!detectedProvider);
const isValid = $derived(!!detectedProvider && !isOffline);
$effect(() => {
if (isOpen) {
@@ -179,6 +193,13 @@
</div>
<div class="modal-body">
{#if isOffline}
<div class="offline-warning">
<CloudOff size={16} />
<span>{$t('offline.featureDisabled')}</span>
</div>
{/if}
{#if error}
<div class="error-message">{error}</div>
{/if}
@@ -322,6 +343,19 @@
overflow-y: auto;
}
.offline-warning {
display: flex;
align-items: center;
gap: 8px;
background: rgba(234, 179, 8, 0.1);
border: 1px solid rgba(234, 179, 8, 0.3);
color: #eab308;
padding: 12px;
border-radius: 8px;
font-size: 13px;
margin-bottom: 16px;
}
.error-message {
background: rgba(239, 68, 68, 0.1);
border: 1px solid rgba(239, 68, 68, 0.3);
@@ -17,6 +17,10 @@
navigateTo,
getNavigationState
} from '$lib/stores/navigationStore';
import {
subscribe as subscribeOffline,
isOffline as checkIsOffline
} from '$lib/stores/offlineStore';
// Backend types matching Rust models
interface LocalTrack {
@@ -150,6 +154,7 @@
let fetchingArtwork = $state(false);
let updatingArtwork = $state(false);
let hasDiscogsCredentials = $state(false);
let isOffline = $state(checkIsOffline());
// Album detail state (for viewing album tracks)
let selectedAlbum = $state<LocalAlbum | null>(null);
@@ -167,12 +172,18 @@
let selectedFolders = $state<Set<string>>(new Set());
let unsubscribeNav: (() => void) | null = null;
let unsubscribeOffline: (() => void) | null = null;
onMount(() => {
loadLibraryData();
loadFolders();
checkDiscogsCredentials();
// Subscribe to offline state changes
unsubscribeOffline = subscribeOffline(() => {
isOffline = checkIsOffline();
});
// Subscribe to navigation changes for back/forward support
unsubscribeNav = subscribeNav(() => {
const navState = getNavigationState();
@@ -205,6 +216,9 @@
if (unsubscribeNav) {
unsubscribeNav();
}
if (unsubscribeOffline) {
unsubscribeOffline();
}
});
async function loadAlbumById(albumId: string) {
@@ -965,6 +979,12 @@
* Fetch missing artist images from Qobuz and Discogs (fallback).
*/
async function fetchMissingArtistImages(): Promise<void> {
// Don't fetch external artwork when offline
if (isOffline) {
console.log('[LocalLibrary] Skipping artist image fetch - offline mode');
return;
}
// Filter out artists we already have images for and "Various Artists"
const toFetch = artists.filter(artist => {
const normalized = normalizeArtistName(artist.name);
@@ -1396,11 +1416,16 @@
<button
class="secondary-btn"
onclick={handleFetchMissingArtwork}
disabled={fetchingArtwork}
disabled={fetchingArtwork || isOffline}
title={isOffline ? 'Artwork fetching unavailable offline' : ''}
>
<ImageDown size={14} class={fetchingArtwork ? 'spinning' : ''} />
<span>{fetchingArtwork ? 'Fetching...' : 'Fetch Missing Artwork'}</span>
</button>
{:else if isOffline}
<div class="discogs-hint">
<span>Artwork fetching unavailable offline</span>
</div>
{:else}
<div class="discogs-hint">
<span>Configure Discogs API for automatic artwork fetching</span>
+11
View File
@@ -6,6 +6,7 @@
import { invoke } from '@tauri-apps/api/core';
import { getCurrentTrack, getCurrentTime, subscribe as subscribePlayer } from './playerStore';
import { isOffline as checkIsOffline } from './offlineStore';
// ============ Types ============
@@ -271,6 +272,16 @@ export async function fetchLyrics(): Promise<void> {
return;
}
// Don't fetch lyrics when offline
if (checkIsOffline()) {
status = 'error';
error = 'Lyrics unavailable offline';
payload = null;
parsedLyrics = { lines: [], isSynced: false };
notifyListeners();
return;
}
// Skip if already fetched for this track
if (track.id === lastFetchedTrackId && status === 'loaded') {
return;