diff --git a/src-tauri/src/error.rs b/src-tauri/src/error.rs index 8d35297..4571a9f 100644 --- a/src-tauri/src/error.rs +++ b/src-tauri/src/error.rs @@ -2,7 +2,7 @@ use std::num::ParseIntError; use futures::future::Aborted; use thiserror::Error; // use anyhow::Result; -use serde::{Deserialize, Serialize, Serializer}; +use serde::{Serialize, Serializer}; #[derive(Error, Debug)] pub enum Error { @@ -21,6 +21,8 @@ pub enum Error { #[error(transparent)] IO(#[from] std::io::Error), #[error(transparent)] + SendError(#[from] tokio::sync::mpsc::error::SendError), + #[error(transparent)] Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error } @@ -64,10 +66,11 @@ impl Serialize for Error { Error::Other(other) => serializer.serialize_str(&other.to_string()), Error::ReqIO(e) => serializer.serialize_str(&e.to_string()), Error::YamlIO(e) => serializer.serialize_str(&e.to_string()), - Error::Err(e) => serializer.serialize_str(&e.to_string()), + Error::Err(e) => serializer.serialize_str(e), Error::Aborted(e) => serializer.serialize_str(&e.to_string()), Error::JsonIO(e) => serializer.serialize_str(&e.to_string()), Error::ParseIntError(e) => serializer.serialize_str(&e.to_string()), + Error::SendError(e) => serializer.serialize_str(&e.to_string()) } } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a26f2f8..c55adbe 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,20 +1,20 @@ use std::path::PathBuf; -use biliup::{Config, User}; -use anyhow::Context; + + use biliup::client::{Client, LoginInfo}; use std::fmt::Write; use std::pin::Pin; use std::task::Poll; -use futures::{FutureExt, Stream}; -use std::future::Future; -use std::rc::Rc; +use futures::{Stream}; + + use reqwest::Body; use bytes::{Buf, Bytes}; -use tauri::{App, Window}; + use tokio::sync::mpsc::UnboundedSender; -use tokio::sync::mpsc::Sender; + use std::sync::{Arc, RwLock}; -use tokio::sync::Mutex; + pub mod error; @@ -99,10 +99,10 @@ impl Progressbar { if n == 0 { Ok(None) } else if n < pc { - pb.send(n as u64); + pb.send(n as u64)?; Ok(Some(content_bytes.copy_to_bytes(n))) } else { - pb.send(pc as u64); + pb.send(pc as u64)?; Ok(Some(content_bytes.copy_to_bytes(pc))) } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 26cf56e..4a2e1d3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,21 +4,20 @@ windows_subsystem = "windows" )] use std::borrow::Cow; -use std::cell::Cell; + use std::path::PathBuf; use std::str::FromStr; -use std::sync::Arc; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::task::Poll; -use std::time::Instant; -use anyhow::{anyhow, bail, Context}; + + + + +use anyhow::{Context}; use biliup::{Account, Config, line, User, VideoFile}; -use biliup::client::{Client, LoginInfo}; +use biliup::client::{Client}; use biliup::video::{BiliBili, Studio, Video}; -use bytes::Buf; use futures::future::abortable; -use futures::stream::Abortable; -use tauri::{Manager, State, Window}; + +use tauri::Window; use app::{config_file, cookie_file, Credential, encode_hex}; use app::error; use app::error::Result; @@ -135,7 +134,7 @@ async fn upload(mut video: Video, window: Window, credential: tauri::State<'_, C }) }); let (a_video, abort_handle) = abortable(f_video); - let id = window.once(encode_hex(filename.encode_utf16().collect::>().as_slice()), move |event| { + let _id = window.once(encode_hex(filename.encode_utf16().collect::>().as_slice()), move |event| { abort_handle.abort(); println!("got window event-name with payload {:?}", event.payload()); // is_remove.store(false, Ordering::Relaxed); @@ -198,7 +197,7 @@ async fn get_myinfo(credential: tauri::State<'_, Credential>) -> Result Result { - Ok(load()?.user.ok_or(error::Error::Err("账号信息不存在".into()))?) + load()?.user.ok_or(error::Error::Err("账号信息不存在".into())) } #[tauri::command] @@ -218,7 +217,7 @@ fn load() -> Result { #[tauri::command] async fn cover_up(input: Cow<'_, [u8]>, credential: tauri::State<'_, Credential>) -> Result { let (login_info, client) = &*credential.get_credential().await?; - let bili = BiliBili::new(&login_info, &client); + let bili = BiliBili::new(login_info, client); let url = bili.cover_up(&input).await?; Ok(url) } @@ -230,7 +229,7 @@ fn is_vid(input: &str) -> bool { #[tauri::command] async fn show_video(input: &str, credential: tauri::State<'_, Credential>) -> Result { - let (login_info, client) = &*credential.get_credential().await?;; + let (login_info, client) = &*credential.get_credential().await?; let bili = BiliBili::new(login_info, client); let mut data = bili.video_data(biliup::video::Vid::from_str(input)?).await?; let mut studio: Studio = serde_json::from_value(data["archive"].take())?;