Skip to content

Commit 55c20d7

Browse files
committed
2.2.0 - Multi-Device Support
1 parent ca9960e commit 55c20d7

File tree

7 files changed

+266
-83
lines changed

7 files changed

+266
-83
lines changed

Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "wooting-profile-switcher"
33
description = "Wooting Profile Switcher"
4-
version = "2.1.4"
4+
version = "2.2.0"
55
authors = ["Shayne Hartford <[email protected]>", "Tony Langhammer"]
66
edition = "2021"
77
readme = "README.md"
@@ -50,7 +50,6 @@ custom-protocol = ["tauri/custom-protocol"]
5050

5151
# https://tauri.app/v1/guides/building/app-size/#rust-build-time-optimizations
5252
[profile.release]
53-
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
5453
lto = true # Enables link to optimizations
5554
opt-level = "s" # Optimize for binary size
5655
strip = true # Remove debug symbols

Tauri.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
productName = "wooting-profile-switcher"
3-
version = "2.1.3"
3+
version = "2.2.0"
44

55
[tauri.bundle]
66
active = true

src/app.rs

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use tauri_egui::{
3030
};
3131
use tauri_plugin_autostart::ManagerExt;
3232
use wooting_profile_switcher as wps;
33+
use wps::DeviceIndices;
3334

