@@ -12,8 +12,11 @@ use cosmic::{
12
12
widget:: { self , dropdown, icon, settings} ,
13
13
Apply , Element , Task ,
14
14
} ;
15
+ use cosmic_config:: { ConfigGet , ConfigSet } ;
16
+ use cosmic_settings_config:: shortcuts:: action:: System ;
17
+ use cosmic_settings_config:: shortcuts:: SystemActions ;
15
18
use cosmic_settings_page:: { self as page, section, Section } ;
16
- use freedesktop_desktop_entry:: { default_paths, DesktopEntry , Iter as DesktopEntryIter } ;
19
+ use freedesktop_desktop_entry:: { default_paths, get_languages_from_env , DesktopEntry , Iter as DesktopEntryIter } ;
17
20
use mime_apps:: App ;
18
21
use slotmap:: SlotMap ;
19
22
use tokio:: sync:: mpsc;
@@ -81,6 +84,7 @@ pub struct AppMeta {
81
84
pub struct Page {
82
85
on_enter_handle : Option < cosmic:: iced:: task:: Handle > ,
83
86
mime_apps : Option < CachedMimeApps > ,
87
+ shortcuts_config : Option < cosmic_config:: Config >
84
88
}
85
89
86
90
impl page:: AutoBind < crate :: pages:: Message > for Page { }
@@ -107,6 +111,10 @@ impl page::Page<crate::pages::Message> for Page {
107
111
handle. abort ( ) ;
108
112
}
109
113
114
+ if self . shortcuts_config . is_none ( ) {
115
+ self . shortcuts_config = cosmic_settings_config:: shortcuts:: context ( ) . ok ( ) ;
116
+ }
117
+
110
118
let ( task, on_enter_handle) = Task :: future ( async move {
111
119
let mut list = mime_apps:: List :: default ( ) ;
112
120
list. load_from_paths ( & mime_apps:: list_paths ( ) ) ;
@@ -239,6 +247,50 @@ impl Page {
239
247
if meta. selected != Some ( id) {
240
248
meta. selected = Some ( id) ;
241
249
let appid = & meta. app_ids [ id] ;
250
+
251
+ // if we're changing terminal, we want to update the COSMIC system actions shortcut
252
+ // for terminal
253
+ if category == Category :: Terminal && self . shortcuts_config . is_some ( ) {
254
+ let shortcuts = self . shortcuts_config . as_ref ( ) . unwrap ( ) ;
255
+ let system_actions = shortcuts. get :: < SystemActions > ( "system_actions" ) ;
256
+ match system_actions {
257
+ Err ( e) => {
258
+ // we don't have system_actions set?
259
+ println ! ( "{}" , e) ;
260
+ }
261
+ Ok ( mut actions) => {
262
+ // get the current terminal option, which should default to cosmic-term
263
+ let current_terminal = actions. get ( & System :: Terminal ) ;
264
+ if current_terminal. is_some ( ) {
265
+ let default_paths = default_paths ( ) ;
266
+ let mut resolved_path = None ;
267
+
268
+ // loop through all FDE paths to try and find a valid .desktop file
269
+ for path in default_paths {
270
+ let full_path = path. join ( [ appid, ".desktop" ] . concat ( ) ) ;
271
+ if full_path. exists ( ) && full_path. is_file ( ) {
272
+ resolved_path = Some ( full_path) ;
273
+ }
274
+ }
275
+
276
+ // if we find a valid .desktop file, we can grab its exec
277
+ if resolved_path. is_some ( ) {
278
+ let desktop_entry = DesktopEntry :: from_path ( resolved_path. unwrap ( ) , Some ( & get_languages_from_env ( ) ) ) ;
279
+ if desktop_entry. is_ok ( ) {
280
+ // grab the exec, add it to system_actions and commit
281
+ let exec = String :: from ( desktop_entry. unwrap ( ) . exec ( ) . unwrap ( ) ) ;
282
+ actions. insert ( System :: Terminal , exec) ;
283
+
284
+ if let Err ( e) = shortcuts. set ( "system_actions" , actions) {
285
+ println ! ( "{}" , e) ;
286
+ }
287
+ }
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+
242
294
for mime in mime_types {
243
295
if let Ok ( mime) = mime. parse ( ) {
244
296
mime_apps
0 commit comments