@@ -22,12 +22,12 @@ pub struct AppState {
22
22
23
23
impl AppState {
24
24
pub fn new ( config : Config , config_path : PathBuf ) -> Self {
25
- let ( tx , _) = broadcast:: channel ( 2 ) ;
26
- let ( txe , _) = broadcast:: channel ( 2 ) ;
25
+ let ( config_tx , _) = broadcast:: channel ( 2 ) ;
26
+ let ( enabled_tx , _) = broadcast:: channel ( 2 ) ;
27
27
28
28
Self {
29
- config_tx : tx ,
30
- enabled_tx : txe ,
29
+ config_tx,
30
+ enabled_tx,
31
31
config : Arc :: new ( RwLock :: new ( config) ) ,
32
32
config_path,
33
33
enabled : Arc :: new ( RwLock :: new ( true ) ) ,
@@ -48,6 +48,7 @@ impl AppState {
48
48
}
49
49
} ) ;
50
50
}
51
+
51
52
pub fn spawn_force_config ( & self , value : WindowConfig ) {
52
53
let app_state: Arc < AppState > = Arc :: new ( self . clone ( ) ) ;
53
54
@@ -116,7 +117,6 @@ impl AppState {
116
117
) -> Result < ( ) , anyhow:: Error > {
117
118
let mut config = self . get_config_mut ( ) . await ;
118
119
119
- // Get the class name to use for parent lookup
120
120
let lookup_class = window_config
121
121
. get_old_classname ( )
122
122
. clone ( )
@@ -134,6 +134,7 @@ impl AppState {
134
134
window_config. refresh_config ( ) ;
135
135
window_config. set_old_classname ( Some ( lookup_class) ) ;
136
136
} else {
137
+ // The config is no longer being forced to remove the parent class
137
138
window_config. set_window_class ( & parent_class) ;
138
139
window_config. reset_config ( ) ;
139
140
window_config. set_window_class ( & lookup_class) ;
@@ -159,10 +160,8 @@ impl AppState {
159
160
}
160
161
161
162
fn remove_existing_config ( & self , config : & mut Config , window_config : & WindowConfig ) {
162
- // Remove configuration by original key
163
163
config. get_windows ( ) . remove ( & window_config. get_key ( ) ) ;
164
164
165
- // Remove configuration by old class if it exists
166
165
if let Some ( old_class) = window_config. get_old_classname ( ) {
167
166
let key = format ! ( "{}|{}" , window_config. get_name( ) , old_class) ;
168
167
config. get_windows ( ) . remove ( & key) ;
@@ -181,7 +180,15 @@ impl AppState {
181
180
* self . enabled . read ( ) . await
182
181
}
183
182
184
- pub async fn set_enable_state ( & self , new_state : bool ) {
183
+ pub async fn enabled ( & self ) {
184
+ self . set_enable_state ( true ) . await
185
+ }
186
+
187
+ pub async fn disable ( & self ) {
188
+ self . set_enable_state ( false ) . await
189
+ }
190
+
191
+ async fn set_enable_state ( & self , new_state : bool ) {
185
192
* self . enabled . write ( ) . await = new_state;
186
193
187
194
self . enabled_tx
0 commit comments