diff --git a/pages/settings.vue b/pages/settings.vue index a17e106..3c39c65 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -44,8 +44,45 @@ import { import type { Component } from "vue"; import type { NavigationItem } from "~/types"; import { platform } from '@tauri-apps/plugin-os'; +import { invoke } from "@tauri-apps/api/core"; -const navigation: Array = [ +const systemData = await invoke<{ + clientId: string; + baseUrl: string; + dataDir: string; + logLevel: string; +}>("fetch_system_data"); + +const isDebugMode = ref(systemData.logLevel.toLowerCase() === "debug"); +const debugRevealed = ref(false); + +// Track shift key state and debug reveal +onMounted(() => { + window.addEventListener('keydown', (e) => { + if (e.key === 'Shift') { + isDebugMode.value = true; + debugRevealed.value = true; + } + }); + + window.addEventListener('keyup', (e) => { + if (e.key === 'Shift') { + isDebugMode.value = debugRevealed.value || systemData.logLevel.toLowerCase() === "debug"; + } + }); + + // Reset debug reveal when leaving the settings page + const router = useRouter(); + router.beforeEach((to) => { + if (!to.path.startsWith('/settings')) { + debugRevealed.value = false; + isDebugMode.value = systemData.logLevel.toLowerCase() === "debug"; + } + }); +}); + +// Make navigation reactive by wrapping in computed +const navigation = computed(() => [ { label: "Home", route: "/settings", @@ -53,7 +90,7 @@ const navigation: Array = [ icon: HomeIcon, }, { - label: "Interface", + label: "Interface", route: "/settings/interface", prefix: "/settings/interface", icon: RectangleGroupIcon, @@ -64,15 +101,21 @@ const navigation: Array = [ prefix: "/settings/downloads", icon: ArrowDownTrayIcon, }, - { + ...(isDebugMode.value ? [{ label: "Debug Info", - route: "/settings/debug", + route: "/settings/debug", prefix: "/settings/debug", icon: BugAntIcon, - }, -]; + }] : []), +]); const currentPlatform = platform(); -const currentPageIndex = useCurrentNavigationIndex(navigation); +// Use .value to unwrap the computed ref +const currentPageIndex = useCurrentNavigationIndex(navigation.value); + +// Watch for navigation changes and update currentPageIndex +watch(navigation, (newNav) => { + currentPageIndex.value = useCurrentNavigationIndex(newNav).value; +}); diff --git a/src-tauri/src/debug.rs b/src-tauri/src/debug.rs index de42dd6..a575b71 100644 --- a/src-tauri/src/debug.rs +++ b/src-tauri/src/debug.rs @@ -1,4 +1,5 @@ use crate::{DATA_ROOT_DIR, DB}; +use log::LevelFilter; use serde::Serialize; #[derive(Serialize)] @@ -7,6 +8,7 @@ pub struct SystemData { client_id: String, base_url: String, data_dir: String, + log_level: String, } #[tauri::command] @@ -16,6 +18,7 @@ pub fn fetch_system_data() -> Result { client_id: db_handle.auth.as_ref().unwrap().client_id.clone(), base_url: db_handle.base_url.clone(), data_dir: DATA_ROOT_DIR.lock().unwrap().to_string_lossy().to_string(), + log_level: std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()), }; drop(db_handle);