summary history branches tags files
commit:23a5686f1f91802fc1b79cf3867b7f4d8da658a9
author:Trevor Bentley
committer:Trevor Bentley
date:Sun May 7 22:31:45 2017 +0200
parents:663d5b795055a2242ff6f95506b7adc9d4bd61f6
Fix Windows.  Only redraw when systray is closed.
diff --git a/src/lib.rs b/src/lib.rs
line changes: +3/-1
index ab6b4b7..6bc77f7
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -51,12 +51,13 @@ pub type StatusBar = DummyStatusBar;
 #[cfg(target_os = "macos")]
 pub type StatusBar = osx::OSXStatusBar;
 #[cfg(target_os = "windows")]
-pub type StatusBar = windows::WindowsStatusBar;
+pub type StatusBar = win::WindowsStatusBar;
 
 pub type MenuItem = *mut Object;
 pub trait TStatusBar {
     type S: TStatusBar;
     fn new(tx: Sender<String>) -> Self::S;
+    fn can_redraw(&mut self) -> bool;
     fn clear_items(&mut self);
     fn add_separator(&mut self);
     fn add_label(&mut self, label: &str);
@@ -76,6 +77,7 @@ pub struct DummyStatusBar {}
 impl TStatusBar for DummyStatusBar {
     type S = DummyStatusBar;
     fn new(_: Sender<String>) -> Self::S { DummyStatusBar {} }
+    fn can_redraw(&mut self) -> bool { true }
     fn clear_items(&mut self) {}
     fn add_separator(&mut self) {}
     fn add_label(&mut self, _: &str) {}

diff --git a/src/main.rs b/src/main.rs
line changes: +1/-1
index 76be926..50022ed
--- a/src/main.rs
+++ b/src/main.rs
@@ -392,7 +392,7 @@ fn main() {
 
     while running.load(Ordering::SeqCst) {
         let now = time::now_utc().to_timespec().sec as i64;
-        if now > refresh_time_utc {
+        if now > refresh_time_utc && status.can_redraw() {
             // Redraw the whole menu once every 60 seconds, or sooner if a
             // command is processed later.
             clear_menu(&mut app, &mut spotify, &mut status);

diff --git a/src/osx/mod.rs b/src/osx/mod.rs
line changes: +3/-0
index b5d75b3..7a37d2a
--- a/src/osx/mod.rs
+++ b/src/osx/mod.rs
@@ -85,6 +85,9 @@ impl TStatusBar for OSXStatusBar {
         }
         bar
     }
+    fn can_redraw(&mut self) -> bool {
+        true
+    }
     fn clear_items(&mut self) {
         unsafe {
             let old_menu = self.menu_bar;

diff --git a/src/win/mod.rs b/src/win/mod.rs
line changes: +6/-9
index 2396ea1..223a28a
--- a/src/win/mod.rs
+++ b/src/win/mod.rs
@@ -24,19 +24,16 @@ impl TStatusBar for WindowsStatusBar {
         {
             let ref mut win = &mut bar.app.window;
             win.set_icon_from_file(&"spotify.ico".to_string());
-            win.add_menu_separator();
-            win.add_menu_item(&"Menu Item1".to_string(), true, |window| {println!("hello")});
-            win.add_menu_item(&"Menu Item2".to_string(), false, |window| {println!("hello")});
-            let idx = win.add_menu_item(&"Menu Item3".to_string(), false, |window| {println!("hello")});
-            let idx = idx.unwrap();
-            win.select_menu_item(idx);
-            win.unselect_menu_item(idx);
-            win.clear_menu();
-            win.add_menu_item(&"Menu Item4".to_string(), false, |window| {println!("hello")});
         }
         bar
     }
+    fn can_redraw(&mut self) -> bool {
+        let ref mut win = &mut self.app.window;
+        !win.menu_displayed()
+    }
     fn clear_items(&mut self) {
+        let ref mut win = &mut self.app.window;
+        win.clear_menu();
     }
     fn set_tooltip(&mut self, text: &str) {
         let ref mut win = &mut self.app.window;