Add git hooks via cargo-husky. Many many cleanups.

This commit is contained in:
Luke D. Jones
2023-01-16 12:03:52 +13:00
parent b5b7799018
commit a83ccbd33d
49 changed files with 252 additions and 250 deletions

View File

@@ -41,3 +41,6 @@ png_pong.workspace = true
nix = "^0.26.1"
tempfile = "3.3.0"
[dev-dependencies]
cargo-husky.workspace = true

View File

@@ -60,6 +60,8 @@ impl Config {
let mut buf = String::new();
// Lint to allow, because we want the above file behaviour
#[allow(clippy::verbose_file_reads)]
if let Ok(read_len) = file.read_to_string(&mut buf) {
if read_len == 0 {
warn!("Zero len read of Config file");

View File

@@ -81,6 +81,8 @@ pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
// First entry is the actual state
if buf[0] == SHOWING_GUI {
ipc_file.write_all(&[SHOWING_GUI])?; // 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)?;
@@ -89,7 +91,7 @@ pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
.rand_bytes(0)
.tempdir();
}
exit(-1);
panic!("Invalid exit or app state");
}
pub fn get_ipc_file() -> Result<File, crate::error::Error> {

View File

@@ -1,5 +1,4 @@
use std::env::args;
use std::fs::OpenOptions;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
@@ -101,15 +100,10 @@ fn main() -> Result<()> {
let enabled_notifications = EnabledNotifications::tokio_mutex(&config);
// Find and load a matching layout for laptop
let mut file = OpenOptions::new()
.read(true)
.open(PathBuf::from(BOARD_NAME))
.map_err(|e| {
println!("DOH! {BOARD_NAME}, {e}");
e
})?;
let mut board_name = String::new();
file.read_to_string(&mut board_name)?;
let mut board_name = std::fs::read_to_string(BOARD_NAME).map_err(|e| {
println!("DOH! {BOARD_NAME}, {e}");
e
})?;
let mut led_support = LaptopLedData::get_data();
@@ -122,7 +116,7 @@ fn main() -> Result<()> {
path.push("rog-aura");
path.push("data");
}
layouts = KeyLayout::layout_files(path.to_owned()).unwrap();
layouts = KeyLayout::layout_files(path.clone()).unwrap();
if let Some(name) = &cli_parsed.board_name {
if let Some(modes) = LedSupportFile::load_from_config() {
@@ -130,7 +124,7 @@ fn main() -> Result<()> {
led_support = data;
}
}
board_name = name.to_owned();
board_name = name.clone();
for layout in &layouts {
if layout
.file_name()
@@ -138,11 +132,11 @@ fn main() -> Result<()> {
.to_string_lossy()
.contains(&led_support.layout_name.to_lowercase())
{
layout_name = Some(layout.to_owned());
layout_name = Some(layout.clone());
}
}
} else {
board_name = "GQ401QM".to_string()
board_name = "GQ401QM".to_owned();
};
if cli_parsed.layout_viewing {
@@ -182,7 +176,7 @@ fn main() -> Result<()> {
layout_name,
layout,
layouts,
enabled_notifications,
&enabled_notifications,
&config,
&supported,
)?;
@@ -222,7 +216,7 @@ fn setup_page_state_and_notifs(
layout_testing: Option<PathBuf>,
keyboard_layout: KeyLayout,
keyboard_layouts: Vec<PathBuf>,
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
enabled_notifications: &Arc<Mutex<EnabledNotifications>>,
config: &Config,
supported: &SupportedFunctions,
) -> Result<Arc<Mutex<SystemState>>> {
@@ -234,7 +228,7 @@ fn setup_page_state_and_notifs(
supported,
)?));
start_notifications(config, page_states.clone(), enabled_notifications)?;
start_notifications(config, &page_states, enabled_notifications)?;
Ok(page_states)
}
@@ -253,21 +247,15 @@ fn start_app(states: Arc<Mutex<SystemState>>, native_options: NativeOptions) ->
/// Bah.. the icon dosn't work on wayland anyway, but we'll leave it in for now.
fn load_icon() -> IconData {
let path = PathBuf::from(APP_ICON_PATH);
let mut buf = Vec::new();
let mut rgba = Vec::new();
let mut height = 512;
let mut width = 512;
if path.exists() {
if let Ok(mut file) = OpenOptions::new()
.read(true)
.open(path)
if let Ok(data) = std::fs::read(path)
.map_err(|e| error!("Error reading app icon: {e:?}"))
.map_err(|e| error!("Error opening app icon: {e:?}"))
{
file.read_to_end(&mut buf)
.map_err(|e| error!("Error reading app icon: {e:?}"))
.ok();
let data = std::io::Cursor::new(buf);
let data = std::io::Cursor::new(data);
let decoder = png_pong::Decoder::new(data).unwrap().into_steps();
let png_pong::Step { raster, delay: _ } = decoder.last().unwrap().unwrap();
@@ -295,7 +283,7 @@ fn do_cli_help(parsed: &CliStart) -> bool {
println!();
if let Some(cmdlist) = CliStart::command_list() {
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_owned()).collect();
for command in commands.iter() {
for command in &commands {
println!("{}", command);
}
}

View File

@@ -473,13 +473,11 @@ pub fn init_tray(
};
std::thread::spawn(move || {
if gtk::init()
.map_err(|e| {
error!("ROGTray: gtk init {e}");
e
})
.is_err()
{
let gtk_init = gtk::init().map_err(|e| {
error!("ROGTray: gtk init {e}");
e
});
if gtk_init.is_err() {
return;
} // Make this the main thread for gtk
debug!("init_tray gtk");

View File

@@ -139,8 +139,8 @@ type SharedHandle = Arc<Mutex<Option<NotificationHandle>>>;
pub fn start_notifications(
config: &Config,
page_states: Arc<Mutex<SystemState>>,
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
page_states: &Arc<Mutex<SystemState>>,
enabled_notifications: &Arc<Mutex<EnabledNotifications>>,
) -> Result<()> {
let last_notification: SharedHandle = Arc::new(Mutex::new(None));
@@ -556,7 +556,7 @@ fn do_mux_notification(message: &str, m: &GpuMode) -> Result<()> {
} else if id == "__closed" {
// TODO: cancel the switching
}
})
});
});
Ok(())
}

View File

@@ -25,7 +25,7 @@ pub fn keyboard(
AdvancedAuraType::None => (false, keyboard_layout.max_width(), false),
AdvancedAuraType::Zoned(zones) => {
let width = if let Some(row) = keyboard_layout.rows_ref().get(2) {
row.width() as f32
row.width()
} else {
0.0
};