@@ -157,36 +157,35 @@ impl page::Page<crate::pages::Message> for Page {
157157 }
158158
159159 fn dialog ( & self ) -> Option < crate :: pages:: Element < ' _ > > {
160- if let Some ( app_to_remove) = & self . app_to_remove {
161- if let Some ( cached_startup_apps) = & self . cached_startup_apps {
162- if let Some ( target_directory_type) = & self . target_directory_type {
163- return Some (
164- widget:: dialog ( )
165- . title ( fl ! (
166- "startup-apps" ,
167- "remove-dialog-title" ,
168- name = app_to_remove. name( & cached_startup_apps. locales)
169- ) )
170- . icon ( icon:: from_name ( "dialog-warning" ) . size ( 64 ) )
171- . body ( fl ! ( "startup-apps" , "remove-dialog-description" ) )
172- . primary_action (
173- button:: suggested ( fl ! ( "remove" ) ) . on_press (
174- Message :: RemoveStartupApplication (
175- target_directory_type. clone ( ) ,
176- app_to_remove. clone ( ) ,
177- true ,
178- )
179- . into ( ) ,
180- ) ,
160+ if let Some ( app_to_remove) = & self . app_to_remove
161+ && let Some ( cached_startup_apps) = & self . cached_startup_apps
162+ && let Some ( target_directory_type) = & self . target_directory_type
163+ {
164+ return Some (
165+ widget:: dialog ( )
166+ . title ( fl ! (
167+ "startup-apps" ,
168+ "remove-dialog-title" ,
169+ name = app_to_remove. name( & cached_startup_apps. locales)
170+ ) )
171+ . icon ( icon:: from_name ( "dialog-warning" ) . size ( 64 ) )
172+ . body ( fl ! ( "startup-apps" , "remove-dialog-description" ) )
173+ . primary_action (
174+ button:: suggested ( fl ! ( "remove" ) ) . on_press (
175+ Message :: RemoveStartupApplication (
176+ target_directory_type. clone ( ) ,
177+ app_to_remove. clone ( ) ,
178+ true ,
181179 )
182- . secondary_action (
183- button:: standard ( fl ! ( "cancel" ) )
184- . on_press ( Message :: CancelRemoveStartupApplication . into ( ) ) ,
185- )
186- . apply ( Element :: from) ,
187- ) ;
188- }
189- }
180+ . into ( ) ,
181+ ) ,
182+ )
183+ . secondary_action (
184+ button:: standard ( fl ! ( "cancel" ) )
185+ . on_press ( Message :: CancelRemoveStartupApplication . into ( ) ) ,
186+ )
187+ . apply ( Element :: from) ,
188+ ) ;
190189 }
191190 None
192191 }
@@ -228,32 +227,31 @@ impl Page {
228227
229228 _ = std:: fs:: create_dir_all ( directory_to_target. as_path ( ) ) ;
230229
231- if let Ok ( exists) = std:: fs:: exists ( directory_to_target. join ( file_name. clone ( ) ) ) {
232- if !exists {
233- // when adding an application, we want to symlink to be more user-friendly
234- // this ensures that, as an application gets updated / removed, so does the
235- // symlink
236- match std:: os:: unix:: fs:: symlink (
237- app. clone ( ) . path ,
238- directory_to_target. join ( file_name) ,
239- ) {
240- Ok ( _) => {
241- if let Some ( ref mut cached_startup_apps) = self . cached_startup_apps
242- {
243- let target_apps = cached_startup_apps. apps . get ( & directory_type) ;
244- if let Some ( target_apps) = target_apps {
245- let mut new_apps = target_apps. clone ( ) ;
246- new_apps. push ( app. clone ( ) ) ;
247-
248- cached_startup_apps
249- . apps
250- . insert ( directory_type. clone ( ) , new_apps) ;
251- }
230+ if let Ok ( exists) = std:: fs:: exists ( directory_to_target. join ( file_name. clone ( ) ) )
231+ && !exists
232+ {
233+ // when adding an application, we want to symlink to be more user-friendly
234+ // this ensures that, as an application gets updated / removed, so does the
235+ // symlink
236+ match std:: os:: unix:: fs:: symlink (
237+ app. clone ( ) . path ,
238+ directory_to_target. join ( file_name) ,
239+ ) {
240+ Ok ( _) => {
241+ if let Some ( ref mut cached_startup_apps) = self . cached_startup_apps {
242+ let target_apps = cached_startup_apps. apps . get ( & directory_type) ;
243+ if let Some ( target_apps) = target_apps {
244+ let mut new_apps = target_apps. clone ( ) ;
245+ new_apps. push ( app. clone ( ) ) ;
246+
247+ cached_startup_apps
248+ . apps
249+ . insert ( directory_type. clone ( ) , new_apps) ;
252250 }
253251 }
254- Err ( e ) => {
255- error ! ( ?e , "Failed to symlink" ) ;
256- }
252+ }
253+ Err ( e ) => {
254+ error ! ( ?e , "Failed to symlink" ) ;
257255 }
258256 }
259257 }
@@ -273,33 +271,30 @@ impl Page {
273271 let directory_to_target =
274272 directories. first ( ) . expect ( "Always at least one directory" ) ;
275273 if let Ok ( exists) = std:: fs:: exists ( directory_to_target. join ( file_name. clone ( ) ) )
274+ && exists
276275 {
277- if exists {
278- // remove_file works for both regular files & symlinks
279- match std:: fs:: remove_file ( directory_to_target. join ( file_name) ) {
280- Ok ( _) => {
281- if let Some ( ref mut cached_startup_apps) =
282- self . cached_startup_apps
283- {
284- let target_apps =
285- cached_startup_apps. apps . get ( & directory_type) ;
286- if let Some ( target_apps) = target_apps {
287- let mut new_apps = Vec :: new ( ) ;
288- for old_app in target_apps {
289- if old_app != & app {
290- new_apps. push ( old_app. clone ( ) ) ;
291- }
276+ // remove_file works for both regular files & symlinks
277+ match std:: fs:: remove_file ( directory_to_target. join ( file_name) ) {
278+ Ok ( _) => {
279+ if let Some ( ref mut cached_startup_apps) = self . cached_startup_apps
280+ {
281+ let target_apps = cached_startup_apps. apps . get ( & directory_type) ;
282+ if let Some ( target_apps) = target_apps {
283+ let mut new_apps = Vec :: new ( ) ;
284+ for old_app in target_apps {
285+ if old_app != & app {
286+ new_apps. push ( old_app. clone ( ) ) ;
292287 }
293-
294- cached_startup_apps
295- . apps
296- . insert ( directory_type. clone ( ) , new_apps) ;
297288 }
289+
290+ cached_startup_apps
291+ . apps
292+ . insert ( directory_type. clone ( ) , new_apps) ;
298293 }
299294 }
300- Err ( e ) => {
301- error ! ( ?e , "Failed to remove file" ) ;
302- }
295+ }
296+ Err ( e ) => {
297+ error ! ( ?e , "Failed to remove file" ) ;
303298 }
304299 }
305300 }
@@ -330,39 +325,30 @@ impl Page {
330325
331326 if let Some ( startup_apps) = & self . cached_startup_apps {
332327 for app in & startup_apps. all_apps {
333- if let Some ( name) = app. name ( & startup_apps. locales ) {
334- if let Some ( exec) = app. exec ( ) {
335- if search_input. is_empty ( )
336- || exec. to_lowercase ( ) . contains ( search_input)
337- || name. to_lowercase ( ) . contains ( search_input)
338- {
339- let mut row = widget:: row:: with_capacity ( 3 )
340- . spacing ( space_xs)
341- . align_y ( Alignment :: Center ) ;
342-
343- row = row. push (
344- icon:: from_name ( app. icon ( ) . unwrap_or ( "application-default" ) )
345- . size ( 32 ) ,
346- ) ;
347-
348- if let Some ( name) = app. name ( & startup_apps. locales ) {
349- row = row. push ( text ( name) . width ( Length :: Fill ) ) ;
350- } else {
351- row = row. push ( text ( & app. appid ) . width ( Length :: Fill ) ) ;
352- }
353- row = row. push (
354- widget:: button:: text ( fl ! ( "add" ) ) . on_press (
355- Message :: AddStartupApplication (
356- directory_type. clone ( ) ,
357- app. clone ( ) ,
358- )
359- . into ( ) ,
360- ) ,
361- ) ;
362-
363- list = list. add ( row)
364- }
328+ if let Some ( name) = app. name ( & startup_apps. locales )
329+ && let Some ( exec) = app. exec ( )
330+ && ( search_input. is_empty ( )
331+ || exec. to_lowercase ( ) . contains ( search_input)
332+ || name. to_lowercase ( ) . contains ( search_input) )
333+ {
334+ let mut row = widget:: row:: with_capacity ( 3 )
335+ . spacing ( space_xs)
336+ . align_y ( Alignment :: Center ) ;
337+
338+ row = row. push (
339+ icon:: from_name ( app. icon ( ) . unwrap_or ( "application-default" ) ) . size ( 32 ) ,
340+ ) ;
341+
342+ if let Some ( name) = app. name ( & startup_apps. locales ) {
343+ row = row. push ( text ( name) . width ( Length :: Fill ) ) ;
344+ } else {
345+ row = row. push ( text ( & app. appid ) . width ( Length :: Fill ) ) ;
365346 }
347+ row = row. push ( widget:: button:: text ( fl ! ( "add" ) ) . on_press (
348+ Message :: AddStartupApplication ( directory_type. clone ( ) , app. clone ( ) ) . into ( ) ,
349+ ) ) ;
350+
351+ list = list. add ( row)
366352 }
367353 }
368354 }
@@ -467,16 +453,16 @@ fn get_all_apps(locales: Vec<String>) -> Vec<DesktopEntry> {
467453 }
468454
469455 // skip if we can't run this in COSMIC
470- if let Some ( only_show_in) = entry. only_show_in ( ) {
471- if !only_show_in. contains ( & "COSMIC" ) {
472- continue ;
473- }
456+ if let Some ( only_show_in) = entry. only_show_in ( )
457+ && !only_show_in. contains ( & "COSMIC" )
458+ {
459+ continue ;
474460 }
475461
476- if let Some ( not_show_in) = entry. not_show_in ( ) {
477- if not_show_in. contains ( & "COSMIC" ) {
478- continue ;
479- }
462+ if let Some ( not_show_in) = entry. not_show_in ( )
463+ && not_show_in. contains ( & "COSMIC" )
464+ {
465+ continue ;
480466 }
481467
482468 result. push ( entry. clone ( ) ) ;
0 commit comments