Skip to content

Commit 5a82f1e

Browse files
committed
More debug info, fix bad path context
1 parent dfe526f commit 5a82f1e

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

src/build.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io::Read;
4+
use std::path::Path;
5+
16
#[cfg(windows)]
27
extern crate winres;
38

49
#[cfg(windows)]
510
fn main() {
11+
get_commit();
612
let mut res = winres::WindowsResource::new();
713
res.set_icon("assets\\icon.ico");
814
res.compile().unwrap();
915
}
1016

11-
#[cfg(unix)]
17+
#[cfg(not(windows))]
1218
fn main() {
19+
get_commit();
20+
}
1321

22+
//Save commit to enviromnent variable
23+
fn get_commit() {
24+
//Github Actions commit
25+
let mut commit = if let Ok(commit) = env::var("GITHUB_SHA") {
26+
commit
27+
} else {
28+
//Local commit
29+
if let Ok(mut f) = File::open(Path::new(".git").join("refs").join("heads").join("master")) {
30+
let mut buf = String::new();
31+
f.read_to_string(&mut buf).ok();
32+
buf
33+
} else {
34+
String::new()
35+
}
36+
};
37+
// Trim
38+
if commit.len() > 8 {
39+
commit = commit[..8].to_string()
40+
}
41+
if commit.is_empty() {
42+
commit = "unknown".to_string();
43+
}
44+
println!("cargo:rustc-env=COMMIT={}", commit);
1445
}

src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ macro_rules! timestamp {
2121
};
2222
}
2323

24+
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
25+
2426
mod tagger;
2527
mod tag;
2628
mod ui;
@@ -63,6 +65,8 @@ fn main() {
6365
}
6466
}));
6567

68+
info!("\n\nStarting OneTagger v{} Commit: {} OS: {}\n", VERSION, env!("COMMIT"), env::consts::OS);
69+
6670
//Parse arguments
6771
let args: Vec<String> = env::args().skip(1).collect();
6872
let mut server_mode = false;

src/ui/socket.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use crate::ui::audiofeatures::{AudioFeaturesConfig, AudioFeatures};
1919
use crate::ui::tageditor::TagEditor;
2020
use crate::playlist::UIPlaylist;
2121

22-
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
23-
2422
//Wrap of tagger config, so playlists can be passed too
2523
#[derive(Debug, Clone, Serialize, Deserialize)]
2624
struct TaggerConfigWrap {
@@ -43,6 +41,22 @@ enum TaggerConfigs {
4341
AudioFeatures(AudioFeaturesConfig)
4442
}
4543

44+
impl TaggerConfigs {
45+
//Print to log for later easier debug
46+
pub fn debug_print(&self) {
47+
match self {
48+
TaggerConfigs::AutoTagger(c) => {
49+
let mut c = c.clone();
50+
c.discogs.token = None;
51+
info!("AutoTagger config: {:?}", c);
52+
},
53+
TaggerConfigs::AudioFeatures(c) => {
54+
info!("AudioFeatures Config: {:?}", c);
55+
}
56+
}
57+
}
58+
}
59+
4660
//Shared variables in socket
4761
struct SocketContext {
4862
player: AudioPlayer,
@@ -112,7 +126,7 @@ fn handle_message(text: &str, websocket: &mut WebSocket<TcpStream>, context: &mu
112126
"init" => {
113127
websocket.write_message(Message::from(json!({
114128
"action": "init",
115-
"version": VERSION,
129+
"version": crate::VERSION,
116130
"startContext": context.start_context
117131
}).to_string())).ok();
118132
},
@@ -138,7 +152,7 @@ fn handle_message(text: &str, websocket: &mut WebSocket<TcpStream>, context: &mu
138152
//Browse folder
139153
"browse" => {
140154
let mut initial = json["path"].as_str().unwrap_or(".");
141-
if initial.is_empty() {
155+
if initial.is_empty() || !Path::new(initial).exists() {
142156
initial = ".";
143157
}
144158
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
165179
let tagger_type = json["config"]["type"].clone();
166180
let path = json["config"]["path"].as_str().unwrap_or("").to_string();
167181
let wrap: TaggerConfigWrap = serde_json::from_value(json)?;
182+
wrap.config.debug_print();
168183
//Get files
169184
let files = if let Some(playlist) = wrap.playlist {
170185
playlist.get_files()?

0 commit comments

Comments
 (0)