mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 08:12:44 +10:00
feat(debug): use shift or DEBUG RUST_LOG to show Debug Info
* Update settings.vue to have a conditional debug page * Update debug.rs to add RUST_LOG status fetching
This commit is contained in:
@ -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<NavigationItem & { icon: Component }> = [
|
||||
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",
|
||||
@ -64,15 +101,21 @@ const navigation: Array<NavigationItem & { icon: Component }> = [
|
||||
prefix: "/settings/downloads",
|
||||
icon: ArrowDownTrayIcon,
|
||||
},
|
||||
{
|
||||
...(isDebugMode.value ? [{
|
||||
label: "Debug Info",
|
||||
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;
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -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<SystemData, String> {
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user