@@ -21,7 +21,6 @@ use cosmic::{
21
21
Application , ApplicationExt , Apply , Element , Task ,
22
22
} ;
23
23
use key_bind:: key_binds;
24
- use pages:: color_schemes:: providers:: cosmic_themes:: CosmicTheme ;
25
24
26
25
use crate :: {
27
26
app:: {
@@ -32,7 +31,7 @@ use crate::{
32
31
fl,
33
32
pages:: {
34
33
self ,
35
- color_schemes:: { config :: ColorScheme , preview , ColorSchemeProvider , ColorSchemes } ,
34
+ color_schemes:: { self , ColorSchemes , Status , Tab } ,
36
35
dock:: Dock ,
37
36
layouts:: Layouts ,
38
37
panel:: Panel ,
@@ -67,23 +66,12 @@ pub struct TweakTool {
67
66
app_themes : Vec < String > ,
68
67
config_handler : Option < cosmic_config:: Config > ,
69
68
config : TweaksConfig ,
70
- available : Vec < ColorScheme > ,
71
- status : Status ,
72
- limit : usize ,
73
- offset : usize ,
74
- }
75
-
76
- pub enum Status {
77
- Idle ,
78
- Loading ,
79
- LoadingMore ,
80
69
}
81
70
82
71
#[ derive( Clone , Debug , Eq , PartialEq ) ]
83
72
pub enum DialogPage {
84
73
SaveCurrentColorScheme ( String ) ,
85
74
CreateSnapshot ( String ) ,
86
- AvailableColorSchemes ,
87
75
}
88
76
89
77
#[ derive( Debug , Clone ) ]
@@ -102,8 +90,6 @@ pub enum Message {
102
90
ToggleContextDrawer ,
103
91
ToggleDialogPage ( DialogPage ) ,
104
92
AppTheme ( usize ) ,
105
- FetchAvailableColorSchemes ( ColorSchemeProvider , usize ) ,
106
- SetAvailableColorSchemes ( Vec < ColorScheme > ) ,
107
93
Key ( Modifiers , Key ) ,
108
94
Modifiers ( Modifiers ) ,
109
95
SystemThemeModeChange ,
@@ -213,18 +199,16 @@ impl Application for TweakTool {
213
199
app_themes : vec ! [ fl!( "match-desktop" ) , fl!( "dark" ) , fl!( "light" ) ] ,
214
200
config_handler : flags. config_handler ,
215
201
config : flags. config ,
216
- available : vec ! [ ] ,
217
- status : Status :: Idle ,
218
- limit : 15 ,
219
- offset : 0 ,
220
202
shorcuts : Shortcuts :: new ( ) ,
221
203
} ;
222
204
223
205
let mut tasks = vec ! [
224
- app. update( Message :: FetchAvailableColorSchemes (
225
- ColorSchemeProvider :: CosmicThemes ,
226
- app. limit,
227
- ) ) ,
206
+ app. update( Message :: ColorSchemes ( Box :: new(
207
+ color_schemes:: Message :: FetchAvailableColorSchemes (
208
+ color_schemes:: ColorSchemeProvider :: CosmicThemes ,
209
+ app. color_schemes. limit,
210
+ ) ,
211
+ ) ) ) ,
228
212
app. update( Message :: Snapshots (
229
213
pages:: snapshots:: Message :: CreateSnapshot (
230
214
fl!( "application-opened" ) ,
@@ -319,17 +303,17 @@ impl Application for TweakTool {
319
303
widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
320
304
)
321
305
. control (
322
- widget:: column:: with_children ( vec ! [
323
- widget:: text:: body( fl!( "color-scheme-name" ) ) . into ( ) ,
324
- widget :: text_input ( "" , name . as_str ( ) )
325
- . id ( self . dialog_text_input . clone ( ) )
326
- . on_input ( move |name| {
327
- Message :: DialogUpdate ( DialogPage :: SaveCurrentColorScheme ( name) )
328
- } )
329
- . on_submit ( Message :: DialogComplete )
330
- . into ( ) ,
331
- ] )
332
- . spacing ( spacing. space_xxs ) ,
306
+ widget:: column ( )
307
+ . push ( widget:: text:: body ( fl ! ( "color-scheme-name" ) ) )
308
+ . push (
309
+ widget :: text_input ( "" , name . as_str ( ) )
310
+ . id ( self . dialog_text_input . clone ( ) )
311
+ . on_input ( move | name| {
312
+ Message :: DialogUpdate ( DialogPage :: SaveCurrentColorScheme ( name ) )
313
+ } )
314
+ . on_submit ( Message :: DialogComplete ) ,
315
+ )
316
+ . spacing ( spacing. space_xxs ) ,
333
317
) ,
334
318
DialogPage :: CreateSnapshot ( name) => widget:: dialog ( )
335
319
. title ( fl ! ( "create-snapshot" ) )
@@ -349,39 +333,6 @@ impl Application for TweakTool {
349
333
} )
350
334
. on_submit ( Message :: DialogComplete ) ,
351
335
) ,
352
- DialogPage :: AvailableColorSchemes => {
353
- let show_more_button: Option < Element < Message > > = match self . status {
354
- Status :: Idle => Some (
355
- widget:: button:: text ( fl ! ( "show-more" ) )
356
- . on_press ( Message :: FetchAvailableColorSchemes (
357
- ColorSchemeProvider :: CosmicThemes ,
358
- self . limit ,
359
- ) )
360
- . class ( cosmic:: style:: Button :: Standard )
361
- . into ( ) ,
362
- ) ,
363
- Status :: LoadingMore => Some (
364
- widget:: button:: text ( fl ! ( "loading" ) )
365
- . class ( cosmic:: style:: Button :: Standard )
366
- . into ( ) ,
367
- ) ,
368
- Status :: Loading => None ,
369
- } ;
370
-
371
- let mut dialog = widget:: dialog ( )
372
- . title ( fl ! ( "available" ) )
373
- . body ( fl ! ( "available-color-schemes-body" ) )
374
- . secondary_action (
375
- widget:: button:: standard ( fl ! ( "close" ) ) . on_press ( Message :: DialogCancel ) ,
376
- )
377
- . control ( self . available_themes ( ) ) ;
378
-
379
- if let Some ( show_more_button) = show_more_button {
380
- dialog = dialog. primary_action ( show_more_button) ;
381
- }
382
-
383
- dialog
384
- }
385
336
} ;
386
337
387
338
Some ( dialog. into ( ) )
@@ -405,14 +356,74 @@ impl Application for TweakTool {
405
356
Page :: Shortcuts => self . shorcuts . view ( ) . map ( Message :: Shortcuts ) ,
406
357
} ;
407
358
408
- widget:: column:: with_children ( vec ! [ view] )
359
+ widget:: column ( )
360
+ . push ( view)
409
361
. padding ( spacing. space_xs )
410
362
. width ( Length :: Fill )
411
363
. height ( Length :: Fill )
412
364
. align_x ( Alignment :: Center )
413
365
. into ( )
414
366
}
415
367
368
+ fn footer ( & self ) -> Option < Element < Self :: Message > > {
369
+ let spacing = cosmic:: theme:: active ( ) . cosmic ( ) . spacing ;
370
+
371
+ match self . nav_model . active_data :: < Page > ( ) {
372
+ Some ( Page :: ColorSchemes ) => match self . color_schemes . model . active_data :: < Tab > ( ) {
373
+ Some ( Tab :: Installed ) => Some (
374
+ widget:: row ( )
375
+ . push ( widget:: horizontal_space ( ) )
376
+ . push (
377
+ widget:: button:: standard ( fl ! ( "save-current-color-scheme" ) )
378
+ . trailing_icon ( icons:: get_handle ( "arrow-into-box-symbolic" , 16 ) )
379
+ . on_press ( Message :: ColorSchemes ( Box :: new (
380
+ color_schemes:: Message :: SaveCurrentColorScheme ( None ) ,
381
+ ) ) ) ,
382
+ )
383
+ . push (
384
+ widget:: button:: standard ( fl ! ( "import-color-scheme" ) )
385
+ . trailing_icon ( icons:: get_handle ( "document-save-symbolic" , 16 ) )
386
+ . on_press ( Message :: ColorSchemes ( Box :: new (
387
+ color_schemes:: Message :: StartImport ,
388
+ ) ) ) ,
389
+ )
390
+ . spacing ( spacing. space_xxs )
391
+ . apply ( widget:: container)
392
+ . class ( cosmic:: style:: Container :: Card )
393
+ . padding ( spacing. space_xxs )
394
+ . into ( ) ,
395
+ ) ,
396
+ Some ( Tab :: Available ) => Some (
397
+ widget:: row ( )
398
+ . push ( widget:: horizontal_space ( ) )
399
+ . push ( match self . color_schemes . status {
400
+ Status :: Idle => widget:: button:: standard ( fl ! ( "show-more" ) )
401
+ . leading_icon ( crate :: core:: icons:: get_handle (
402
+ "content-loading-symbolic" ,
403
+ 16 ,
404
+ ) )
405
+ . on_press ( Message :: ColorSchemes ( Box :: new (
406
+ color_schemes:: Message :: FetchAvailableColorSchemes (
407
+ color_schemes:: ColorSchemeProvider :: CosmicThemes ,
408
+ self . color_schemes . limit ,
409
+ ) ,
410
+ ) ) ) ,
411
+ Status :: LoadingMore | Status :: Loading => {
412
+ widget:: button:: standard ( fl ! ( "loading" ) )
413
+ }
414
+ } )
415
+ . spacing ( spacing. space_xxs )
416
+ . apply ( widget:: container)
417
+ . class ( cosmic:: style:: Container :: Card )
418
+ . padding ( spacing. space_xxs )
419
+ . into ( ) ,
420
+ ) ,
421
+ None => None ,
422
+ } ,
423
+ _ => None ,
424
+ }
425
+ }
426
+
416
427
fn update ( & mut self , message : Self :: Message ) -> cosmic:: Task < app:: Message < Self :: Message > > {
417
428
// Helper for updating config values efficiently
418
429
macro_rules! config_set {
@@ -448,45 +459,6 @@ impl Application for TweakTool {
448
459
log:: error!( "{err}" )
449
460
}
450
461
}
451
- Message :: FetchAvailableColorSchemes ( provider, limit) => {
452
- if self . offset == 0 {
453
- self . status = Status :: Loading ;
454
- } else {
455
- self . status = Status :: LoadingMore ;
456
- }
457
- self . limit = limit;
458
- self . offset += self . limit ;
459
- let limit = self . limit ;
460
- let offset = self . offset ;
461
- tasks. push ( Task :: perform (
462
- async move {
463
- let url = match provider {
464
- ColorSchemeProvider :: CosmicThemes => {
465
- format ! ( "https://cosmic-themes.org/api/themes/?order=name&limit={}&offset={}" , limit, offset)
466
- }
467
- } ;
468
-
469
- let response = reqwest:: get ( url) . await ?;
470
- let themes: Vec < CosmicTheme > = response. json ( ) . await ?;
471
- let available = themes
472
- . into_iter ( )
473
- . map ( ColorScheme :: from)
474
- . collect ( ) ;
475
- Ok ( available)
476
- } ,
477
- |res : Result < Vec < ColorScheme > , reqwest:: Error > | match res {
478
- Ok ( themes) => cosmic:: app:: Message :: App ( Message :: SetAvailableColorSchemes ( themes) ) ,
479
- Err ( e) => {
480
- log:: error!( "{e}" ) ;
481
- cosmic:: app:: Message :: App ( Message :: SetAvailableColorSchemes ( vec ! [ ] ) )
482
- }
483
- } ,
484
- ) ) ;
485
- }
486
- Message :: SetAvailableColorSchemes ( mut available) => {
487
- self . status = Status :: Idle ;
488
- self . available . append ( & mut available) ;
489
- }
490
462
Message :: AppTheme ( index) => {
491
463
let app_theme = match index {
492
464
1 => AppTheme :: Dark ,
@@ -535,9 +507,6 @@ impl Application for TweakTool {
535
507
DialogPage :: SaveCurrentColorScheme ( String :: new ( ) ) ,
536
508
) ) )
537
509
}
538
- pages:: color_schemes:: Message :: OpenAvailableThemes => tasks. push (
539
- self . update ( Message :: ToggleDialogPage ( DialogPage :: AvailableColorSchemes ) ) ,
540
- ) ,
541
510
_ => tasks. push (
542
511
self . color_schemes
543
512
. update ( * message)
@@ -569,7 +538,6 @@ impl Application for TweakTool {
569
538
pages:: snapshots:: Message :: CreateSnapshot ( name, SnapshotKind :: User ) ,
570
539
) ) )
571
540
}
572
- DialogPage :: AvailableColorSchemes => ( ) ,
573
541
}
574
542
}
575
543
}
@@ -645,6 +613,7 @@ impl Application for TweakTool {
645
613
646
614
impl TweakTool {
647
615
fn update_config ( & mut self ) -> Task < cosmic:: app:: Message < Message > > {
616
+ self . color_schemes . refresh_theme_mode ( ) ;
648
617
app:: command:: set_theme ( self . config . app_theme . theme ( ) )
649
618
}
650
619
@@ -666,34 +635,4 @@ impl TweakTool {
666
635
. into( ) ] )
667
636
. into ( )
668
637
}
669
-
670
- fn available_themes < ' a > ( & self ) -> Element < ' a , Message > {
671
- let spacing = cosmic:: theme:: active ( ) . cosmic ( ) . spacing ;
672
-
673
- let loading: Option < Element < ' a , Message > > = if let Status :: Loading = self . status {
674
- Some ( widget:: text ( fl ! ( "loading" ) ) . into ( ) )
675
- } else {
676
- None
677
- } ;
678
-
679
- let available: Option < Element < ' a , Message > > = match self . status {
680
- Status :: Idle | Status :: LoadingMore => {
681
- let themes: Vec < Element < Message > > =
682
- self . available . iter ( ) . map ( preview:: available) . collect ( ) ;
683
- let widgets = widget:: flex_row ( themes)
684
- . row_spacing ( spacing. space_xs )
685
- . column_spacing ( spacing. space_xs )
686
- . apply ( widget:: container)
687
- . padding ( [ 0 , spacing. space_xxs ] ) ;
688
- Some ( widgets. into ( ) )
689
- }
690
- Status :: Loading => None ,
691
- } ;
692
-
693
- widget:: container ( widget:: scrollable ( widget:: column:: with_children (
694
- loading. into_iter ( ) . chain ( available) . collect ( ) ,
695
- ) ) )
696
- . height ( Length :: Fixed ( 450.0 ) )
697
- . into ( )
698
- }
699
638
}
0 commit comments