mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fix the IPC
This commit is contained in:
@@ -2,7 +2,6 @@ use std::env;
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use ::zbus::export::futures_util::lock::Mutex;
|
use ::zbus::export::futures_util::lock::Mutex;
|
||||||
use ::zbus::Connection;
|
use ::zbus::Connection;
|
||||||
@@ -18,7 +17,6 @@ use asusd::{print_board_info, CtrlTask, Reloadable, ZbusRun, DBUS_NAME};
|
|||||||
use config_traits::{StdConfig, StdConfigLoad2, StdConfigLoad3};
|
use config_traits::{StdConfig, StdConfigLoad2, StdConfigLoad3};
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use rog_aura::aura_detection::LaptopLedData;
|
use rog_aura::aura_detection::LaptopLedData;
|
||||||
use tokio::time::sleep;
|
|
||||||
use zbus::SignalContext;
|
use zbus::SignalContext;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ pub struct KeyLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl KeyLayout {
|
impl KeyLayout {
|
||||||
pub fn from_file(path: &Path) -> Result<Self, Error> {
|
fn from_file(path: &Path) -> Result<Self, Error> {
|
||||||
let buf: String = std::fs::read_to_string(path)
|
let buf: String = std::fs::read_to_string(path)
|
||||||
.map_err(|e| Error::IoPath(path.to_string_lossy().to_string(), e))?;
|
.map_err(|e| Error::IoPath(path.to_string_lossy().to_string(), e))?;
|
||||||
if buf.is_empty() {
|
if buf.is_empty() {
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ use tempfile::TempDir;
|
|||||||
|
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mocking"))]
|
||||||
|
const DATA_DIR: &str = "/usr/share/rog-gui/";
|
||||||
|
#[cfg(feature = "mocking")]
|
||||||
|
const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
||||||
|
const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
|
||||||
|
pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png";
|
||||||
|
|
||||||
pub fn print_versions() {
|
pub fn print_versions() {
|
||||||
println!("App and daemon versions:");
|
println!("App and daemon versions:");
|
||||||
println!(" rog-gui v{}", VERSION);
|
println!(" rog-gui v{}", VERSION);
|
||||||
@@ -59,7 +66,7 @@ pub enum Page {
|
|||||||
|
|
||||||
/// Either exit the process, or return with a refreshed tmp-dir
|
/// Either exit the process, or return with a refreshed tmp-dir
|
||||||
pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
|
pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
|
||||||
let mut buf = [0u8; 4];
|
let mut buf = [0u8; 2];
|
||||||
let path = std::env::temp_dir().join("rog-gui");
|
let path = std::env::temp_dir().join("rog-gui");
|
||||||
|
|
||||||
if path.read_dir()?.next().is_none() {
|
if path.read_dir()?.next().is_none() {
|
||||||
@@ -77,15 +84,15 @@ pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
|
|||||||
.open(path.join("ipc.pipe"))?;
|
.open(path.join("ipc.pipe"))?;
|
||||||
|
|
||||||
// If the app is running this ends up stacked on top of SHOWING_GUI
|
// If the app is running this ends up stacked on top of SHOWING_GUI
|
||||||
ipc_file.write_all(&[SHOW_GUI])?;
|
ipc_file.write_all(&[SHOW_GUI, 0])?;
|
||||||
// tiny sleep to give the app a chance to respond
|
// tiny sleep to give the app a chance to respond
|
||||||
sleep(Duration::from_millis(100));
|
sleep(Duration::from_millis(10));
|
||||||
ipc_file.read(&mut buf).ok();
|
ipc_file.read(&mut buf).ok();
|
||||||
|
|
||||||
// First entry is the actual state
|
// First entry is the actual state
|
||||||
if buf[0] == SHOWING_GUI {
|
if buf[0] == SHOWING_GUI {
|
||||||
ipc_file.write_all(&[SHOWING_GUI])?; // Store state again as we drained the fifo
|
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
|
// Early exit is not an error and we don't want to pass back a dir
|
||||||
#[allow(clippy::exit)]
|
#[allow(clippy::exit)]
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if buf[0] == SHOW_GUI {
|
} else if buf[0] == SHOW_GUI {
|
||||||
|
|||||||
@@ -7,14 +7,12 @@ use std::thread::{self, sleep, spawn};
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
use log::{warn, LevelFilter};
|
use log::LevelFilter;
|
||||||
use rog_aura::aura_detection::{LaptopLedData, LedSupportFile};
|
|
||||||
use rog_aura::layouts::KeyLayout;
|
|
||||||
use rog_control_center::cli_options::CliStart;
|
use rog_control_center::cli_options::CliStart;
|
||||||
use rog_control_center::config::Config;
|
use rog_control_center::config::Config;
|
||||||
use rog_control_center::error::Result;
|
use rog_control_center::error::Result;
|
||||||
use rog_control_center::slint::ComponentHandle;
|
use rog_control_center::slint::ComponentHandle;
|
||||||
use rog_control_center::system_state::SystemState;
|
use rog_control_center::system_state::{AuraCreation, SystemState};
|
||||||
use rog_control_center::tray::init_tray;
|
use rog_control_center::tray::init_tray;
|
||||||
use rog_control_center::update_and_notify::{start_notifications, EnabledNotifications};
|
use rog_control_center::update_and_notify::{start_notifications, EnabledNotifications};
|
||||||
use rog_control_center::{
|
use rog_control_center::{
|
||||||
@@ -25,15 +23,17 @@ use tokio::runtime::Runtime;
|
|||||||
// use winit::monitor::VideoMode;
|
// use winit::monitor::VideoMode;
|
||||||
// use winit::window::{Fullscreen, WindowLevel};
|
// use winit::window::{Fullscreen, WindowLevel};
|
||||||
|
|
||||||
#[cfg(not(feature = "mocking"))]
|
|
||||||
const DATA_DIR: &str = "/usr/share/rog-gui/";
|
|
||||||
#[cfg(feature = "mocking")]
|
|
||||||
const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
|
||||||
const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
|
|
||||||
// const APP_ICON_PATH: &str =
|
|
||||||
// "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png";
|
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
// tmp-dir must live to the end of program life
|
||||||
|
let _tmp_dir = match tempfile::Builder::new()
|
||||||
|
.prefix("rog-gui")
|
||||||
|
.rand_bytes(0)
|
||||||
|
.tempdir()
|
||||||
|
{
|
||||||
|
Ok(tmp) => tmp,
|
||||||
|
Err(_) => on_tmp_dir_exists().unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
let args: Vec<String> = args().skip(1).collect();
|
let args: Vec<String> = args().skip(1).collect();
|
||||||
|
|
||||||
let cli_parsed = match CliStart::parse_args_default(&args) {
|
let cli_parsed = match CliStart::parse_args_default(&args) {
|
||||||
@@ -81,110 +81,46 @@ fn main() -> Result<()> {
|
|||||||
config.run_in_background = true;
|
config.run_in_background = true;
|
||||||
let tmp = config.enabled_notifications.clone(); // ends up being a double clone, oh well.
|
let tmp = config.enabled_notifications.clone(); // ends up being a double clone, oh well.
|
||||||
config.save(&tmp)?;
|
config.save(&tmp)?;
|
||||||
|
} else {
|
||||||
|
get_ipc_file().unwrap().write_all(&[SHOW_GUI, 0]).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let enabled_notifications = EnabledNotifications::tokio_mutex(&config);
|
let enabled_notifications = EnabledNotifications::tokio_mutex(&config);
|
||||||
|
let aura_creation = AuraCreation::new(cli_parsed.board_name, cli_parsed.layout_viewing)?;
|
||||||
|
|
||||||
// Find and load a matching layout for laptop
|
// TODO: config mutex to share config in various places
|
||||||
let mut board_name = std::fs::read_to_string(BOARD_NAME).map_err(|e| {
|
let states = setup_page_state_and_notifs(aura_creation, &enabled_notifications, &config)?;
|
||||||
println!("DOH! {BOARD_NAME}, {e}");
|
|
||||||
e
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut led_support = LaptopLedData::get_data();
|
|
||||||
|
|
||||||
let mut path = PathBuf::from(DATA_DIR);
|
|
||||||
let mut layout_name = None;
|
|
||||||
let mut layouts = Vec::new();
|
|
||||||
if cli_parsed.board_name.is_some() || cli_parsed.layout_viewing {
|
|
||||||
if cfg!(feature = "mocking") {
|
|
||||||
path.pop();
|
|
||||||
path.push("rog-aura");
|
|
||||||
path.push("data");
|
|
||||||
}
|
|
||||||
layouts = KeyLayout::layout_files(path.clone()).unwrap();
|
|
||||||
|
|
||||||
if let Some(name) = &cli_parsed.board_name {
|
|
||||||
if let Some(modes) = LedSupportFile::load_from_supoprt_db() {
|
|
||||||
if let Some(data) = modes.matcher(name) {
|
|
||||||
led_support = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
board_name = name.clone();
|
|
||||||
for layout in &layouts {
|
|
||||||
if layout
|
|
||||||
.file_name()
|
|
||||||
.unwrap()
|
|
||||||
.to_string_lossy()
|
|
||||||
.contains(&led_support.layout_name.to_lowercase())
|
|
||||||
{
|
|
||||||
layout_name = Some(layout.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
board_name = "GQ401QM".to_owned();
|
|
||||||
};
|
|
||||||
|
|
||||||
if cli_parsed.layout_viewing {
|
|
||||||
layout_name = Some(layouts[0].clone());
|
|
||||||
board_name = layouts[0]
|
|
||||||
.file_name()
|
|
||||||
.unwrap()
|
|
||||||
.to_string_lossy()
|
|
||||||
.split_once('_')
|
|
||||||
.unwrap()
|
|
||||||
.0
|
|
||||||
.to_owned();
|
|
||||||
led_support.layout_name = board_name.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let layout = KeyLayout::find_layout(led_support, path)
|
|
||||||
.map_err(|e| {
|
|
||||||
println!("DERP! , {e}");
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
warn!("Did not find a keyboard layout matching {board_name}");
|
|
||||||
KeyLayout::default_layout()
|
|
||||||
});
|
|
||||||
|
|
||||||
// tmp-dir must live to the end of program life
|
|
||||||
let _tmp_dir = match tempfile::Builder::new()
|
|
||||||
.prefix("rog-gui")
|
|
||||||
.rand_bytes(0)
|
|
||||||
.tempdir()
|
|
||||||
{
|
|
||||||
Ok(tmp) => tmp,
|
|
||||||
Err(_) => on_tmp_dir_exists().unwrap(),
|
|
||||||
};
|
|
||||||
dbg!();
|
|
||||||
|
|
||||||
let states = setup_page_state_and_notifs(
|
|
||||||
layout_name,
|
|
||||||
layout,
|
|
||||||
layouts,
|
|
||||||
&enabled_notifications,
|
|
||||||
&config,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if config.enable_tray_icon {
|
if config.enable_tray_icon {
|
||||||
init_tray(supported_properties, states.clone());
|
init_tray(supported_properties, states.clone());
|
||||||
}
|
}
|
||||||
dbg!();
|
|
||||||
|
|
||||||
thread_local! { pub static UI: std::cell::RefCell<Option<MainWindow>> = Default::default()};
|
thread_local! { pub static UI: std::cell::RefCell<Option<MainWindow>> = Default::default()};
|
||||||
i_slint_backend_selector::with_platform(|_| Ok(())).unwrap();
|
i_slint_backend_selector::with_platform(|_| Ok(())).unwrap();
|
||||||
|
|
||||||
dbg!();
|
let mut do_once = !config.startup_in_background;
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut buf = [0u8; 2];
|
let mut buf = [0u8; 2];
|
||||||
// blocks until it is read, typically the read will happen after a second
|
// blocks until it is read, typically the read will happen after a second
|
||||||
// process writes to the IPC (so there is data to actually read)
|
// process writes to the IPC (so there is data to actually read)
|
||||||
loop {
|
loop {
|
||||||
get_ipc_file().unwrap().read_exact(&mut buf).unwrap();
|
if do_once {
|
||||||
|
buf[0] = SHOW_GUI;
|
||||||
|
do_once = false;
|
||||||
|
} else {
|
||||||
|
get_ipc_file().unwrap().read_exact(&mut buf).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
if buf[0] == SHOW_GUI {
|
if buf[0] == SHOW_GUI {
|
||||||
println!("Should show window {buf:?}");
|
println!("Should show window {buf:?}");
|
||||||
let mut ipc_file = get_ipc_file().unwrap();
|
// There's a balancing act with read/write timing of IPC, there needs to be a
|
||||||
ipc_file.write_all(&[SHOWING_GUI, 0]).unwrap();
|
// small sleep after this to give any other process a chance to
|
||||||
|
// read the IPC before looping
|
||||||
|
get_ipc_file()
|
||||||
|
.unwrap()
|
||||||
|
.write_all(&[SHOWING_GUI, 0])
|
||||||
|
.unwrap();
|
||||||
|
sleep(Duration::from_millis(50));
|
||||||
|
|
||||||
let states = states.clone();
|
let states = states.clone();
|
||||||
i_slint_core::api::invoke_from_event_loop(move || {
|
i_slint_core::api::invoke_from_event_loop(move || {
|
||||||
@@ -193,8 +129,7 @@ fn main() -> Result<()> {
|
|||||||
if let Some(ui) = ui.as_mut() {
|
if let Some(ui) = ui.as_mut() {
|
||||||
ui.window().show().unwrap();
|
ui.window().show().unwrap();
|
||||||
ui.window().on_close_requested(|| {
|
ui.window().on_close_requested(|| {
|
||||||
let mut ipc_file = get_ipc_file().unwrap();
|
get_ipc_file().unwrap().write_all(&[0, 0]).unwrap();
|
||||||
ipc_file.write_all(&[0, 0]).unwrap();
|
|
||||||
slint::CloseRequestResponse::HideWindow
|
slint::CloseRequestResponse::HideWindow
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -202,8 +137,7 @@ fn main() -> Result<()> {
|
|||||||
newui.window().show().unwrap();
|
newui.window().show().unwrap();
|
||||||
println!("New window should be showing now"); // but it isn't
|
println!("New window should be showing now"); // but it isn't
|
||||||
newui.window().on_close_requested(|| {
|
newui.window().on_close_requested(|| {
|
||||||
let mut ipc_file = get_ipc_file().unwrap();
|
get_ipc_file().unwrap().write_all(&[0, 0]).unwrap();
|
||||||
ipc_file.write_all(&[0, 0]).unwrap();
|
|
||||||
slint::CloseRequestResponse::HideWindow
|
slint::CloseRequestResponse::HideWindow
|
||||||
});
|
});
|
||||||
ui.replace(newui);
|
ui.replace(newui);
|
||||||
@@ -214,6 +148,12 @@ fn main() -> Result<()> {
|
|||||||
} else if buf[1] == QUIT_APP {
|
} else if buf[1] == QUIT_APP {
|
||||||
slint::quit_event_loop().unwrap();
|
slint::quit_event_loop().unwrap();
|
||||||
} else if buf[0] != SHOWING_GUI {
|
} else if buf[0] != SHOWING_GUI {
|
||||||
|
Config::load().unwrap();
|
||||||
|
if !config.run_in_background {
|
||||||
|
slint::quit_event_loop().unwrap();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
println!("Should hide window {buf:?}");
|
println!("Should hide window {buf:?}");
|
||||||
i_slint_core::api::invoke_from_event_loop(move || {
|
i_slint_core::api::invoke_from_event_loop(move || {
|
||||||
UI.with(|ui| {
|
UI.with(|ui| {
|
||||||
@@ -268,16 +208,12 @@ fn setup_window(_states: Arc<Mutex<SystemState>>) -> MainWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn setup_page_state_and_notifs(
|
fn setup_page_state_and_notifs(
|
||||||
layout_testing: Option<PathBuf>,
|
aura_creation: AuraCreation,
|
||||||
keyboard_layout: KeyLayout,
|
|
||||||
keyboard_layouts: Vec<PathBuf>,
|
|
||||||
enabled_notifications: &Arc<Mutex<EnabledNotifications>>,
|
enabled_notifications: &Arc<Mutex<EnabledNotifications>>,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
) -> Result<Arc<Mutex<SystemState>>> {
|
) -> Result<Arc<Mutex<SystemState>>> {
|
||||||
let page_states = Arc::new(Mutex::new(SystemState::new(
|
let page_states = Arc::new(Mutex::new(SystemState::new(
|
||||||
layout_testing,
|
aura_creation,
|
||||||
keyboard_layout,
|
|
||||||
keyboard_layouts,
|
|
||||||
enabled_notifications.clone(),
|
enabled_notifications.clone(),
|
||||||
config.enable_tray_icon,
|
config.enable_tray_icon,
|
||||||
config.run_in_background,
|
config.run_in_background,
|
||||||
@@ -288,8 +224,8 @@ fn setup_page_state_and_notifs(
|
|||||||
Ok(page_states)
|
Ok(page_states)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bah.. the icon dosn't work on wayland anyway, but we'll leave it in for now.
|
// /// Bah.. the icon dosn't work on wayland anyway, but we'll leave it in for
|
||||||
// fn load_icon() -> IconData {
|
// now. fn load_icon() -> IconData {
|
||||||
// let path = PathBuf::from(APP_ICON_PATH);
|
// let path = PathBuf::from(APP_ICON_PATH);
|
||||||
// let mut rgba = Vec::new();
|
// let mut rgba = Vec::new();
|
||||||
// let mut height = 512;
|
// let mut height = 512;
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ use std::path::PathBuf;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use log::error;
|
use log::{error, warn};
|
||||||
use rog_anime::{Animations, DeviceState};
|
use rog_anime::{Animations, DeviceState};
|
||||||
|
use rog_aura::aura_detection::{LaptopLedData, LedSupportFile};
|
||||||
use rog_aura::layouts::KeyLayout;
|
use rog_aura::layouts::KeyLayout;
|
||||||
use rog_aura::usb::AuraPowerDev;
|
use rog_aura::usb::AuraPowerDev;
|
||||||
use rog_aura::{AuraEffect, AuraModeNum, LedBrightness};
|
use rog_aura::{AuraEffect, AuraModeNum, LedBrightness};
|
||||||
@@ -19,7 +20,7 @@ use crate::error::Result;
|
|||||||
#[cfg(feature = "mocking")]
|
#[cfg(feature = "mocking")]
|
||||||
use crate::mocking::DaemonProxyBlocking as GfxProxyBlocking;
|
use crate::mocking::DaemonProxyBlocking as GfxProxyBlocking;
|
||||||
use crate::update_and_notify::EnabledNotifications;
|
use crate::update_and_notify::EnabledNotifications;
|
||||||
use crate::RogDbusClientBlocking;
|
use crate::{RogDbusClientBlocking, BOARD_NAME, DATA_DIR};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct PlatformState {
|
pub struct PlatformState {
|
||||||
@@ -121,10 +122,7 @@ impl AuraState {
|
|||||||
pub fn new(layout: &KeyLayout, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
pub fn new(layout: &KeyLayout, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
current_mode: if !layout.basic_modes().is_empty() {
|
current_mode: if !layout.basic_modes().is_empty() {
|
||||||
dbg!();
|
dbus.proxies().aura().led_mode().unwrap_or_default()
|
||||||
let x = dbus.proxies().aura().led_mode().unwrap_or_default();
|
|
||||||
dbg!();
|
|
||||||
x
|
|
||||||
} else {
|
} else {
|
||||||
AuraModeNum::Static
|
AuraModeNum::Static
|
||||||
},
|
},
|
||||||
@@ -215,6 +213,7 @@ impl Default for GfxState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The keyboard layout, used for such things as per-key and zones
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AuraCreation {
|
pub struct AuraCreation {
|
||||||
/// Specifically for testing the development of keyboard layouts (combined
|
/// Specifically for testing the development of keyboard layouts (combined
|
||||||
@@ -228,18 +227,78 @@ pub struct AuraCreation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AuraCreation {
|
impl AuraCreation {
|
||||||
pub fn new(
|
pub fn new(test_name: Option<String>, view_layout: bool) -> Result<Self> {
|
||||||
layout_testing: Option<PathBuf>,
|
let mut led_support = LaptopLedData::get_data();
|
||||||
keyboard_layout: KeyLayout,
|
|
||||||
keyboard_layouts: Vec<PathBuf>,
|
let mut path = PathBuf::from(DATA_DIR);
|
||||||
) -> Self {
|
let mut layout_testing = None;
|
||||||
Self {
|
let mut keyboard_layouts = Vec::new();
|
||||||
|
|
||||||
|
// Find and load a matching layout for laptop
|
||||||
|
let mut board_name = std::fs::read_to_string(BOARD_NAME).map_err(|e| {
|
||||||
|
println!("DOH! {BOARD_NAME}, {e}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if test_name.is_some() || view_layout {
|
||||||
|
if cfg!(feature = "mocking") {
|
||||||
|
path.pop();
|
||||||
|
path.push("rog-aura");
|
||||||
|
path.push("data");
|
||||||
|
}
|
||||||
|
keyboard_layouts = KeyLayout::layout_files(path.clone()).unwrap();
|
||||||
|
|
||||||
|
if let Some(name) = test_name {
|
||||||
|
if let Some(modes) = LedSupportFile::load_from_supoprt_db() {
|
||||||
|
if let Some(data) = modes.matcher(&name) {
|
||||||
|
led_support = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
board_name = name;
|
||||||
|
for layout in &keyboard_layouts {
|
||||||
|
if layout
|
||||||
|
.file_name()
|
||||||
|
.unwrap()
|
||||||
|
.to_string_lossy()
|
||||||
|
.contains(&led_support.layout_name.to_lowercase())
|
||||||
|
{
|
||||||
|
layout_testing = Some(layout.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
board_name = "GQ401QM".to_owned();
|
||||||
|
};
|
||||||
|
|
||||||
|
if view_layout {
|
||||||
|
layout_testing = Some(keyboard_layouts[0].clone());
|
||||||
|
board_name = keyboard_layouts[0]
|
||||||
|
.file_name()
|
||||||
|
.unwrap()
|
||||||
|
.to_string_lossy()
|
||||||
|
.split_once('_')
|
||||||
|
.unwrap()
|
||||||
|
.0
|
||||||
|
.to_owned();
|
||||||
|
led_support.layout_name = board_name.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let keyboard_layout = KeyLayout::find_layout(led_support, path)
|
||||||
|
.map_err(|e| {
|
||||||
|
println!("DERP! , {e}");
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|_| {
|
||||||
|
warn!("Did not find a keyboard layout matching {board_name}");
|
||||||
|
KeyLayout::default_layout()
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
layout_testing,
|
layout_testing,
|
||||||
layout_last_modified: SystemTime::now(),
|
layout_last_modified: SystemTime::now(),
|
||||||
keyboard_layout,
|
keyboard_layout,
|
||||||
keyboard_layouts,
|
keyboard_layouts,
|
||||||
keyboard_layout_index: 0,
|
keyboard_layout_index: 0,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,31 +330,25 @@ impl SystemState {
|
|||||||
/// Creates self, including the relevant dbus connections and proixies for
|
/// Creates self, including the relevant dbus connections and proixies for
|
||||||
/// internal use
|
/// internal use
|
||||||
pub fn new(
|
pub fn new(
|
||||||
layout_testing: Option<PathBuf>,
|
aura_creation: AuraCreation,
|
||||||
keyboard_layout: KeyLayout,
|
|
||||||
keyboard_layouts: Vec<PathBuf>,
|
|
||||||
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
||||||
tray_enabled: bool,
|
tray_enabled: bool,
|
||||||
run_in_bg: bool,
|
run_in_bg: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
dbg!();
|
|
||||||
let (asus_dbus, conn) = RogDbusClientBlocking::new()?;
|
let (asus_dbus, conn) = RogDbusClientBlocking::new()?;
|
||||||
dbg!();
|
let aura = AuraState::new(&aura_creation.keyboard_layout, &asus_dbus)
|
||||||
let aura = AuraState::new(&keyboard_layout, &asus_dbus)
|
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
let e = format!("Could not get AuraState state: {e}");
|
let e = format!("Could not get AuraState state: {e}");
|
||||||
error!("{e}");
|
error!("{e}");
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
dbg!();
|
|
||||||
let gfx_dbus = GfxProxyBlocking::builder(&conn)
|
let gfx_dbus = GfxProxyBlocking::builder(&conn)
|
||||||
.destination(":org.supergfxctl.Daemon")?
|
.destination(":org.supergfxctl.Daemon")?
|
||||||
.build()
|
.build()
|
||||||
.expect("Couldn't connect to supergfxd");
|
.expect("Couldn't connect to supergfxd");
|
||||||
dbg!();
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
aura_creation: AuraCreation::new(layout_testing, keyboard_layout, keyboard_layouts),
|
aura_creation,
|
||||||
enabled_notifications,
|
enabled_notifications,
|
||||||
bios: PlatformState::new(&asus_dbus)
|
bios: PlatformState::new(&asus_dbus)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
|
|||||||
Reference in New Issue
Block a user