mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-06-08 11:42:47 +02:00
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:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user