opt: close main window when exit from tray on macOS

This commit is contained in:
Kingtous
2023-05-02 23:48:49 +08:00
parent a77b795c47
commit 3980e52a88
5 changed files with 41 additions and 7 deletions

View File

@@ -36,6 +36,8 @@ pub enum PrivacyModeState {
OffByPeer,
OffUnknown,
}
// IPC actions here.
pub const IPC_ACTION_CLOSE: &str = "close";
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "t", content = "c")]
@@ -871,6 +873,14 @@ pub async fn send_url_scheme(url: String) -> ResultType<()> {
Ok(())
}
// Emit `close` events to ipc.
pub fn close_all_instances() -> ResultType<bool> {
match crate::ipc::send_url_scheme(IPC_ACTION_CLOSE.to_owned()) {
Ok(_) => Ok(true),
Err(err) => Err(err),
}
}
#[cfg(test)]
mod test {
use super::*;

View File

@@ -211,6 +211,7 @@ pub fn uninstall(show_new_window: bool) -> bool {
);
if uninstalled {
crate::ipc::set_option("stop-service", "Y");
let _ = crate::ipc::close_all_instances();
// leave ipc a little time
std::thread::sleep(std::time::Duration::from_millis(300));
std::process::Command::new("launchctl")