fix(wm): handle winvd errors gracefully

Of course, the crate built to interact with an undocumented COM API is
not the best candidate for unwrap and expect calls...

fix #15
This commit is contained in:
LGUG2Z
2021-08-19 14:51:35 -07:00
parent 4e9b294835
commit 6f7e87799b
3 changed files with 22 additions and 21 deletions
+10 -9
View File
@@ -52,16 +52,17 @@ pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
impl WindowManager { impl WindowManager {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn process_command(&mut self, message: SocketMessage) -> Result<()> { pub fn process_command(&mut self, message: SocketMessage) -> Result<()> {
let virtual_desktop_id = winvd::helpers::get_current_desktop_number() let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();
.expect("could not determine the current virtual desktop number"); if let (Some(id), Some(virtual_desktop_id)) = (virtual_desktop_id, self.virtual_desktop_id)
{
if id != virtual_desktop_id {
tracing::warn!(
"ignoring events while not on virtual desktop {:?}",
virtual_desktop_id
);
if virtual_desktop_id != self.virtual_desktop_id { return Ok(());
tracing::warn!( }
"ignoring commands while not on virtual desktop {}",
self.virtual_desktop_id
);
return Ok(());
} }
match message { match message {
+10 -9
View File
@@ -48,16 +48,17 @@ impl WindowManager {
return Ok(()); return Ok(());
} }
let virtual_desktop_id = winvd::helpers::get_current_desktop_number() let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();
.expect("could not determine the current virtual desktop number"); if let (Some(id), Some(virtual_desktop_id)) = (virtual_desktop_id, self.virtual_desktop_id)
{
if id != virtual_desktop_id {
tracing::warn!(
"ignoring events while not on virtual desktop {:?}",
virtual_desktop_id
);
if virtual_desktop_id != self.virtual_desktop_id { return Ok(());
tracing::warn!( }
"ignoring events while not on virtual desktop {}",
self.virtual_desktop_id
);
return Ok(());
} }
// Make sure we have the most recently focused monitor from any event // Make sure we have the most recently focused monitor from any event
+2 -3
View File
@@ -45,7 +45,7 @@ pub struct WindowManager {
pub command_listener: UnixListener, pub command_listener: UnixListener,
pub is_paused: bool, pub is_paused: bool,
pub hotwatch: Hotwatch, pub hotwatch: Hotwatch,
pub virtual_desktop_id: usize, pub virtual_desktop_id: Option<usize>,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@@ -123,8 +123,7 @@ impl WindowManager {
let listener = UnixListener::bind(&socket)?; let listener = UnixListener::bind(&socket)?;
let virtual_desktop_id = winvd::helpers::get_current_desktop_number() let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();
.expect("could not determine the current virtual desktop number");
Ok(Self { Ok(Self {
monitors: Ring::default(), monitors: Ring::default(),