From d11788c1a6749470ba982159f16fb9a533a15249 Mon Sep 17 00:00:00 2001 From: Borber Date: Fri, 22 Sep 2023 15:49:43 +0800 Subject: [PATCH 1/4] [mod] TODO --- .prettierrc.toml | 10 ---------- TODO.md | 1 + 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 .prettierrc.toml create mode 100644 TODO.md diff --git a/.prettierrc.toml b/.prettierrc.toml deleted file mode 100644 index 2a42e39..0000000 --- a/.prettierrc.toml +++ /dev/null @@ -1,10 +0,0 @@ -trailingComma = "es5" -tabWidth = 4 -semi = false -singleQuote = true - -[[overrides]] -files = ['*.yaml', '*.yml'] - -[overrides.options] -tabWidth = 2 diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..9895f05 --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +- 给 Client 添加函数返回其函数调用信息, 命令, 平台名称 From 9d38597b83b60296986ffe749afbde7c85ec86d0 Mon Sep 17 00:00:00 2001 From: Borber Date: Sat, 23 Sep 2023 10:43:20 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[mod]=20=E5=88=A0=E9=99=A4=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/gui/src-tauri/src/database/mod.rs | 2 +- crates/gui/src-tauri/src/main.rs | 12 +++++++--- crates/gui/src-tauri/src/service/subscribe.rs | 22 +++++++++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/crates/gui/src-tauri/src/database/mod.rs b/crates/gui/src-tauri/src/database/mod.rs index 457d011..372a821 100644 --- a/crates/gui/src-tauri/src/database/mod.rs +++ b/crates/gui/src-tauri/src/database/mod.rs @@ -3,7 +3,7 @@ pub mod subscribe; use anyhow::Result; use sea_orm::*; -// TODO 初始化创建表 +/// 初始化数据库 pub async fn init(db: &DatabaseConnection) -> Result { let backend = DbBackend::Sqlite; let schema = Schema::new(backend); diff --git a/crates/gui/src-tauri/src/main.rs b/crates/gui/src-tauri/src/main.rs index 68334a6..46e4157 100644 --- a/crates/gui/src-tauri/src/main.rs +++ b/crates/gui/src-tauri/src/main.rs @@ -31,14 +31,19 @@ async fn url(live: String, rid: String) -> Resp { } } +#[tauri::command] +async fn all_subscribe() -> Resp> { + service::subscribe::all().await.into() +} + #[tauri::command] async fn add_subscribe(live: String, rid: String) -> Resp { service::subscribe::add(live, rid).await.into() } #[tauri::command] -async fn all_subscribe() -> Resp> { - service::subscribe::all().await.into() +async fn remove_subscribe(live: String, rid: String) -> Resp { + service::subscribe::remove(live, rid).await.into() } #[tauri::command] @@ -60,8 +65,9 @@ async fn main() { }) .invoke_handler(tauri::generate_handler![ url, - add_subscribe, all_subscribe, + add_subscribe, + remove_subscribe, play, ]) .run(tauri::generate_context!()) diff --git a/crates/gui/src-tauri/src/service/subscribe.rs b/crates/gui/src-tauri/src/service/subscribe.rs index 53857ed..9e58311 100644 --- a/crates/gui/src-tauri/src/service/subscribe.rs +++ b/crates/gui/src-tauri/src/service/subscribe.rs @@ -3,6 +3,16 @@ use sea_orm::*; use crate::{database::subscribe, pool}; +/// 获取所有订阅 +/// +/// Get all subscribe +pub async fn all() -> Result> { + Ok(subscribe::Entity::find().all(pool!()).await?) +} + +/// 添加订阅 +/// +/// Add subscribe pub async fn add(live: String, rid: String) -> Result { subscribe::Entity::insert(subscribe::ActiveModel { live: Set(live), @@ -13,6 +23,14 @@ pub async fn add(live: String, rid: String) -> Result { Ok(true) } -pub async fn all() -> Result> { - Ok(subscribe::Entity::find().all(pool!()).await?) +/// 删除订阅 +/// +/// Delete subscribe +pub async fn remove(live: String, rid: String) -> Result { + subscribe::Entity::delete_many() + .filter(subscribe::Column::Live.eq(live)) + .filter(subscribe::Column::Rid.eq(rid)) + .exec(pool!()) + .await?; + Ok(true) } From e5811fcbd085dc74df2c32c40222c92a5e504e95 Mon Sep 17 00:00:00 2001 From: Borber Date: Sat, 23 Sep 2023 14:58:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[mod]=20=E6=B7=BB=E5=8A=A0=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=9C=8D=E5=8A=A1,=20=E5=B0=9A=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=94=A8,=20=E8=BF=98=E9=9C=80=E8=A6=81=E5=A4=A7=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/gui/src-tauri/src/main.rs | 7 ++- crates/gui/src-tauri/src/manager/mod.rs | 17 +----- crates/gui/src-tauri/src/manager/refresh.rs | 67 +++++++++++++++++++++ crates/gui/src-tauri/src/setup.rs | 8 +++ 4 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 crates/gui/src-tauri/src/manager/refresh.rs create mode 100644 crates/gui/src-tauri/src/setup.rs diff --git a/crates/gui/src-tauri/src/main.rs b/crates/gui/src-tauri/src/main.rs index 46e4157..43ce6b1 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::Manager; +use tauri::{App, Manager}; use window_shadows::set_shadow; mod common; @@ -13,6 +13,7 @@ mod manager; mod model; mod resp; mod service; +mod setup; mod util; #[tauri::command] @@ -51,10 +52,12 @@ async fn play(url: String) -> Resp { util::play(&url).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")) { diff --git a/crates/gui/src-tauri/src/manager/mod.rs b/crates/gui/src-tauri/src/manager/mod.rs index e4a403c..1d2e0f5 100644 --- a/crates/gui/src-tauri/src/manager/mod.rs +++ b/crates/gui/src-tauri/src/manager/mod.rs @@ -1,16 +1 @@ -// TODO 更新直播 -// 1. 获取所有订阅主播 -// 2. 将同平台的主播分组 -// 3. 每次取不同平台的一个主播获取直播源 -// 4. 将获取到的数据通过事件通知前端 -// - 开播 -// - 存在卡片, 不做动作 -// - 不存在卡片, 新增直播卡片 -// - 未开播 -// - 存在卡片, 删除 -// - 不存在卡片, 不做动作 - -// TODO 定时更新直播 - -// TODO 手动更新 -// 1. 全部获取完毕发送更新完毕通知给前端 +pub mod refresh; diff --git a/crates/gui/src-tauri/src/manager/refresh.rs b/crates/gui/src-tauri/src/manager/refresh.rs new file mode 100644 index 0000000..9707561 --- /dev/null +++ b/crates/gui/src-tauri/src/manager/refresh.rs @@ -0,0 +1,67 @@ +use crate::{clients, config::headers, service}; + +use std::collections::HashMap; + +use anyhow::Result; +use tauri::{App, Manager}; + +// TODO 声明返回类型, 指明所属平台 +// 刷新单个订阅 +pub async fn refresh(app: &App, 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)?; + Ok(()) +} + +/// 刷新所有订阅的直播源 +pub async fn refresh_all(app: &App) -> Result<()> { + let lives = service::subscribe::all().await?; + let mut lists = HashMap::new(); + for live in lives { + let entry = lists.entry(live.live).or_insert_with(Vec::new); + entry.push(live.rid); + } + + loop { + if lists.is_empty() { + // TODO 发送更新完毕事件 + break; + } + + let once = lists + .iter_mut() + .map(|(live, rids)| rids.pop().map(|rid| (live.clone(), rid))) + .collect::>(); + + for (live, rid) in once.into_iter().flatten() { + refresh(app, live, rid).await?; + } + + // 去除所需获取主播为空的平台 + lists.retain(|_, rids| !rids.is_empty()); + + // 等待间隔 + tokio::time::sleep(std::time::Duration::from_millis(300)).await; + } + Ok(()) +} + +// TODO 手动更新 +// 1. 全部获取完毕发送更新完毕通知给前端 +// - 开播 +// - 存在卡片, 不做动作 +// - 不存在卡片, 新增直播卡片 +// - 未开播 +// - 存在卡片, 删除 +// - 不存在卡片, 不做动作 + +// TODO 定时更新直播 +// 界面启动时,调用后端命令,然后获取App句柄,随后进行循环命令 + +// TODO 设置增加 每次自动刷新的间隔时间 diff --git a/crates/gui/src-tauri/src/setup.rs b/crates/gui/src-tauri/src/setup.rs new file mode 100644 index 0000000..910b044 --- /dev/null +++ b/crates/gui/src-tauri/src/setup.rs @@ -0,0 +1,8 @@ +use std::error::Error; + +use tauri::{App, Manager}; + +pub fn handler(app: &mut App) -> Result<(), Box> { + + Ok(()) +} From 58f820762bda2c5fd3873aa1311df26223b9d4ec Mon Sep 17 00:00:00 2001 From: Borber Date: Sat, 23 Sep 2023 16:11:30 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[mod]=20=E6=B7=BB=E5=8A=A0=E5=88=B7?= =?UTF-8?q?=E6=96=B0=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(()) }