Fix offline mode toggle and add network verification
- Change OfflinePlaceholder icon to use offline.svg instead of Power icon - Add flex-shrink protection to Toggle component to prevent collapsing - Add network verification when disabling offline mode: - Check network connectivity before switching to online - Show semi-transparent overlay during check - Revert to offline and show toast if no internet available - Add check_network Tauri command to verify connectivity - Add i18n strings for noNetworkToast and checkingNetwork (en/es)
This commit is contained in:
1 parent
5c1fb23899
commit
373e61f0bd
8 files changed
+95
-18
No files matched your search
@@ -512,6 +512,7 @@ pub fn run() {
|
|||||||
offline::commands::get_offline_settings,
|
offline::commands::get_offline_settings,
|
||||||
offline::commands::set_manual_offline,
|
offline::commands::set_manual_offline,
|
||||||
offline::commands::set_show_partial_playlists,
|
offline::commands::set_show_partial_playlists,
|
||||||
|
offline::commands::check_network,
|
||||||
// Offline playlist sync queue commands
|
// Offline playlist sync queue commands
|
||||||
offline::commands::create_pending_playlist,
|
offline::commands::create_pending_playlist,
|
||||||
offline::commands::get_pending_playlists,
|
offline::commands::get_pending_playlists,
|
||||||
|
|||||||
@@ -488,6 +488,12 @@ pub mod commands {
|
|||||||
store.set_show_partial_playlists(enabled)
|
store.set_show_partial_playlists(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if network connectivity is available
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn check_network() -> bool {
|
||||||
|
super::check_network_connectivity().await
|
||||||
|
}
|
||||||
|
|
||||||
// === Pending Playlist Sync Commands ===
|
// === Pending Playlist Sync Commands ===
|
||||||
|
|
||||||
/// Create a playlist while offline (queued for sync)
|
/// Create a playlist while offline (queued for sync)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { WifiOff, CloudOff, Power, Library } from 'lucide-svelte';
|
import { Library } from 'lucide-svelte';
|
||||||
import { t } from '$lib/i18n';
|
import { t } from '$lib/i18n';
|
||||||
import type { OfflineReason } from '$lib/stores/offlineStore';
|
import type { OfflineReason } from '$lib/stores/offlineStore';
|
||||||
|
|
||||||
@@ -9,24 +9,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let { reason = null, onGoToLibrary }: Props = $props();
|
let { reason = null, onGoToLibrary }: Props = $props();
|
||||||
|
|
||||||
// Get icon based on reason
|
|
||||||
function getIcon(r: OfflineReason | null) {
|
|
||||||
switch (r) {
|
|
||||||
case 'no_network': return WifiOff;
|
|
||||||
case 'not_logged_in': return CloudOff;
|
|
||||||
case 'manual_override': return Power;
|
|
||||||
default: return WifiOff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const icon = $derived(getIcon(reason));
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="offline-placeholder" role="alert" aria-live="polite">
|
<div class="offline-placeholder" role="alert" aria-live="polite">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="icon-container" aria-hidden="true">
|
<div class="icon-container" aria-hidden="true">
|
||||||
<svelte:component this={icon} size={64} strokeWidth={1.5} />
|
<img src="/offline.svg" alt="" class="offline-icon" />
|
||||||
</div>
|
</div>
|
||||||
<h2>
|
<h2>
|
||||||
{#if reason === 'no_network'}
|
{#if reason === 'no_network'}
|
||||||
@@ -80,6 +68,12 @@
|
|||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.offline-icon {
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
filter: brightness(0) invert(0.6);
|
||||||
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|||||||
@@ -21,12 +21,14 @@
|
|||||||
.toggle {
|
.toggle {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 44px;
|
width: 44px;
|
||||||
|
min-width: 44px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
border-radius: 9999px;
|
border-radius: 9999px;
|
||||||
border: none;
|
border: none;
|
||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color 150ms ease;
|
transition: background-color 150ms ease;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle.enabled {
|
.toggle.enabled {
|
||||||
|
|||||||
@@ -34,9 +34,11 @@
|
|||||||
getSettings as getOfflineSettings,
|
getSettings as getOfflineSettings,
|
||||||
setManualOffline,
|
setManualOffline,
|
||||||
setShowPartialPlaylists,
|
setShowPartialPlaylists,
|
||||||
|
checkNetwork,
|
||||||
type OfflineStatus,
|
type OfflineStatus,
|
||||||
type OfflineSettings
|
type OfflineSettings
|
||||||
} from '$lib/stores/offlineStore';
|
} from '$lib/stores/offlineStore';
|
||||||
|
import { showToast } from '$lib/stores/toastStore';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onBack?: () => void;
|
onBack?: () => void;
|
||||||
@@ -85,6 +87,7 @@
|
|||||||
// Offline mode state
|
// Offline mode state
|
||||||
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
|
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
|
||||||
let offlineSettings = $state<OfflineSettings>(getOfflineSettings());
|
let offlineSettings = $state<OfflineSettings>(getOfflineSettings());
|
||||||
|
let isCheckingNetwork = $state(false);
|
||||||
|
|
||||||
// Audio device state
|
// Audio device state
|
||||||
let audioDevices = $state<AudioDevice[]>([]);
|
let audioDevices = $state<AudioDevice[]>([]);
|
||||||
@@ -580,10 +583,30 @@
|
|||||||
|
|
||||||
// Offline mode handlers
|
// Offline mode handlers
|
||||||
async function handleManualOfflineChange(enabled: boolean) {
|
async function handleManualOfflineChange(enabled: boolean) {
|
||||||
|
// If enabling offline mode, just do it directly
|
||||||
|
if (enabled) {
|
||||||
|
try {
|
||||||
|
await setManualOffline(true);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to enable manual offline mode:', error);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If disabling offline mode, verify network connectivity first
|
||||||
|
isCheckingNetwork = true;
|
||||||
try {
|
try {
|
||||||
await setManualOffline(enabled);
|
const hasNetwork = await checkNetwork();
|
||||||
|
if (hasNetwork) {
|
||||||
|
await setManualOffline(false);
|
||||||
|
} else {
|
||||||
|
showToast($t('offline.noNetworkToast'), 'error');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to set manual offline mode:', error);
|
console.error('Failed to disable manual offline mode:', error);
|
||||||
|
showToast($t('offline.noNetworkToast'), 'error');
|
||||||
|
} finally {
|
||||||
|
isCheckingNetwork = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1455,6 +1478,12 @@
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if isCheckingNetwork}
|
||||||
|
<div class="network-check-overlay" aria-busy="true" aria-label={$t('offline.checkingNetwork')}>
|
||||||
|
<div class="network-check-spinner"></div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.settings-view {
|
.settings-view {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -2024,6 +2053,35 @@
|
|||||||
.status-indicator.offline {
|
.status-indicator.offline {
|
||||||
color: #fbbf24;
|
color: #fbbf24;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Network check overlay */
|
||||||
|
.network-check-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 9999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.network-check-spinner {
|
||||||
|
width: 48px;
|
||||||
|
height: 48px;
|
||||||
|
border: 4px solid rgba(255, 255, 255, 0.2);
|
||||||
|
border-top-color: var(--accent-primary);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<MigrationModal
|
<MigrationModal
|
||||||
|
|||||||
@@ -444,6 +444,8 @@
|
|||||||
"notAvailable": "Not Available Offline",
|
"notAvailable": "Not Available Offline",
|
||||||
"trackNotAvailable": "This track is not available offline",
|
"trackNotAvailable": "This track is not available offline",
|
||||||
"featureDisabled": "This feature requires internet connection",
|
"featureDisabled": "This feature requires internet connection",
|
||||||
"startWithoutLogin": "Start in offline mode without logging in"
|
"startWithoutLogin": "Start in offline mode without logging in",
|
||||||
|
"noNetworkToast": "No internet connection available",
|
||||||
|
"checkingNetwork": "Checking network connection..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,6 +444,8 @@
|
|||||||
"notAvailable": "No Disponible Offline",
|
"notAvailable": "No Disponible Offline",
|
||||||
"trackNotAvailable": "Esta pista no esta disponible offline",
|
"trackNotAvailable": "Esta pista no esta disponible offline",
|
||||||
"featureDisabled": "Esta funcion requiere conexion a internet",
|
"featureDisabled": "Esta funcion requiere conexion a internet",
|
||||||
"startWithoutLogin": "Iniciar en modo offline sin autenticacion"
|
"startWithoutLogin": "Iniciar en modo offline sin autenticacion",
|
||||||
|
"noNetworkToast": "No hay conexion a internet disponible",
|
||||||
|
"checkingNetwork": "Verificando conexion a internet..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,6 +141,18 @@ async function fetchSettings(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check network connectivity
|
||||||
|
*/
|
||||||
|
export async function checkNetwork(): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
return await invoke<boolean>('check_network');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to check network:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle manual offline mode
|
* Toggle manual offline mode
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user