Skip to content

Commit

Permalink
fix warn
Browse files Browse the repository at this point in the history
  • Loading branch information
ForgQi committed Jun 30, 2022
1 parent 53a3728 commit 487d828
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
7 changes: 5 additions & 2 deletions src-tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,6 +21,8 @@ pub enum Error {
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
SendError(#[from] tokio::sync::mpsc::error::SendError<u64>),
#[error(transparent)]
Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error
}

Expand Down Expand Up @@ -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())
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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)))
}
}
Expand Down
27 changes: 13 additions & 14 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Vec<u16>>().as_slice()), move |event| {
let _id = window.once(encode_hex(filename.encode_utf16().collect::<Vec<u16>>().as_slice()), move |event| {
abort_handle.abort();
println!("got window event-name with payload {:?}", event.payload());
// is_remove.store(false, Ordering::Relaxed);
Expand Down Expand Up @@ -198,7 +197,7 @@ async fn get_myinfo(credential: tauri::State<'_, Credential>) -> Result<serde_js

#[tauri::command]
fn load_account() -> Result<User> {
Ok(load()?.user.ok_or(error::Error::Err("账号信息不存在".into()))?)
load()?.user.ok_or(error::Error::Err("账号信息不存在".into()))
}

#[tauri::command]
Expand All @@ -218,7 +217,7 @@ fn load() -> Result<Config> {
#[tauri::command]
async fn cover_up(input: Cow<'_, [u8]>, credential: tauri::State<'_, Credential>) -> Result<String> {
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)
}
Expand All @@ -230,7 +229,7 @@ fn is_vid(input: &str) -> bool {

#[tauri::command]
async fn show_video(input: &str, credential: tauri::State<'_, Credential>) -> Result<Studio> {
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())?;
Expand Down

0 comments on commit 487d828

Please sign in to comment.