From 2f731863a933a6d44b5a4177daebf9c7b2099f1a Mon Sep 17 00:00:00 2001 From: BTJ <2407356083@qq.com> Date: Sun, 31 Dec 2023 21:08:25 +0800 Subject: [PATCH] =?UTF-8?q?fix.=20=E5=AE=8C=E5=96=84=E5=90=84=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/.taurignore | 3 ++- src-tauri/Cargo.lock | 21 +++++++++++++++++++ src-tauri/Cargo.toml | 2 +- src-tauri/src/logger.rs | 9 +++++--- src-tauri/src/main.rs | 46 ++++++++++++++++++++--------------------- src/css/style.css | 2 +- src/js/render.js | 25 +++++++++++++++++----- 7 files changed, 73 insertions(+), 35 deletions(-) diff --git a/src-tauri/.taurignore b/src-tauri/.taurignore index a8fb5de..fd0877f 100644 --- a/src-tauri/.taurignore +++ b/src-tauri/.taurignore @@ -1 +1,2 @@ -/ffmpeg/* \ No newline at end of file +/ffmpeg/* +/Temp/* \ No newline at end of file diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a43365e..4095ce9 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1890,6 +1890,12 @@ dependencies = [ "unicase", ] +[[package]] +name = "minisign-verify" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "933dca44d65cdd53b355d0b73d380a2ff5da71f87f036053188bf1eab6a19881" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -3382,6 +3388,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bfe673cf125ef364d6f56b15e8ce7537d9ca7e4dae1cf6fbbdeed2e024db3d9" dependencies = [ "anyhow", + "base64 0.21.5", "bytes", "cocoa", "dirs-next", @@ -3395,6 +3402,7 @@ dependencies = [ "heck 0.4.1", "http", "ignore", + "minisign-verify", "objc", "once_cell", "open", @@ -3419,12 +3427,14 @@ dependencies = [ "tauri-utils", "tempfile", "thiserror", + "time", "tokio", "url", "uuid", "webkit2gtk", "webview2-com", "windows 0.39.0", + "zip", ] [[package]] @@ -4721,3 +4731,14 @@ checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" dependencies = [ "linked-hash-map", ] + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "byteorder", + "crc32fast", + "crossbeam-utils", +] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 9d4b412..1fc9f93 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -19,7 +19,7 @@ chrono = "0.4" rusqlite = { version = "0.27.0", features = ["bundled"] } regex = "1.10.2" futures = "0.3" -tauri = { version = "1.5", features = [ "os-all", "shell-open", "dialog-open", "http-request"] } +tauri = { version = "1.5", features = [ "updater", "os-all", "shell-open", "dialog-open", "http-request"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" reqwest = { version = "0.11.9", features = ["json", "cookies", "stream"] } diff --git a/src-tauri/src/logger.rs b/src-tauri/src/logger.rs index 9793d43..f05c202 100644 --- a/src-tauri/src/logger.rs +++ b/src-tauri/src/logger.rs @@ -5,13 +5,16 @@ use log4rs::{ encode::pattern::PatternEncoder, }; use log::LevelFilter; +use std::{env, path::PathBuf}; pub fn init_logger() -> Result<(), Box> { - let logfile = format!("logs/{}.log", Local::now().format("%Y-%m-%d_%H-%M-%S")); + let logfile = format!("{}/{}.log", + PathBuf::from(env::var("APPDATA").unwrap()).join("com.btjawa.bilitools").join("Logs").to_string_lossy(), + Local::now().format("%Y-%m-%d_%H-%M-%S")); let file_appender = FileAppender::builder() - .encoder(Box::new(PatternEncoder::new("[log {d(%Y-%m-%d %H:%M:%S)}] {m}{n}"))) + .encoder(Box::new(PatternEncoder::new("[{l} {d(%Y-%m-%d %H:%M:%S)}] {m}{n}"))) .build(logfile)?; let console_appender = ConsoleAppender::builder() - .encoder(Box::new(PatternEncoder::new("[log {d(%Y-%m-%d %H:%M:%S)}] {m}{n}"))) + .encoder(Box::new(PatternEncoder::new("[{l} {d(%Y-%m-%d %H:%M:%S)}] {m}{n}"))) .build(); let config = Config::builder() .appender(Appender::builder().build("file", Box::new(file_appender))) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 83a1ab7..31a45a8 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -18,14 +18,12 @@ lazy_static! { static ref LOGIN_POLLING: Arc = Arc::new(AtomicBool::new(false)); static ref DOWNLOAD_INFO_MAP: Mutex> = Mutex::new(HashMap::new()); static ref WORKING_DIR: PathBuf = { - PathBuf::from(env::var("APPDATA").expect("APPDATA environment variable not found")) - .join("com.btjawa.bilitools") + PathBuf::from(env::var("APPDATA").unwrap()).join("com.btjawa.bilitools") }; static ref DOWNLOAD_DIR: Arc> = { - Arc::new(RwLock::new(PathBuf::from(env::var("USERPROFILE").expect("USERPROFILE environment variable not found")) - .join("Desktop"))) + Arc::new(RwLock::new(PathBuf::from(env::var("USERPROFILE").unwrap()).join("Desktop"))) }; - static ref TEMP_DIR: Arc> = Arc::new(RwLock::new(WORKING_DIR.join("Temp"))); + static ref TEMP_DIR: Arc> = Arc::new(RwLock::new(env::current_dir().unwrap().join("Temp"))); static ref COOKIE_PATH: PathBuf = WORKING_DIR.join("Cookies"); static ref CONFIG_PATH: Arc> = Arc::new(RwLock::new(WORKING_DIR.join("config.json"))); static ref MAX_CONCURRENT_DOWNLOADS: Arc> = Arc::new(RwLock::new(2)); @@ -348,7 +346,7 @@ async fn download_file(window: tauri::Window, task: DownloadTask, action: String let mut downloaded: u64 = 0; let start_time = Instant::now(); let mut last_log_time = Instant::now(); - let log_interval = Duration::from_millis(250); + let log_interval = Duration::from_secs(1); while let Some(chunk_result) = stream.next().await { match chunk_result { Ok(chunk) => { @@ -392,7 +390,7 @@ async fn download_file(window: tauri::Window, task: DownloadTask, action: String async fn merge_video_audio(window: tauri::Window, audio_path: &PathBuf, video_path: &PathBuf, output: &PathBuf) -> Result { log::info!(""); log::info!("Starting merge process for audio"); - let current_dir = env::current_dir().map_err(|e| {handle_err(window.clone(), e.to_string()); e.to_string()})?; + let current_dir = env::current_dir().unwrap(); let ffmpeg_path = current_dir.join("ffmpeg").join("ffmpeg.exe"); let output_path = output.to_string_lossy(); if let Some(ss_dir_path) = output.parent() { @@ -401,7 +399,6 @@ async fn merge_video_audio(window: tauri::Window, audio_path: &PathBuf, video_pa log::info!("成功创建{}", ss_dir_path.to_string_lossy()); } } - let output_clone = output_path.clone(); let video_filename = &output.file_name() .and_then(|f| f.to_str()) .ok_or_else(|| "无法提取视频文件名".to_string())?; @@ -466,7 +463,7 @@ async fn merge_video_audio(window: tauri::Window, audio_path: &PathBuf, video_pa } } } - messages.push(&output_clone); + messages.push(&video_filename); log::info!("{:?}", messages.join(" | ")); io::stdout().flush().map_err(|e| {handle_err(window.clone(), e.to_string()); e.to_string()})?; window_clone.emit("merge-progress", &messages).map_err(|e| {handle_err(window.clone(), e.to_string()); e.to_string()})?; @@ -488,13 +485,13 @@ async fn merge_video_audio(window: tauri::Window, audio_path: &PathBuf, video_pa if status.success() { log::info!(""); log::info!("FFmpeg process completed."); - window.emit("merge-success", output).unwrap(); - Ok(output_path.to_string()) + window.emit("merge-success", video_filename).unwrap(); + Ok(video_filename.to_string()) } else { if let Err(e) = tokio::fs::remove_file(&*output_path.clone()).await { return Err(format!("无法删除合并失败视频文件: {}", e)); } - window.emit("merge-failed", output).unwrap(); + window.emit("merge-failed", video_filename).unwrap(); Err("FFmpeg command failed".to_string()) } } @@ -559,13 +556,10 @@ fn insert_cookie(window: tauri::Window, cookie_str: &str) -> Result<(), String> // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command #[tauri::command] async fn init(window: tauri::Window) -> Result { + init_database(window.clone().clone()).await; rw_config(window.clone(), "read".to_string(), None).await.map_err(|e| {handle_err(window.clone(), e.to_string()); e.to_string()})?; - let window_clone = window.clone(); stop_login(); - tokio::spawn(async move { - init_database(window_clone.clone()).await; - let _ = get_buvid(window_clone).await; - }); + let _ = get_buvid(window.clone()).await; let cookies = load_cookies().unwrap_or_else(|err| { log::warn!("Error loading cookies: {:?}", err); HashMap::new() }); if let Some(mid_cookie) = cookies.values().find(|cookie| cookie.name.eq("DedeUserID")) { @@ -632,16 +626,20 @@ async fn rw_config(window: tauri::Window, action: String, sets: Option } #[tauri::command] -async fn open_select(_window: tauri::Window, display_name: String, cid: String) { +async fn open_select(window: tauri::Window, display_name: String, cid: String) { let download_info_map = DOWNLOAD_INFO_MAP.lock().await; if let Some(video_info) = download_info_map.get(&display_name) { if video_info.cid == cid { - let _ = Command::new("C:\\Windows\\explorer.exe") - .arg(format!("/select,{}", video_info.output_path.to_string_lossy())) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("Failed to open Windows Explorer"); + if let Err(e) = fs::metadata(&video_info.output_path) { + handle_err(window.clone(), e.to_string()); + } else { + let _ = Command::new("C:\\Windows\\explorer.exe") + .arg(format!("/select,\"{}\"", video_info.output_path.to_string_lossy())) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .map_err(|e| {handle_err(window.clone(), e.to_string()); e.to_string()}); + } } } } diff --git a/src/css/style.css b/src/css/style.css index 102b314..e7113b6 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -1537,7 +1537,7 @@ input[name="temp-dir-path"] { animation: settings-page-anime 0.5s cubic-bezier(0,1,.6,1); } -.settings-page._info svg { width: 20%; } +.settings-page._info svg { width: 235px; } .settings-page._info img { width: 80px; diff --git a/src/js/render.js b/src/js/render.js index 12edc7c..c0fee19 100644 --- a/src/js/render.js +++ b/src/js/render.js @@ -216,7 +216,7 @@ async function getDownUrl(details, quality, action, line, fileType, index) { if (action=="multi") downAudios++; let qualityStr, ext, displayName; const safeTitle = videoData[index].title.replace(/\s*[\\/:*?"<>|]\s*/g, '_').replace(/\s/g, '_'); - const ssDir = videoData[index].ss_title; + const ssDir = `《${videoData[index].ss_title}》`; if (action == "only") { qualityStr = isVideo ? quality.dms_desc : quality.ads_desc; ext = isVideo ? "mp4" : "aac"; @@ -998,10 +998,22 @@ async function appendDownPageBlock(type, quality, data) { // 填充下载块 const infoDesc = $('
').addClass('down-page-info-desc').html(desc.replace(/\n/g, '
')); const infoTitle = $('
').addClass('down-page-info-title').html(finalTitle).css('max-width', `100%`); const infoProgressText = $('
').addClass('down-page-info-progress-text').html(`等待下载`); - const infoProgress = $('
').addClass('down-page-info-progress').html($('
').addClass('down-page-info-progress-bar')); - const openDirBtn = $('
').addClass('down-page-open-dir-btn').html(`打开文件`); + const infoProgressBar = $('
').addClass('down-page-info-progress-bar'); + const infoProgress = $('
').addClass('down-page-info-progress').html(infoProgressBar); + const openDirBtn = $('
').addClass('down-page-open-dir-btn').html(`定位文件`); infoBlock.append(infoCover, infoData.append(infoId, infoTitle, infoDesc, openDirBtn, infoProgressText, infoProgress)).appendTo(downPage); - openDirBtn.on('click', () => invoke('open_select', { displayName: finalTitle, cid: cid.toString() })); + openDirBtn.on('click', () => { + if (parseFloat(infoProgressBar.css('width')) / parseFloat(infoProgress.css('width')) < 1) { + iziToast.error({ + icon: 'fa-regular fa-circle-exclamation', + layout: '2', + title: `下载`, + message: `请等待下载完毕` + }); + } else { + invoke('open_select', { displayName: finalTitle, cid: cid.toString() }); + } + }); } function applyDimensionList(details, type, action, ms) { // 填充分辨率 @@ -1736,7 +1748,8 @@ listen("download-success", async (event) => { icon: 'fa-solid fa-circle-info', layout: '2', title: '下载', - message: `《${event.payload}》下载成功~`, + timeout: 10000, + message: `《${event.payload}》下载成功~
可在下载页中点击 “定位文件” 定位文件`, }); }) @@ -1745,6 +1758,7 @@ listen("download-failed", async (event) => { icon: 'fa-solid fa-circle-info', layout: '2', title: '下载', + timeout: 10000, message: `《${event.payload[0]}》下载失败
错误原因: ${event.payload[1]}`, }); }) @@ -1754,6 +1768,7 @@ listen("error", async (event) => { icon: 'fa-solid fa-circle-info', layout: '2', title: '错误', + timeout: 10000, message: `遇到错误:${event.payload}`, }); })