From 58f820762bda2c5fd3873aa1311df26223b9d4ec Mon Sep 17 00:00:00 2001 From: Borber Date: Sat, 23 Sep 2023 16:11:30 +0800 Subject: [PATCH] =?UTF-8?q?[mod]=20=E6=B7=BB=E5=8A=A0=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/gui/src-tauri/src/main.rs | 10 +++++++--- crates/gui/src-tauri/src/manager/refresh.rs | 19 +++++++++++++------ crates/gui/src-tauri/src/setup.rs | 1 - 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/gui/src-tauri/src/main.rs b/crates/gui/src-tauri/src/main.rs index 43ce6b1..d18f417 100644 --- a/crates/gui/src-tauri/src/main.rs +++ b/crates/gui/src-tauri/src/main.rs @@ -3,7 +3,7 @@ use common::CONTEXT; use resp::Resp; use seam_core::{error::SeamError, live::Node}; -use tauri::{App, Manager}; +use tauri::{AppHandle, Manager}; use window_shadows::set_shadow; mod common; @@ -52,12 +52,15 @@ async fn play(url: String) -> Resp { util::play(&url).into() } - +#[tauri::command] +async fn refresh(app: AppHandle, live: String, rid: String) -> Resp<()> { + manager::refresh::refresh(&app, live, rid).await.into() +} #[tokio::main] async fn main() { CONTEXT.get_or_init(common::load).await; - + tauri::Builder::default() .setup(|app| { if cfg!(any(target_os = "macos", target_os = "windows")) { @@ -72,6 +75,7 @@ async fn main() { add_subscribe, remove_subscribe, play, + refresh, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/crates/gui/src-tauri/src/manager/refresh.rs b/crates/gui/src-tauri/src/manager/refresh.rs index 9707561..cb46bff 100644 --- a/crates/gui/src-tauri/src/manager/refresh.rs +++ b/crates/gui/src-tauri/src/manager/refresh.rs @@ -3,24 +3,32 @@ use crate::{clients, config::headers, service}; use std::collections::HashMap; use anyhow::Result; -use tauri::{App, Manager}; +use seam_core::live::Node; +use serde::Serialize; +use tauri::{AppHandle, Manager}; + +#[derive(Clone, Debug, Serialize)] +pub struct ReFreshMessage { + pub live: String, + pub node: Node, +} // TODO 声明返回类型, 指明所属平台 // 刷新单个订阅 -pub async fn refresh(app: &App, live: String, rid: String) -> Result<()> { +pub async fn refresh(app: &AppHandle, live: String, rid: String) -> Result<()> { let clients = clients!(); let node = clients .get(&live) .unwrap() .get(&rid, Some(headers(&live))) .await?; - - app.emit_all("refresh", node)?; + + app.emit_all("refresh", ReFreshMessage { live, node })?; Ok(()) } /// 刷新所有订阅的直播源 -pub async fn refresh_all(app: &App) -> Result<()> { +pub async fn refresh_all(app: &AppHandle) -> Result<()> { let lives = service::subscribe::all().await?; let mut lists = HashMap::new(); for live in lives { @@ -30,7 +38,6 @@ pub async fn refresh_all(app: &App) -> Result<()> { loop { if lists.is_empty() { - // TODO 发送更新完毕事件 break; } diff --git a/crates/gui/src-tauri/src/setup.rs b/crates/gui/src-tauri/src/setup.rs index 910b044..b08162d 100644 --- a/crates/gui/src-tauri/src/setup.rs +++ b/crates/gui/src-tauri/src/setup.rs @@ -3,6 +3,5 @@ use std::error::Error; use tauri::{App, Manager}; pub fn handler(app: &mut App) -> Result<(), Box> { - Ok(()) }