Fix up colour sliders

- Fixup colour sliders for UI
- Correctly drop tokio runtime
This commit is contained in:
Luke D. Jones
2024-05-08 22:28:22 +12:00
parent 1b023d0f5f
commit a18692ef1e
9 changed files with 134 additions and 143 deletions

View File

@@ -22,8 +22,6 @@ use rog_control_center::{
get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, QUIT_APP, SHOWING_GUI, SHOW_GUI,
};
use tokio::runtime::Runtime;
// use winit::monitor::VideoMode;
// use winit::window::{Fullscreen, WindowLevel};
#[tokio::main]
async fn main() -> Result<()> {
@@ -73,11 +71,6 @@ async fn main() -> Result<()> {
.format_timestamp(None)
.init();
// start tokio
let rt = Runtime::new().expect("Unable to create Runtime");
// Enter the runtime so that `tokio::spawn` is available immediately.
let _enter = rt.enter();
let supported_properties = match proxy.supported_properties() {
Ok(s) => s,
Err(_e) => {
@@ -117,7 +110,13 @@ async fn main() -> Result<()> {
let enable_tray_icon = config.enable_tray_icon;
let startup_in_background = config.startup_in_background;
let config = Arc::new(Mutex::new(config));
start_notifications(config.clone())?;
// start tokio
let rt = Runtime::new().expect("Unable to create Runtime");
// Enter the runtime so that `tokio::spawn` is available immediately.
let _enter = rt.enter();
start_notifications(config.clone(), &rt)?;
if enable_tray_icon {
init_tray(supported_properties, config.clone());
}
@@ -208,6 +207,7 @@ async fn main() -> Result<()> {
});
slint::run_event_loop_until_quit().unwrap();
rt.shutdown_background();
Ok(())
}

View File

@@ -18,6 +18,8 @@ use serde::{Deserialize, Serialize};
use supergfxctl::actions::UserActionRequired as GfxUserAction;
use supergfxctl::pci_device::{GfxMode, GfxPower};
use supergfxctl::zbus_proxy::DaemonProxy as SuperProxy;
use tokio::runtime::Runtime;
use tokio::task::JoinHandle;
use tokio::time::sleep;
use zbus::export::futures_util::StreamExt;
@@ -44,10 +46,13 @@ impl Default for EnabledNotifications {
}
}
pub fn start_notifications(config: Arc<Mutex<Config>>) -> Result<()> {
pub fn start_notifications(
config: Arc<Mutex<Config>>,
rt: &Runtime,
) -> Result<Vec<JoinHandle<()>>> {
// Setup the AC/BAT commands that will run on power status change
let config_copy = config.clone();
tokio::task::spawn_blocking(move || {
let blocking = rt.spawn_blocking(move || {
let power = AsusPower::new()
.map_err(|e| {
error!("AsusPower: {e}");
@@ -217,7 +222,7 @@ pub fn start_notifications(config: Arc<Mutex<Config>>) -> Result<()> {
};
});
Ok(())
Ok(vec![blocking])
}
fn convert_gfx_mode(gfx: GfxMode) -> GpuMode {