Skip to content

Commit

Permalink
2.3.4 - Debug Info
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayBox committed Mar 26, 2024
1 parent ddfa7ba commit 4af4dc2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wooting-profile-switcher"
description = "Wooting Profile Switcher"
version = "2.3.3"
version = "2.3.4"
authors = ["Shayne Hartford <shaybox@shaybox.com>", "Tony Langhammer"]
edition = "2021"
readme = "README.md"
Expand Down
14 changes: 3 additions & 11 deletions Tauri.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
[package]
productName = "wooting-profile-switcher"
version = "2.3.3"
version = "2.3.4"

[tauri.bundle]
active = true
targets = "all"
identifier = "com.shaybox.wooting-profile-switcher"
icon = [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico",
]
icon = ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"]
copyright = "Copyright (c) 2021 Shayne Hartford"
category = "Utility"
shortDescription = "Automatically switch Wooting keyboard profiles based on focused window"
Expand All @@ -31,6 +25,4 @@ devPath = "src"
distDir = "src"

[plugins.updater]
endpoints = [
"https://github.com/ShayBox/Wooting-Profile-Switcher/releases/latest/download/latest.json",
]
endpoints = ["https://github.com/ShayBox/Wooting-Profile-Switcher/releases/latest/download/latest.json"]
32 changes: 21 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl TryFrom<Vec<u8>> for U32 {
}
}

bail!("Incomplete integer")
println!("Incomplete integer");
Ok(Self(result))
}
}

Expand Down Expand Up @@ -129,9 +130,13 @@ impl TryFrom<Vec<u8>> for Device {
index += 1;
}
6 => {
let bytes = vec![buffer[index], buffer[index + 1]];
let mut bytes = vec![buffer[index]];
while buffer[index] >> 3 != 0 {
index += 1;
bytes.push(buffer[index]);
}
device.product_id = U32::try_from(bytes)?.0;
index += 2;
index += 1;
}
7 => {
let bytes = vec![buffer[index]];
Expand Down Expand Up @@ -208,9 +213,15 @@ impl From<&Device> for DeviceID {
device.revision,
device.week,
device.year,
device.pcb_design.unwrap_or_default(),
device.minor_rev.unwrap_or_default(),
device.variant.unwrap_or_default(),
device
.pcb_design
.map_or_else(String::new, |pcb_design| format!("T{pcb_design:02}")),
device
.minor_rev
.map_or_else(String::new, |minor_rev| format!("{minor_rev:02}")),
device
.variant
.map_or_else(String::new, |variant| format!("S{variant:02}")),
);

Self(device_id)
Expand Down Expand Up @@ -294,10 +305,6 @@ impl TryFrom<DeviceSerial> for Device {
#[allow(clippy::too_many_lines)]
pub fn get_active_device() -> Result<Device> {
unsafe {
if !rgb::wooting_usb_find_keyboard() {
bail!("Failed to find keyboard")
};

/* Response Bytes
* 0-1 Magic Word
* 2 Command
Expand Down Expand Up @@ -331,6 +338,7 @@ pub fn get_active_device() -> Result<Device> {
bail!("Invalid response command");
}

println!("Serial Buffer: {:?}", &buffer[5..5 + buffer[4] as usize]);
let wooting_usb_meta = *rgb::wooting_usb_get_meta();
let c_str_model_name = CStr::from_ptr(wooting_usb_meta.model);
let mut device = Device::try_from(buffer)?;
Expand All @@ -345,7 +353,9 @@ pub fn get_all_devices() -> Result<Vec<Device>> {

unsafe {
rgb::wooting_usb_disconnect(false);
rgb::wooting_usb_find_keyboard();
if !rgb::wooting_usb_find_keyboard() {
bail!("Failed to find keyboard(s)")
};

for device_index in 0..MAX_DEVICES {
if !rgb::wooting_usb_select_device(device_index) {
Expand Down
25 changes: 20 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn main() -> Result<()> {

let args = app.state::<RwLock<Args>>();
let config = app.state::<RwLock<Config>>();
println!("{:#?}\n{:#?}", args.read(), config.read());

// One-shot command line argument to set the device and profile index
if let Some(profile_index) = args.read().profile_index {
Expand All @@ -97,15 +98,19 @@ fn main() -> Result<()> {
config.read().swap_lighting,
);

println!("Profile Index Updated");
std::process::exit(0);
}

// Scan for Wooting devices and Wootility profiles to save
println!("Scanning Wootility for devices and profiles to save");
if let Ok(mut wootility) = Wootility::load() {
let Ok(devices) = wps::get_all_devices() else {
eprintln!("Failed to find any devices");
eprintln!("Make sure you run Wootility once");
std::process::exit(1);
let devices = match wps::get_all_devices() {
Ok(devices) => devices,
Err(error) => {
eprintln!("{error}");
std::process::exit(1);
// TODO: Add a GUI popup
}
};

println!("Found Devices: {devices:#?}");
Expand All @@ -116,13 +121,18 @@ fn main() -> Result<()> {
.filter_map(|mut device| {
let device_id = DeviceID::from(&device);
let device_serial = DeviceSerial::from(&device);
println!("Device ID: {device_id}");
println!("Device Serial: {device_serial}");
println!("Found Profiles: {:#?}", wootility.profiles);

device.profiles = wootility
.profiles
.devices
.remove(&device_id)?
.into_iter()
.map(|profile| profile.details.name)
.collect();

Some((device_serial, device))
})
.collect();
Expand All @@ -137,8 +147,10 @@ fn main() -> Result<()> {
let auto_launch_manager = app.autolaunch();
if let Some(auto_launch) = config.read().auto_launch {
let _ = if auto_launch {
println!("Auto Launch Enabled");
auto_launch_manager.enable()
} else {
println!("Auto Launch Disabled");
auto_launch_manager.disable()
};
}
Expand All @@ -151,10 +163,13 @@ fn main() -> Result<()> {
tauri::async_runtime::block_on(async move {
match updater.check().await {
Ok(update) => {
println!("Checking for updates...");
if !update.is_update_available() {
println!("No updates found.");
return;
}

println!("Update found, please wait...");
if let Err(error) = update.download_and_install(|_event| {}).await {
eprintln!("{error}");
}
Expand Down

0 comments on commit 4af4dc2

Please sign in to comment.