Skip to content

Commit

Permalink
🎨 add guard clause
Browse files Browse the repository at this point in the history
  • Loading branch information
friedow committed Oct 30, 2023
1 parent 83a1323 commit e123f0b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions client/src/plugin/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ pub struct WindowsPlugin {

impl WindowsPlugin {
pub fn spawn() -> iced::Subscription<crate::Message> {
if let Ok(mut plugin) = Self::try_new() {
return iced::subscription::channel(
std::any::TypeId::of::<Self>(),
100,
|plugin_channel_out| async move {
let (app_channel_out, plugin_channel_in) =
iced::futures::channel::mpsc::channel(100);
let main_loop_result = plugin
.main(plugin_channel_out, app_channel_out, plugin_channel_in)
.await;
if let Err(error) = main_loop_result {
Self::log_and_panic(error);
}
loop {}
},
);
} else {
iced::Subscription::<crate::Message>::none()
let plugin_result = PluginType::new();
if let Err(_) = plugin_result {
return iced::Subscription::<crate::Message>::none()
}

let mut plugin = plugin_result.unwrap();
return iced::subscription::channel(
std::any::TypeId::of::<Self>(),
100,
|plugin_channel_out| async move {
let (app_channel_out, plugin_channel_in) =
iced::futures::channel::mpsc::channel(100);
let main_loop_result = plugin
.main(plugin_channel_out, app_channel_out, plugin_channel_in)
.await;
if let Err(error) = main_loop_result {
Self::log_and_panic(error);
}
loop {}
},
);
}

fn get_window_nodes(node: swayipc::Node) -> Vec<swayipc::Node> {
Expand Down

0 comments on commit e123f0b

Please sign in to comment.