d70d9d5fbd
- Implemented separate sound effects volume control in settings. - Updated backend to handle new `sfx_volume` parameter. - Enhanced UI to include sound effects volume slider in admin panel. - Integrated sound effects for various user interactions (clicks, navigation, alerts). - Added a new global sound engine to manage audio synthesis without external files. - Updated documentation for Docker deployment and Windows packaging. - Refactored audio context management to ensure sound effects are available post user interaction.
60 lines
2.2 KiB
Rust
60 lines
2.2 KiB
Rust
// 说明:早期 Rust 内嵌后端(server/storage/models/events,axum :10801)已随架构迁移到
|
||
// Python 后端(FastAPI :10085)而移除;当前 Rust 侧仅负责窗口与生命周期,
|
||
// 外加一个「运行时配置读取」命令(供前端读取 exe 旁 config.json,部署免重打包改地址)。
|
||
|
||
use std::fs;
|
||
use std::path::PathBuf;
|
||
use tauri::{AppHandle, Manager};
|
||
|
||
/// 读取运行时配置(部署用,免重新打包):
|
||
/// 1) exe 同目录 config.json / dpm.config.json(最高优先)
|
||
/// 2) 应用配置目录 config.json
|
||
/// 内容示例:
|
||
/// { "api_base": "http://192.168.1.9:10085",
|
||
/// "mqtt_url": "ws://192.168.1.3:8083/mqtt",
|
||
/// "mqtt_username": "dpm", "mqtt_password": "123456" }
|
||
/// 返回 JSON 字符串;未配置返回 null。
|
||
#[tauri::command]
|
||
fn read_runtime_config(app: AppHandle) -> Option<String> {
|
||
let mut candidates: Vec<PathBuf> = Vec::new();
|
||
if let Ok(exe) = std::env::current_exe() {
|
||
if let Some(dir) = exe.parent() {
|
||
candidates.push(dir.join("config.json"));
|
||
candidates.push(dir.join("dpm.config.json"));
|
||
}
|
||
}
|
||
if let Ok(dir) = app.path().app_config_dir() {
|
||
candidates.push(dir.join("config.json"));
|
||
}
|
||
for p in candidates {
|
||
if p.exists() {
|
||
if let Ok(s) = fs::read_to_string(&p) {
|
||
let t = s.trim();
|
||
if t.starts_with('{') {
|
||
return Some(t.to_string());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
None
|
||
}
|
||
|
||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||
pub fn run() {
|
||
tauri::Builder::default()
|
||
.plugin(tauri_plugin_opener::init())
|
||
.plugin(tauri_plugin_autostart::init(
|
||
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
|
||
Some(vec![]),
|
||
))
|
||
.invoke_handler(tauri::generate_handler![read_runtime_config])
|
||
.on_window_event(|window, event| {
|
||
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
|
||
api.prevent_close();
|
||
let _ = window.minimize();
|
||
}
|
||
})
|
||
.run(tauri::generate_context!())
|
||
.expect("error while running tauri application");
|
||
}
|