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 {
#[tracing::instrument(skip(self))]
pub fn process_command(&mut self, message: SocketMessage) -> Result<()> {
let virtual_desktop_id = winvd::helpers::get_current_desktop_number()
.expect("could not determine the current virtual desktop number");
let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();
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 {
tracing::warn!(
"ignoring commands while not on virtual desktop {}",
self.virtual_desktop_id
);
return Ok(());
return Ok(());
}
}
match message {
+10 -9
View File
@@ -48,16 +48,17 @@ impl WindowManager {
return Ok(());
}
let virtual_desktop_id = winvd::helpers::get_current_desktop_number()
.expect("could not determine the current virtual desktop number");
let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();
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 {
tracing::warn!(
"ignoring events while not on virtual desktop {}",
self.virtual_desktop_id
);
return Ok(());
return Ok(());
}
}
// 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 is_paused: bool,
pub hotwatch: Hotwatch,
pub virtual_desktop_id: usize,
pub virtual_desktop_id: Option<usize>,
}
#[derive(Debug, Serialize)]
@@ -123,8 +123,7 @@ impl WindowManager {
let listener = UnixListener::bind(&socket)?;
let virtual_desktop_id = winvd::helpers::get_current_desktop_number()
.expect("could not determine the current virtual desktop number");
let virtual_desktop_id = winvd::helpers::get_current_desktop_number().ok();
Ok(Self {
monitors: Ring::default(),