@@ -30,6 +30,7 @@ use tauri_egui::{
3030} ;
3131use tauri_plugin_autostart:: ManagerExt ;
3232use wooting_profile_switcher as wps;
33+ use wps:: DeviceIndices ;
3334
3435use crate :: {
3536 config:: { Config , Rule , Theme } ,
@@ -42,53 +43,56 @@ const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
4243const CARGO_PKG_REPOSITORY : & str = env ! ( "CARGO_PKG_REPOSITORY" ) ;
4344const CARGO_PKG_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
4445
46+ #[ derive( Clone , Debug ) ]
4547struct 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
5557impl 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 } ) ;
0 commit comments