- DevTools off by default (no more auto-open on launch) - New "Developer" tab in Settings with a checkbox to toggle devtools - Toggle takes effect immediately (opens/closes inspector) - Setting persists: devtools restored on next launch if enabled - toggle_devtools Tauri command wraps window.open/close_devtools Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use serde_json::{json, Value};
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
use crate::llama::LlamaManager;
|
|
|
|
fn settings_path() -> PathBuf {
|
|
LlamaManager::data_dir().join("settings.json")
|
|
}
|
|
|
|
/// Load app settings from disk.
|
|
#[tauri::command]
|
|
pub fn load_settings() -> Value {
|
|
let path = settings_path();
|
|
if !path.exists() {
|
|
return json!({});
|
|
}
|
|
match fs::read_to_string(&path) {
|
|
Ok(content) => serde_json::from_str(&content).unwrap_or(json!({})),
|
|
Err(_) => json!({}),
|
|
}
|
|
}
|
|
|
|
/// Save app settings to disk.
|
|
#[tauri::command]
|
|
pub fn save_settings(settings: Value) -> Result<(), String> {
|
|
let path = settings_path();
|
|
if let Some(parent) = path.parent() {
|
|
fs::create_dir_all(parent).map_err(|e| format!("Cannot create settings dir: {e}"))?;
|
|
}
|
|
let json = serde_json::to_string_pretty(&settings).map_err(|e| e.to_string())?;
|
|
fs::write(&path, json).map_err(|e| format!("Cannot write settings: {e}"))?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Toggle devtools on the main window.
|
|
#[tauri::command]
|
|
pub fn toggle_devtools(app: tauri::AppHandle, open: bool) {
|
|
use tauri::Manager;
|
|
if let Some(window) = app.get_webview_window("main") {
|
|
if open {
|
|
window.open_devtools();
|
|
} else {
|
|
window.close_devtools();
|
|
}
|
|
}
|
|
}
|