Skip to content

Commit

Permalink
More debug info, fix bad path context
Browse files Browse the repository at this point in the history
  • Loading branch information
Marekkon5 committed Jul 3, 2021
1 parent dfe526f commit 5a82f1e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
33 changes: 32 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ macro_rules! timestamp {
};
}

pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");

mod tagger;
mod tag;
mod ui;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 19 additions & 4 deletions src/ui/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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();
},
Expand All @@ -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) {
Expand All @@ -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()?
Expand Down

0 comments on commit 5a82f1e

Please sign in to comment.