mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Refactor ROGCC to use dbus to communicate with self instead of pipe file
This commit is contained in:
@@ -2,14 +2,8 @@
|
||||
#![allow(clippy::redundant_clone, clippy::cmp_owned)]
|
||||
slint::include_modules!();
|
||||
|
||||
// Intentionally reexport slint so that GUI consumers don't need to add to
|
||||
// `Cargo.toml`
|
||||
use std::fs::{remove_dir_all, File, OpenOptions};
|
||||
use std::io::{Read, Write};
|
||||
use std::process::exit;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
/// Intentionally reexport slint so that GUI consumers don't need to add to
|
||||
/// `Cargo.toml`
|
||||
pub use slint;
|
||||
|
||||
pub mod cli_options;
|
||||
@@ -21,11 +15,7 @@ pub mod notify;
|
||||
pub mod tray;
|
||||
pub mod types;
|
||||
pub mod ui;
|
||||
|
||||
use nix::sys::stat;
|
||||
use nix::unistd;
|
||||
use tempfile::TempDir;
|
||||
// use log::{error, info, warn};
|
||||
pub mod zbus;
|
||||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png";
|
||||
@@ -42,10 +32,6 @@ pub fn print_versions() {
|
||||
println!("rog-platform v{}", rog_platform::VERSION);
|
||||
}
|
||||
|
||||
pub const SHOWING_GUI: u8 = 1;
|
||||
pub const SHOW_GUI: u8 = 2;
|
||||
pub const QUIT_APP: u8 = 3;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum Page {
|
||||
AppSettings,
|
||||
@@ -54,59 +40,3 @@ pub enum Page {
|
||||
AnimeMatrix,
|
||||
FanCurves,
|
||||
}
|
||||
|
||||
/// Either exit the process, or return with a refreshed tmp-dir
|
||||
pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
|
||||
let mut buf = [0u8; 2];
|
||||
let path = std::env::temp_dir().join("rog-gui");
|
||||
|
||||
if path.read_dir()?.next().is_none() {
|
||||
std::fs::remove_dir_all(path)?;
|
||||
return tempfile::Builder::new()
|
||||
.prefix("rog-gui")
|
||||
.rand_bytes(0)
|
||||
.tempdir();
|
||||
}
|
||||
|
||||
let mut ipc_file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(false)
|
||||
.open(path.join("ipc.pipe"))?;
|
||||
|
||||
// If the app is running this ends up stacked on top of SHOWING_GUI
|
||||
ipc_file.write_all(&[SHOW_GUI, 0])?;
|
||||
// tiny sleep to give the app a chance to respond
|
||||
sleep(Duration::from_millis(10));
|
||||
ipc_file.read_exact(&mut buf).ok();
|
||||
|
||||
// First entry is the actual state
|
||||
if buf[0] == SHOWING_GUI {
|
||||
ipc_file.write_all(&[SHOWING_GUI, 0])?; // Store state again as we drained the fifo
|
||||
// Early exit is not an error and we don't want to pass back a dir
|
||||
#[allow(clippy::exit)]
|
||||
exit(0);
|
||||
} else if buf[0] == SHOW_GUI {
|
||||
remove_dir_all(&path)?;
|
||||
return tempfile::Builder::new()
|
||||
.prefix("rog-gui")
|
||||
.rand_bytes(0)
|
||||
.tempdir();
|
||||
}
|
||||
panic!("Invalid exit or app state");
|
||||
}
|
||||
|
||||
pub fn get_ipc_file() -> Result<File, crate::error::Error> {
|
||||
let tmp_dir = std::env::temp_dir().join("rog-gui");
|
||||
let fifo_path = tmp_dir.join("ipc.pipe");
|
||||
if let Err(e) = unistd::mkfifo(&fifo_path, stat::Mode::S_IRWXU) {
|
||||
if !matches!(e, nix::errno::Errno::EEXIST) {
|
||||
Err(e)?
|
||||
}
|
||||
}
|
||||
Ok(OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
// .truncate(true)
|
||||
.open(&fifo_path)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user