Skip to content

Commit df5bbbc

Browse files
committed
fix(tray): perform clean shutdown on exit
1 parent c2f90da commit df5bbbc

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod plugins;
99
mod tray;
1010

1111
use crate::config::{load_config, Config};
12+
use crate::tray::TrayMessage;
1213
use anyhow::{bail, Context, Result};
1314
use async_osc::OscMessage;
1415
use clap::Parser;
@@ -132,26 +133,33 @@ impl Launcher {
132133
}
133134

134135
async fn wait(&mut self, subsys: &SubsystemHandle) -> Result<()> {
135-
let (reload_tx, mut reload_rx) = mpsc::channel(4);
136-
let mut tray = tray::Tray::new(reload_tx, self.dark_mode_icons)?;
136+
let (tray_tx, mut tray_rx) = mpsc::channel(4);
137+
let mut tray = tray::Tray::new(tray_tx, self.dark_mode_icons)?;
137138
let mut maybe_plugin_subsys: Option<NestedSubsystem> = None;
138139

139140
loop {
140141
select! {
141-
Some(()) = reload_rx.recv() => {
142-
info!("Reloading plugins");
143-
self.config = Arc::new(load_config().await?);
144-
145-
if let Some(plugin_subsys) = maybe_plugin_subsys {
146-
subsys.perform_partial_shutdown(plugin_subsys).await?;
147-
148-
let config = self.config.clone();
149-
let receiver_tx = self.receiver_tx.clone();
150-
let sender_tx = self.sender_tx.clone();
151-
152-
maybe_plugin_subsys = Some(subsys.start("Plugins", move |subsys| {
153-
run_plugins(subsys, config, receiver_tx, sender_tx)
154-
}));
142+
Some(message) = tray_rx.recv() => {
143+
match message {
144+
TrayMessage::ReloadPlugins => {
145+
info!("Reloading plugins");
146+
self.config = Arc::new(load_config().await?);
147+
148+
if let Some(plugin_subsys) = maybe_plugin_subsys {
149+
subsys.perform_partial_shutdown(plugin_subsys).await?;
150+
151+
let config = self.config.clone();
152+
let receiver_tx = self.receiver_tx.clone();
153+
let sender_tx = self.sender_tx.clone();
154+
155+
maybe_plugin_subsys = Some(subsys.start("Plugins", move |subsys| {
156+
run_plugins(subsys, config, receiver_tx, sender_tx)
157+
}));
158+
}
159+
}
160+
TrayMessage::Exit => {
161+
subsys.request_shutdown();
162+
}
155163
}
156164
}
157165
Some(vrchat_running) = self.rx.recv() => {

src/tray.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,30 @@ fn get_active_icon(dark_mode: bool) -> IconSource {
6363
})
6464
}
6565

66+
#[derive(Debug)]
67+
pub enum TrayMessage {
68+
ReloadPlugins,
69+
Exit,
70+
}
71+
6672
pub struct Tray {
6773
tray: TrayItem,
6874
dark_mode_icons: bool,
6975
}
7076

7177
impl Tray {
72-
pub fn new(reload_tx: mpsc::Sender<()>, dark_mode_icons: bool) -> Result<Self> {
78+
pub fn new(message_tx: mpsc::Sender<TrayMessage>, dark_mode_icons: bool) -> Result<Self> {
7379
let mut tray = TrayItem::new("VRC OSC Manager", get_inactive_icon(dark_mode_icons))?;
7480

81+
let reload_plugins_tx = message_tx.clone();
7582
tray.add_menu_item("Reload plugins", move || {
76-
reload_tx.blocking_send(()).unwrap();
83+
reload_plugins_tx
84+
.blocking_send(TrayMessage::ReloadPlugins)
85+
.unwrap();
7786
})?;
7887

79-
tray.add_menu_item("Exit", || {
80-
std::process::exit(0);
88+
tray.add_menu_item("Exit", move || {
89+
message_tx.blocking_send(TrayMessage::Exit).unwrap();
8190
})?;
8291

8392
Ok(Self {

0 commit comments

Comments
 (0)