Skip to content

Commit

Permalink
Shutdown on request
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulspronck committed Oct 23, 2023
1 parent 7ab441e commit 6391cf7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use rumqttc::{AsyncClient, Event, LastWill, MqttOptions, Packet, QoS, ConnAck, ConnectReturnCode};
use serde::{Deserialize, Serialize};
use std::process::Command;
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{Manager, State};
use tokio::sync::Mutex;
Expand Down Expand Up @@ -195,6 +196,31 @@ async fn main() {
let datapoint_key: Vec<&str> =
datapoint_key_split.collect();

let device_key = vec_topic[2];

if device_key == device_key_clone && datapoint_key[0] == "Shutdown" {
if cfg!(target_os = "windows") {
// Windows
Command::new("shutdown")
.args(&["/s", "/t", "0"])
.output()
.expect("Failed to shut down the computer");
} else if cfg!(target_os = "linux") {
// Linux
Command::new("shutdown")
.args(&["-h", "now"])
.output()
.expect("Failed to shut down the computer");
} else if cfg!(target_os = "macos") {
// macOS
Command::new("shutdown")
.args(&["-h", "now"])
.output()
.expect("Failed to shut down the computer");
}
continue
}

let s: String = format!(
"{}",
datapoint_key[0]
Expand Down

0 comments on commit 6391cf7

Please sign in to comment.