design: upgrade global design of the app

This commit is contained in:
2026-04-23 11:21:38 +02:00
parent a397c86bc3
commit fe108a3b61
9 changed files with 208 additions and 10 deletions

View File

@ -1,4 +1,5 @@
use tauri::{AppHandle, Manager, State};
use tauri::{AppHandle, Emitter, Manager, State};
use tauri::window::Color;
use serde::{Deserialize, Serialize};
use std::sync::Mutex;
use rusqlite::Connection;
@ -494,6 +495,61 @@ pub fn toggle_quest_step(
db::toggle_quest_step(&conn, &profile_id, &quest_name, step_index).map_err(|e| e.to_string())
}
fn percent_encode(s: &str) -> String {
let mut result = String::new();
for byte in s.bytes() {
match byte {
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
result.push(byte as char);
}
b => result.push_str(&format!("%{:02X}", b)),
}
}
result
}
#[tauri::command]
pub async fn open_image_viewer(
app: AppHandle,
state: State<'_, DbState>,
image_url: String,
) -> Result<(), String> {
if let Some(win) = app.get_webview_window("image-viewer") {
win.emit("set-viewer-image", &image_url).map_err(|e| e.to_string())?;
win.set_focus().map_err(|e| e.to_string())?;
return Ok(());
}
let (w, h, x, y) = {
let conn = state.0.lock().map_err(|e| e.to_string())?;
let w: f64 = db::get_setting(&conn, "viewer_width").and_then(|v| v.parse().ok()).unwrap_or(600.0);
let h: f64 = db::get_setting(&conn, "viewer_height").and_then(|v| v.parse().ok()).unwrap_or(500.0);
let x: Option<f64> = db::get_setting(&conn, "viewer_x").and_then(|v| v.parse().ok());
let y: Option<f64> = db::get_setting(&conn, "viewer_y").and_then(|v| v.parse().ok());
(w, h, x, y)
};
let path = format!("/?viewer=1&imageUrl={}", percent_encode(&image_url));
let mut builder = tauri::WebviewWindowBuilder::new(
&app,
"image-viewer",
tauri::WebviewUrl::App(path.into()),
)
.title("Image")
.decorations(false)
.resizable(true)
.always_on_top(true)
.background_color(Color(13, 17, 23, 255))
.inner_size(w, h);
if let (Some(x), Some(y)) = (x, y) {
builder = builder.position(x, y);
}
builder.build().map_err(|e| e.to_string())?;
Ok(())
}
fn collect_quest_names(data: &parser::GuideData) -> Vec<String> {
let mut names = Vec::new();
for section in &data.sections {