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