3
3
4
4
mod graphics;
5
5
6
+ use crate :: desktop_entries:: graphics:: is_switchable;
6
7
use crate :: * ;
7
8
use freedesktop_desktop_entry:: { default_paths, DesktopEntry , Iter as DesktopIter , PathSource } ;
8
9
use futures:: StreamExt ;
@@ -12,7 +13,6 @@ use std::hash::{Hash, Hasher};
12
13
use std:: process:: Command ;
13
14
use tokio:: io:: AsyncWrite ;
14
15
use tracing:: error;
15
- use crate :: desktop_entries:: graphics:: is_switchable;
16
16
17
17
#[ derive( Debug , Eq ) ]
18
18
struct Item {
@@ -30,7 +30,7 @@ struct Item {
30
30
#[ derive( Debug , PartialEq , Eq ) ]
31
31
pub enum ContextAction {
32
32
Action ( Action ) ,
33
- GpuPreference ( GpuPreference )
33
+ GpuPreference ( GpuPreference ) ,
34
34
}
35
35
36
36
impl Item {
@@ -39,18 +39,18 @@ impl Item {
39
39
// No action provided just run the desktop entry with the default gpu
40
40
None => run_exec_command ( & self . exec , self . prefer_non_default_gpu ) ,
41
41
// Run the provided action
42
- Some ( idx) => {
43
- match self . context . get ( idx as usize ) {
44
- None => error ! ( "Could not find context action at index {idx}" ) ,
45
- Some ( action) => match action {
46
- ContextAction :: Action ( action ) => run_exec_command ( & action. exec , self . prefer_non_default_gpu ) ,
47
- ContextAction :: GpuPreference ( pref ) => match pref {
48
- GpuPreference :: Default => run_exec_command ( & self . exec , false ) ,
49
- GpuPreference :: NonDefault => run_exec_command ( & self . exec , true ) ,
50
- } ,
42
+ Some ( idx) => match self . context . get ( idx as usize ) {
43
+ None => error ! ( "Could not find context action at index {idx}" ) ,
44
+ Some ( action ) => match action {
45
+ ContextAction :: Action ( action) => {
46
+ run_exec_command ( & action. exec , self . prefer_non_default_gpu )
47
+ }
48
+ ContextAction :: GpuPreference ( pref ) => match pref {
49
+ GpuPreference :: Default => run_exec_command ( & self . exec , false ) ,
50
+ GpuPreference :: NonDefault => run_exec_command ( & self . exec , true ) ,
51
51
} ,
52
- }
53
- }
52
+ } ,
53
+ } ,
54
54
}
55
55
}
56
56
}
@@ -221,8 +221,8 @@ impl<W: AsyncWrite + Unpin> App<W> {
221
221
let action =
222
222
entry. action_name ( action, locale) . and_then ( |name| {
223
223
entry. action_exec ( action) . map ( |exec| Action {
224
- name : action . to_string ( ) ,
225
- description : name . to_string ( ) ,
224
+ name : name . to_string ( ) ,
225
+ description : action . to_string ( ) ,
226
226
exec : exec. to_string ( ) ,
227
227
} )
228
228
} ) ;
@@ -238,19 +238,21 @@ impl<W: AsyncWrite + Unpin> App<W> {
238
238
. map ( |action| ContextAction :: Action ( action) ) ;
239
239
240
240
let entry_prefers_non_default_gpu = entry. prefers_non_default_gpu ( ) ;
241
- let prefer_non_default_gpu = entry_prefers_non_default_gpu && is_switchable ( ) ;
242
- let prefer_default_gpu = !entry_prefers_non_default_gpu && is_switchable ( ) ;
241
+ let prefer_non_default_gpu =
242
+ entry_prefers_non_default_gpu && is_switchable ( ) ;
243
+ let prefer_default_gpu =
244
+ !entry_prefers_non_default_gpu && is_switchable ( ) ;
243
245
244
- let context: Vec < ContextAction > = if prefer_non_default_gpu {
246
+ let context: Vec < ContextAction > = if prefer_non_default_gpu {
245
247
vec ! [ ContextAction :: GpuPreference ( GpuPreference :: Default ) ]
246
248
} else if prefer_default_gpu {
247
249
vec ! [ ContextAction :: GpuPreference ( GpuPreference :: NonDefault ) ]
248
250
} else {
249
251
vec ! [ ]
250
252
}
251
- . into_iter ( )
252
- . chain ( actions)
253
- . collect ( ) ;
253
+ . into_iter ( )
254
+ . chain ( actions)
255
+ . collect ( ) ;
254
256
255
257
let item = Item {
256
258
appid : entry. appid . to_owned ( ) ,
@@ -267,7 +269,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
267
269
exec : exec. to_owned ( ) ,
268
270
src,
269
271
context,
270
- prefer_non_default_gpu : entry_prefers_non_default_gpu
272
+ prefer_non_default_gpu : entry_prefers_non_default_gpu,
271
273
} ;
272
274
273
275
deduplicator. insert ( item) ;
@@ -312,22 +314,20 @@ impl<W: AsyncWrite + Unpin> App<W> {
312
314
description : action. description . to_owned ( ) ,
313
315
exec : Some ( action. exec . to_string ( ) ) ,
314
316
} ) ,
315
- ContextAction :: GpuPreference ( pref) => {
316
- match pref {
317
- GpuPreference :: Default => options. push ( ContextOption {
318
- id : 0 ,
319
- name : "Integrated Graphics" . to_owned ( ) ,
320
- description : "Launch Using Integrated Graphics Card" . to_owned ( ) ,
321
- exec : None ,
322
- } ) ,
323
- GpuPreference :: NonDefault => options. push ( ContextOption {
324
- id : 0 ,
325
- name : "Discrete Graphics" . to_owned ( ) ,
326
- description : "Launch Using Discrete Graphics Card" . to_owned ( ) ,
327
- exec : None ,
328
- } ) ,
329
- }
330
- }
317
+ ContextAction :: GpuPreference ( pref) => match pref {
318
+ GpuPreference :: Default => options. push ( ContextOption {
319
+ id : 0 ,
320
+ name : "Integrated Graphics" . to_owned ( ) ,
321
+ description : "Launch Using Integrated Graphics Card" . to_owned ( ) ,
322
+ exec : None ,
323
+ } ) ,
324
+ GpuPreference :: NonDefault => options. push ( ContextOption {
325
+ id : 0 ,
326
+ name : "Discrete Graphics" . to_owned ( ) ,
327
+ description : "Launch Using Discrete Graphics Card" . to_owned ( ) ,
328
+ exec : None ,
329
+ } ) ,
330
+ } ,
331
331
}
332
332
}
333
333
0 commit comments