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 { setLocale, locale, t } from '$lib/i18n';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import MigrationModal from '../MigrationModal.svelte';
|
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 {
|
interface Props {
|
||||||
onBack?: () => void;
|
onBack?: () => void;
|
||||||
@@ -73,6 +82,10 @@
|
|||||||
let showMigrationModal = $state(false);
|
let showMigrationModal = $state(false);
|
||||||
let legacyTracksCount = $state(0);
|
let legacyTracksCount = $state(0);
|
||||||
|
|
||||||
|
// Offline mode state
|
||||||
|
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
|
||||||
|
let offlineSettings = $state<OfflineSettings>(getOfflineSettings());
|
||||||
|
|
||||||
// Audio device state
|
// Audio device state
|
||||||
let audioDevices = $state<AudioDevice[]>([]);
|
let audioDevices = $state<AudioDevice[]>([]);
|
||||||
let pipewireSinks = $state<PipewireSink[]>([]);
|
let pipewireSinks = $state<PipewireSink[]>([]);
|
||||||
@@ -265,6 +278,16 @@
|
|||||||
|
|
||||||
// Check for legacy downloads
|
// Check for legacy downloads
|
||||||
checkLegacyDownloads();
|
checkLegacyDownloads();
|
||||||
|
|
||||||
|
// Subscribe to offline state changes
|
||||||
|
const unsubscribeOffline = subscribeOffline(() => {
|
||||||
|
offlineStatus = getOfflineStatus();
|
||||||
|
offlineSettings = getOfflineSettings();
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unsubscribeOffline();
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
async function loadLastfmState() {
|
async function loadLastfmState() {
|
||||||
@@ -555,6 +578,23 @@
|
|||||||
localStorage.setItem('qbz-prefer-highest', String(enabled));
|
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) {
|
async function handleLanguageChange(lang: string) {
|
||||||
language = lang;
|
language = lang;
|
||||||
const localeCode = languageToLocale[lang];
|
const localeCode = languageToLocale[lang];
|
||||||
@@ -953,6 +993,45 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</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 -->
|
<!-- Appearance Section -->
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<h3 class="section-title">{$t('settings.appearance.title')}</h3>
|
<h3 class="section-title">{$t('settings.appearance.title')}</h3>
|
||||||
@@ -1935,6 +2014,16 @@
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Offline status indicator */
|
||||||
|
.status-indicator {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #4ade80;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-indicator.offline {
|
||||||
|
color: #fbbf24;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<MigrationModal
|
<MigrationModal
|
||||||
|
|||||||
Reference in new issue
Block a user