3435
use crate::{
3536
config::{Config, Rule, Theme},
@@ -42,53 +43,56 @@ const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
4243
const CARGO_PKG_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
4344
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
4445

46+
#[derive(Clone, Debug)]
4547
struct SelectedRule {
4648
alias: String,
4749
match_app_name: String,
4850
match_bin_name: String,
4951
match_bin_path: String,
5052
match_win_name: String,
51-
profile_index: u8,
53+
device_indices: DeviceIndices,
5254
rule_index: usize,
5355
}
5456

5557
impl SelectedRule {
5658
fn new(rule: Rule, i: usize) -> Self {
5759
Self {
5860
alias: rule.alias,
61+
device_indices: rule.device_indices,
5962
match_app_name: rule.match_app_name.unwrap_or_default(),
6063
match_bin_name: rule.match_bin_name.unwrap_or_default(),
6164
match_bin_path: rule.match_bin_path.unwrap_or_default(),
6265
match_win_name: rule.match_win_name.unwrap_or_default(),
63-
profile_index: rule.profile_index,
6466
rule_index: i,
6567
}
6668
}
69+
}
6770

68-
fn to_rule(&self) -> Rule {
69-
Rule {
70-
alias: self.alias.clone(),
71-
match_app_name: self
71+
impl From<SelectedRule> for Rule {
72+
fn from(rule: SelectedRule) -> Self {
73+
Self {
74+
alias: rule.alias,
75+
device_indices: rule.device_indices,
76+
match_app_name: rule
7277
.match_app_name
7378
.is_empty()
7479
.not()
75-
.then_some(self.match_app_name.clone()),
76-
match_bin_name: self
80+
.then_some(rule.match_app_name),
81+
match_bin_name: rule
7782
.match_bin_name
7883
.is_empty()
7984
.not()
80-
.then_some(self.match_bin_name.clone()),
81-
match_bin_path: self
85+
.then_some(rule.match_bin_name),
86+
match_bin_path: rule
8287
.match_bin_path
8388
.is_empty()
8489
.not()
85-
.then_some(self.match_bin_path.clone()),
86-
match_win_name: self
90+
.then_some(rule.match_bin_path),
91+
match_win_name: rule
8792
.match_win_name
8893
.is_empty()
8994
.not()
90-
.then_some(self.match_win_name.clone()),
91-
profile_index: self.profile_index,
95+
.then_some(rule.match_win_name),
9296
}
9397
}
9498
}
@@ -323,6 +327,21 @@ impl App for MainApp {
323327
TopBottomPanel::top("top_panel").show(ctx, |ui| {
324328
MenuBar(ui, |ui| {
325329
ui.menu_button("File", |ui| {
330+
if config.read().serial_numbers.len() > 1 {
331+
for serial_number in config.read().serial_numbers.clone() {
332+
if ui.button(&serial_number).clicked() {
333+
ui.close_menu();
334+
335+
args.write().serial_number = Some(serial_number.clone());
336+
if !wps::select_device(&serial_number).unwrap() {
337+
println!("Device ({serial_number}) not found");
338+
};
339+
}
340+
}
341+
342+
ui.separator();
343+
}
344+
326345
for (profile_index, title) in config.read().profiles.iter().enumerate() {
327346
if ui.button(title).clicked() {
328347
ui.close_menu();
@@ -446,7 +465,7 @@ impl App for MainApp {
446465

447466
let height = 18.0;
448467
TableBuilder::new(ui)
449-
.column(Column::exact(100.0))
468+
.column(Column::exact(140.0))
450469
.column(Column::remainder())
451470
.body(|mut body| {
452471
body.row(height, |mut row| {
@@ -491,19 +510,37 @@ impl App for MainApp {
491510
});
492511
body.row(height, |mut row| {
493512
row.col(|ui| {
494-
ui.label("Profile Index");
513+
ui.label("Serial Numbers");
495514
});
496515
row.col(|ui| {
497-
let slider = Slider::new(&mut selected_rule.profile_index, 0..=3)
498-
.clamp_to_range(true);
499-
ui.add(slider);
516+
ui.label("Profile Indices");
500517
});
501518
});
519+
for serial_number in config.read().serial_numbers.clone() {
520+
let profile_index = selected_rule.device_indices.get_mut(&serial_number);
521+
if profile_index.is_none() {
522+
selected_rule
523+
.device_indices
524+
.insert(serial_number.to_owned(), 0);
525+
continue;
526+
}
527+
body.row(height, |mut row| {
528+
row.col(|ui| {
529+
ui.label(serial_number);
530+
});
531+
row.col(|ui| {
532+
let slider = Slider::new(&mut *profile_index.unwrap(), 0..=3)
533+
.clamp_to_range(true);
534+
ui.add(slider);
535+
});
536+
});
537+
}
502538
body.row(height, |mut row| {
503539
row.col(|ui| {
504540
if ui.button("Save").clicked() {
541+
let rule = selected_rule.clone().into();
505542
let mut config = config.write();
506-
config.rules[selected_rule.rule_index] = selected_rule.to_rule();
543+
config.rules[selected_rule.rule_index] = rule;
507544
config.save().expect("Failed to save config");
508545
}
509546
});

src/config.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::{
77

88
use anyhow::{bail, Result};
99
use serde::{Deserialize, Serialize};
10+
use wooting_profile_switcher as wps;
11+
use wps::DeviceIndices;
1012

1113
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1214
pub enum Theme {
@@ -27,7 +29,7 @@ pub struct Rule {
2729
pub match_bin_path: Option<String>,
2830
#[serde(rename = "title")]
2931
pub match_win_name: Option<String>,
30-
pub profile_index: u8,
32+
pub device_indices: DeviceIndices,
3133
}
3234

3335
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
@@ -42,10 +44,12 @@ pub struct Ui {
4244
pub struct Config {
4345
pub auto_launch: Option<bool>,
4446
pub auto_update: Option<bool>,
45-
pub fallback_profile_index: Option<u8>,
47+
pub fallback_device_indices: Option<DeviceIndices>,
4648
pub loop_sleep_ms: u64,
4749
pub send_sleep_ms: u64,
4850
pub swap_lighting: bool,
51+
pub serial_number: String,
52+
pub serial_numbers: Vec<String>,
4953
pub profiles: Vec<String>,
5054
pub rules: Vec<Rule>,
5155
pub ui: Ui,
@@ -56,10 +60,12 @@ impl Default for Config {
5660
Self {
5761
auto_launch: None,
5862
auto_update: None,
59-
fallback_profile_index: Some(0),
63+
fallback_device_indices: Some(wps::get_device_indices().unwrap()),
6064
loop_sleep_ms: 250,
6165
send_sleep_ms: 250,
6266
swap_lighting: true,
67+
serial_number: wps::get_active_serial_number().unwrap(),
68+
serial_numbers: Vec::new(),
6369
profiles: vec![
6470
String::from("Typing Profile"),
6571
String::from("Rapid Profile"),
@@ -68,11 +74,11 @@ impl Default for Config {
6874
],
6975
rules: vec![Rule {
7076
alias: String::from("The Binding of Isaac"),
77+
device_indices: DeviceIndices::new(),
7178
match_app_name: Some(String::from("isaac-ng")),
7279
match_bin_name: Some(String::from("isaac-ng.exe")),
7380
match_bin_path: Some(String::from("C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Binding of Isaac Rebirth\\isaac-ng.exe")),
7481
match_win_name: Some(String::from("Binding of Isaac: Repentance")),
75-
profile_index: 1,
7682
}],
7783
ui: Ui {
7884
scale: 1.25,

0 commit comments

Comments
 (0)