diff --git a/Cargo.toml b/Cargo.toml index 194525b..01800dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ skulpin = "0.5" derive-new = "0.5" env_logger = "0.7.1" rmpv = "0.4.2" -msgbox = "0.4.0" rust-embed = { version = "5.2.0", features = ["debug-embed"] } image = "0.22.3" nvim-rs = { git = "https://github.com/KillTheMule/nvim-rs", branch = "futures", features = [ "use_tokio" ] } @@ -23,6 +22,9 @@ async-trait = "0.1.18" lazy_static = "1.4.0" unicode-segmentation = "1.6.0" +[target.'cfg(not(linux))'.dependencies] +msgbox = { version = "0.4.0"} + [build-dependencies] winres = "0.1.11" diff --git a/src/bridge/events.rs b/src/bridge/events.rs index 15fd229..757dad9 100644 --- a/src/bridge/events.rs +++ b/src/bridge/events.rs @@ -223,7 +223,7 @@ fn parse_mode_info_set(mode_info_set_arguments: Vec) -> Result, - #[new(default)] pub style_id: Option, - #[new(default)] pub cell_percentage: Option, - #[new(default)] pub blinkwait: Option, - #[new(default)] pub blinkon: Option, - #[new(default)] pub blinkoff: Option, } diff --git a/src/error_handling.rs b/src/error_handling.rs index d5ee1a0..3fef0d5 100644 --- a/src/error_handling.rs +++ b/src/error_handling.rs @@ -1,5 +1,14 @@ use msgbox::IconType; +fn show_error(title: &str, explanation: &str) -> ! { + if cfg!(target_os = "linux") { + panic!("{}: {}", title, explanation); + } else { + msgbox::create(title, explanation, IconType::Error); + panic!(explanation.to_string()); + } +} + pub trait ResultPanicExplanation { fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T; } @@ -9,8 +18,7 @@ impl ResultPanicExplanation for Result { match self { Err(error) => { let explanation = format!("{}: {}", explanation, error.to_string()); - msgbox::create(title, &explanation, IconType::Error); - panic!(explanation); + show_error(title, &explanation); }, Ok(content) => content } @@ -25,8 +33,7 @@ impl OptionPanicExplanation for Option { fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T { match self { None => { - msgbox::create(title, &explanation, IconType::Error); - panic!(explanation.to_string()); + show_error(title, explanation); }, Some(content) => content } diff --git a/src/redraw_scheduler.rs b/src/redraw_scheduler.rs index eff5e36..5a24d8e 100644 --- a/src/redraw_scheduler.rs +++ b/src/redraw_scheduler.rs @@ -46,7 +46,7 @@ pub fn redraw_loop() { } } - if let Some(time_to_sleep) = Duration::from_secs_f32(1.0 / 60.0).checked_sub(Instant::now() - frame_start) { + if let Some(time_to_sleep) = Duration::from_secs_f32(1.0 / 60.0).checked_sub(frame_start.elapsed()) { thread::sleep(time_to_sleep) } } diff --git a/src/renderer/fps_tracker.rs b/src/renderer/fps_tracker.rs deleted file mode 100644 index 48f624e..0000000 --- a/src/renderer/fps_tracker.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::time::Instant; - -pub struct FpsTracker { - last_record_time: Instant, - frame_count: usize, - pub fps: usize -} - -impl FpsTracker { - pub fn new() -> FpsTracker { - FpsTracker { - fps: 0, - last_record_time: Instant::now(), - frame_count: 0 - } - } - - pub fn record_frame(&mut self) { - self.frame_count = self.frame_count + 1; - let now = Instant::now(); - let time_since = (now - self.last_record_time).as_secs_f32(); - if time_since > 1.0 { - self.fps = self.frame_count; - self.last_record_time = now; - self.frame_count = 0; - } - } -}