Skip to content

Commit

Permalink
[mod] 添加刷新事件返回结构
Browse files Browse the repository at this point in the history
  • Loading branch information
Borber committed Sep 23, 2023
1 parent e5811fc commit 58f8207
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
10 changes: 7 additions & 3 deletions crates/gui/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,12 +52,15 @@ async fn play(url: String) -> Resp<bool> {
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")) {
Expand All @@ -72,6 +75,7 @@ async fn main() {
add_subscribe,
remove_subscribe,
play,
refresh,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
19 changes: 13 additions & 6 deletions crates/gui/src-tauri/src/manager/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,7 +38,6 @@ pub async fn refresh_all(app: &App) -> Result<()> {

loop {
if lists.is_empty() {
// TODO 发送更新完毕事件
break;
}

Expand Down
1 change: 0 additions & 1 deletion crates/gui/src-tauri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ use std::error::Error;
use tauri::{App, Manager};

pub fn handler(app: &mut App) -> Result<(), Box<dyn Error>> {

Ok(())
}

0 comments on commit 58f8207

Please sign in to comment.