Skip to content

Commit

Permalink
[desktop] Improve tauri traymenu
Browse files Browse the repository at this point in the history
  • Loading branch information
vlabo committed May 22, 2024
1 parent a984032 commit 0c99b93
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 56 deletions.
191 changes: 185 additions & 6 deletions desktop/tauri/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions desktop/tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ http = "1.0.0"
url = "2.5.0"
thiserror = "1.0"
log = "0.4.21"
reqwest = { version = "0.12" }

# Linux only
[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
21 changes: 21 additions & 0 deletions desktop/tauri/src-tauri/src/portmaster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ use serde;
use std::sync::Mutex;
use tauri::{AppHandle, Manager, Runtime};

const PORTMASTER_BASE_URL: &'static str = "http://127.0.0.1:817/api/v1/";

pub trait Handler {
fn on_connect(&mut self, cli: PortAPI) -> ();
fn on_disconnect(&mut self);
Expand Down Expand Up @@ -203,6 +205,25 @@ impl<R: Runtime> PortmasterInterface<R> {
}
}

/// Send Shutdown request to portmaster
pub fn trigger_shutdown(&self) {
tauri::async_runtime::spawn(async move {
let client = reqwest::Client::new();
match client
.post(format!("{}/core/shutdown", PORTMASTER_BASE_URL))
.send()
.await
{
Ok(v) => {
debug!("shutdown request sent {:?}", v);
}
Err(err) => {
error!("failed to send shutdown request {}", err);
}
}
});
}

//// Internal functions
fn start_notification_handler(&self) {
if let Some(api) = self.get_api() {
Expand Down
Loading

0 comments on commit 0c99b93

Please sign in to comment.