feat(offline): add offline mode settings section
- Add Offline Mode section to SettingsView - Display current offline status with reason - Toggle for manual offline mode (Enable Offline Mode) - Toggle for showing partial playlists in offline mode - Subscribe to offlineStore for real-time status updates - Add status indicator styling (green=online, yellow=offline) cc
This commit is contained in:
1 parent
b7c1af6123
commit
78d35785ed
1 file changed
+89
@@ -28,6 +28,15 @@
|
||||
import { setLocale, locale, t } from '$lib/i18n';
|
||||
import { get } from 'svelte/store';
|
||||
import MigrationModal from '../MigrationModal.svelte';
|
||||
import {
|
||||
subscribe as subscribeOffline,
|
||||
getStatus as getOfflineStatus,
|
||||
getSettings as getOfflineSettings,
|
||||
setManualOffline,
|
||||
setShowPartialPlaylists,
|
||||
type OfflineStatus,
|
||||
type OfflineSettings
|
||||
} from '$lib/stores/offlineStore';
|
||||
|
||||
interface Props {
|
||||
onBack?: () => void;
|
||||
@@ -73,6 +82,10 @@
|
||||
let showMigrationModal = $state(false);
|
||||
let legacyTracksCount = $state(0);
|
||||
|
||||
// Offline mode state
|
||||
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
|
||||
let offlineSettings = $state<OfflineSettings>(getOfflineSettings());
|
||||
|
||||
// Audio device state
|
||||
let audioDevices = $state<AudioDevice[]>([]);
|
||||
let pipewireSinks = $state<PipewireSink[]>([]);
|
||||
@@ -265,6 +278,16 @@
|
||||
|
||||
// Check for legacy downloads
|
||||
checkLegacyDownloads();
|
||||
|
||||
// Subscribe to offline state changes
|
||||
const unsubscribeOffline = subscribeOffline(() => {
|
||||
offlineStatus = getOfflineStatus();
|
||||
offlineSettings = getOfflineSettings();
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsubscribeOffline();
|
||||
};
|
||||
});
|
||||
|
||||
async function loadLastfmState() {
|
||||
@@ -555,6 +578,23 @@
|
||||
localStorage.setItem('qbz-prefer-highest', String(enabled));
|
||||
}
|
||||
|
||||
// Offline mode handlers
|
||||
async function handleManualOfflineChange(enabled: boolean) {
|
||||
try {
|
||||
await setManualOffline(enabled);
|
||||
} catch (error) {
|
||||
console.error('Failed to set manual offline mode:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleShowPartialPlaylistsChange(enabled: boolean) {
|
||||
try {
|
||||
await setShowPartialPlaylists(enabled);
|
||||
} catch (error) {
|
||||
console.error('Failed to set show partial playlists:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLanguageChange(lang: string) {
|
||||
language = lang;
|
||||
const localeCode = languageToLocale[lang];
|
||||
@@ -953,6 +993,45 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Offline Mode Section -->
|
||||
<section class="section">
|
||||
<h3 class="section-title">{$t('offline.title')}</h3>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<span class="setting-label">{$t('offline.status')}</span>
|
||||
<span class="setting-desc status-indicator" class:offline={offlineStatus.isOffline}>
|
||||
{#if offlineStatus.isOffline}
|
||||
{#if offlineStatus.reason === 'no_network'}
|
||||
{$t('offline.noNetwork')}
|
||||
{:else if offlineStatus.reason === 'not_logged_in'}
|
||||
{$t('offline.notLoggedIn')}
|
||||
{:else if offlineStatus.reason === 'manual_override'}
|
||||
{$t('offline.manualMode')}
|
||||
{:else}
|
||||
{$t('offline.offlineReason')}
|
||||
{/if}
|
||||
{:else}
|
||||
{$t('offline.online')}
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<span class="setting-label">{$t('offline.enableManual')}</span>
|
||||
<span class="setting-desc">{$t('offline.enableManualDesc')}</span>
|
||||
</div>
|
||||
<Toggle enabled={offlineSettings.manualOfflineMode} onchange={handleManualOfflineChange} />
|
||||
</div>
|
||||
<div class="setting-row last">
|
||||
<div class="setting-info">
|
||||
<span class="setting-label">{$t('offline.showPartialPlaylists')}</span>
|
||||
<span class="setting-desc">{$t('offline.showPartialPlaylistsDesc')}</span>
|
||||
</div>
|
||||
<Toggle enabled={offlineSettings.showPartialPlaylists} onchange={handleShowPartialPlaylistsChange} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Appearance Section -->
|
||||
<section class="section">
|
||||
<h3 class="section-title">{$t('settings.appearance.title')}</h3>
|
||||
@@ -1935,6 +2014,16 @@
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Offline status indicator */
|
||||
.status-indicator {
|
||||
font-weight: 500;
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
.status-indicator.offline {
|
||||
color: #fbbf24;
|
||||
}
|
||||
</style>
|
||||
|
||||
<MigrationModal
|
||||
|
||||
Reference in new issue
Block a user