From 5a82f1e44452929f5980805a18d818236f94791f Mon Sep 17 00:00:00 2001 From: Marekkon5 <marekkon5@yahoo.com> Date: Sat, 3 Jul 2021 21:40:06 +0200 Subject: [PATCH] More debug info, fix bad path context --- src/build.rs | 33 ++++++++++++++++++++++++++++++++- src/main.rs | 4 ++++ src/ui/socket.rs | 23 +++++++++++++++++++---- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/build.rs b/src/build.rs index d62d9194..fa00d2d0 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,14 +1,45 @@ +use std::env; +use std::fs::File; +use std::io::Read; +use std::path::Path; + #[cfg(windows)] extern crate winres; #[cfg(windows)] fn main() { + get_commit(); let mut res = winres::WindowsResource::new(); res.set_icon("assets\\icon.ico"); res.compile().unwrap(); } -#[cfg(unix)] +#[cfg(not(windows))] fn main() { + get_commit(); +} +//Save commit to enviromnent variable +fn get_commit() { + //Github Actions commit + let mut commit = if let Ok(commit) = env::var("GITHUB_SHA") { + commit + } else { + //Local commit + if let Ok(mut f) = File::open(Path::new(".git").join("refs").join("heads").join("master")) { + let mut buf = String::new(); + f.read_to_string(&mut buf).ok(); + buf + } else { + String::new() + } + }; + // Trim + if commit.len() > 8 { + commit = commit[..8].to_string() + } + if commit.is_empty() { + commit = "unknown".to_string(); + } + println!("cargo:rustc-env=COMMIT={}", commit); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1effd959..6a196cf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,8 @@ macro_rules! timestamp { }; } +pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + mod tagger; mod tag; mod ui; @@ -63,6 +65,8 @@ fn main() { } })); + info!("\n\nStarting OneTagger v{} Commit: {} OS: {}\n", VERSION, env!("COMMIT"), env::consts::OS); + //Parse arguments let args: Vec<String> = env::args().skip(1).collect(); let mut server_mode = false; diff --git a/src/ui/socket.rs b/src/ui/socket.rs index bfe40061..032d871e 100644 --- a/src/ui/socket.rs +++ b/src/ui/socket.rs @@ -19,8 +19,6 @@ use crate::ui::audiofeatures::{AudioFeaturesConfig, AudioFeatures}; use crate::ui::tageditor::TagEditor; use crate::playlist::UIPlaylist; -const VERSION: &'static str = env!("CARGO_PKG_VERSION"); - //Wrap of tagger config, so playlists can be passed too #[derive(Debug, Clone, Serialize, Deserialize)] struct TaggerConfigWrap { @@ -43,6 +41,22 @@ enum TaggerConfigs { AudioFeatures(AudioFeaturesConfig) } +impl TaggerConfigs { + //Print to log for later easier debug + pub fn debug_print(&self) { + match self { + TaggerConfigs::AutoTagger(c) => { + let mut c = c.clone(); + c.discogs.token = None; + info!("AutoTagger config: {:?}", c); + }, + TaggerConfigs::AudioFeatures(c) => { + info!("AudioFeatures Config: {:?}", c); + } + } + } +} + //Shared variables in socket struct SocketContext { player: AudioPlayer, @@ -112,7 +126,7 @@ fn handle_message(text: &str, websocket: &mut WebSocket<TcpStream>, context: &mu "init" => { websocket.write_message(Message::from(json!({ "action": "init", - "version": VERSION, + "version": crate::VERSION, "startContext": context.start_context }).to_string())).ok(); }, @@ -138,7 +152,7 @@ fn handle_message(text: &str, websocket: &mut WebSocket<TcpStream>, context: &mu //Browse folder "browse" => { let mut initial = json["path"].as_str().unwrap_or("."); - if initial.is_empty() { + if initial.is_empty() || !Path::new(initial).exists() { initial = "."; } if let Some(path) = tinyfiledialogs::select_folder_dialog("Select path", initial) { @@ -165,6 +179,7 @@ fn handle_message(text: &str, websocket: &mut WebSocket<TcpStream>, context: &mu let tagger_type = json["config"]["type"].clone(); let path = json["config"]["path"].as_str().unwrap_or("").to_string(); let wrap: TaggerConfigWrap = serde_json::from_value(json)?; + wrap.config.debug_print(); //Get files let files = if let Some(playlist) = wrap.playlist { playlist.get_files()?