- 更新前端支持触控操作

This commit is contained in:
Pine
2026-05-14 15:07:41 +08:00
parent f4dcc30c2b
commit af326571da
16 changed files with 795 additions and 38 deletions
+4
View File
@@ -42,6 +42,10 @@ pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_autostart::init(
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
Some(vec![]),
))
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+10
View File
@@ -9,6 +9,8 @@ pub struct Settings {
pub auto_play: bool,
pub play_mode: String,
pub image_duration: u32,
pub fullscreen: bool,
pub autostart: bool,
}
impl Default for Settings {
@@ -20,6 +22,8 @@ impl Default for Settings {
auto_play: true,
play_mode: "sequential".into(),
image_duration: 5,
fullscreen: true,
autostart: false,
}
}
}
@@ -88,6 +92,10 @@ pub struct ServerEvent {
pub play_mode: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub image_duration: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub fullscreen: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub autostart: Option<bool>,
}
// ============ Playlist Response ============
@@ -116,6 +124,8 @@ pub struct SettingsUpdate {
pub volume: Option<u32>,
pub play_mode: Option<String>,
pub image_duration: Option<u32>,
pub fullscreen: Option<bool>,
pub autostart: Option<bool>,
}
#[derive(Debug, Deserialize)]
+40
View File
@@ -169,6 +169,7 @@ pub fn create_router(state: AppState) -> Router {
Router::new()
.route("/api/login", post(login_handler))
.route("/api/settings", get(get_settings).post(update_settings))
.route("/api/display-command", post(display_command_handler))
.route("/media", get(list_media))
.route("/upload", post(upload_handler))
.route("/api/delete", post(delete_handler))
@@ -221,6 +222,8 @@ async fn get_settings() -> Json<serde_json::Value> {
"volume": s.volume,
"play_mode": s.play_mode,
"image_duration": s.image_duration,
"fullscreen": s.fullscreen,
"autostart": s.autostart,
}))
}
@@ -231,6 +234,8 @@ async fn update_settings(
volume: body.volume,
play_mode: body.play_mode.clone(),
image_duration: body.image_duration,
fullscreen: body.fullscreen,
autostart: body.autostart,
});
EVENTS.broadcast(&ServerEvent {
@@ -239,6 +244,8 @@ async fn update_settings(
volume: body.volume,
play_mode: body.play_mode,
image_duration: body.image_duration,
fullscreen: body.fullscreen,
autostart: body.autostart,
});
Json(serde_json::json!({"ok": true}))
@@ -356,6 +363,8 @@ async fn delete_handler(
volume: None,
play_mode: None,
image_duration: None,
fullscreen: None,
autostart: None,
});
Json(OkResponse { ok: true })
@@ -439,6 +448,8 @@ async fn add_playlist(
volume: None,
play_mode: None,
image_duration: None,
fullscreen: None,
autostart: None,
});
Json(OkResponse { ok: true })
}
@@ -453,6 +464,8 @@ async fn remove_playlist(
volume: None,
play_mode: None,
image_duration: None,
fullscreen: None,
autostart: None,
});
Json(OkResponse { ok: true })
}
@@ -472,6 +485,8 @@ async fn control_handler(
volume: None,
play_mode: None,
image_duration: None,
fullscreen: None,
autostart: None,
});
let mut playback = state.playback.lock().await;
@@ -489,11 +504,34 @@ async fn control_handler(
volume: None,
play_mode: None,
image_duration: None,
fullscreen: None,
autostart: None,
});
Ok(Json(serde_json::json!({"ok": true, "action": body.action})))
}
// ===================== Handler: 显示命令(最小化、全屏等) =====================
async fn display_command_handler(
Json(body): Json<ActionBody>,
) -> Result<Json<serde_json::Value>, (StatusCode, String)> {
match body.action.as_str() {
"minimize" => {
EVENTS.broadcast(&ServerEvent {
action: "minimize_window".into(),
state: None,
volume: None,
play_mode: None,
image_duration: None,
fullscreen: None,
autostart: None,
});
Ok(Json(serde_json::json!({"ok": true, "action": "minimize"})))
}
_ => Err((StatusCode::BAD_REQUEST, "不支持的显示命令".into())),
}
}
// ===================== Handler: 状态 =====================
async fn get_state(
State(state): State<AppState>,
@@ -527,6 +565,8 @@ async fn update_state(
volume: None,
play_mode: None,
image_duration: None,
fullscreen: None,
autostart: None,
});
Json(OkResponse { ok: true })
+6
View File
@@ -86,6 +86,12 @@ impl Storage {
if let Some(d) = update.image_duration {
s.image_duration = d;
}
if let Some(f) = update.fullscreen {
s.fullscreen = f;
}
if let Some(a) = update.autostart {
s.autostart = a;
}
}
}
self.save();