@@ -3,14 +3,15 @@ mod config;
33mod icons;
44mod platform_tools;
55mod storage;
6+ use components:: footer:: footer;
67use components:: icon_button:: { icon_button, ICON } ;
78use components:: list_item:: list_item;
89use components:: scroll_view:: scroll_view;
910use config:: { LOG_DIR , LOG_FILE , WINDOW_HEIGHT , WINDOW_WIDTH } ;
1011use iced:: keyboard:: Modifiers ;
11- use iced:: widget:: { text_editor, text_input, tooltip } ;
12+ use iced:: widget:: { text_editor, text_input} ;
1213use iced:: window:: Position ;
13- use iced:: { event, keyboard, Alignment , Event , Font , Subscription } ;
14+ use iced:: { event, keyboard, Alignment , Event , Font , Padding , Subscription } ;
1415use iced:: {
1516 widget:: { button, center, container, image, row, text, Column , Text } ,
1617 window, Background , Border , Color , Element , Length , Shadow , Size , Task , Theme ,
@@ -22,7 +23,6 @@ use std::time::{Duration, Instant};
2223use storage:: { BrowserInfo , BrowserProfile , MatchItem , Storage } ;
2324use tracing:: info;
2425use tracing_subscriber:: fmt:: format:: FmtSpan ;
25- use url:: Url ;
2626
2727struct Gomi {
2828 is_default_browser : bool ,
@@ -77,6 +77,7 @@ enum Message {
7777 MoveWindow ( window:: Id ) ,
7878 WindowClosed ,
7979 WindowUnfocused ,
80+ RefreshApplication ,
8081}
8182
8283impl Gomi {
@@ -323,14 +324,25 @@ impl Gomi {
323324 Task :: none ( )
324325 }
325326 }
327+ Message :: RefreshApplication => {
328+ let mut storage = self . storage . clone ( ) ;
329+ Task :: perform (
330+ async move {
331+ storage. delete_all_browsers ( ) ;
332+ let browsers = platform_tools:: get_url_handlers ( ) . await ;
333+ storage. batch_insert_browsers ( browsers. clone ( ) ) ;
334+ browsers
335+ } ,
336+ Message :: GoHome ,
337+ )
338+ }
326339 }
327340 }
328341
329342 fn view ( & self , _: window:: Id ) -> Element < Message > {
330343 let content = match & self . current_page {
331344 Page :: Home => {
332345 let browsers = self . browser_list . clone ( ) . unwrap_or_default ( ) ;
333- let current_url = self . current_url . clone ( ) ;
334346 let is_default_browser = self . is_default_browser ;
335347 if !is_default_browser {
336348 container ( center (
@@ -414,65 +426,23 @@ impl Gomi {
414426 } ,
415427 ICON :: Profile ,
416428 Message :: ListProfiles ( browser. clone ( ) ) ,
429+ "List profiles" . to_string ( ) ,
417430 ) ) ;
418431 }
419432
420- let footer = if let Some ( url) = current_url {
421- let url_cloned = url. clone ( ) ;
422- let url = Url :: parse ( & url) . unwrap ( ) ;
423- let host = url. host_str ( ) . unwrap_or_default ( ) . to_string ( ) ;
424-
425- container ( tooltip (
426- Text :: new ( host) . size ( 13 ) . style ( |_| text:: Style {
427- color : Some ( Color :: from_rgb ( 0.2 , 0.2 , 0.2 ) ) ,
428- } ) ,
429- container (
430- Text :: new ( url_cloned)
431- . size ( 13 )
432- . color ( Color :: from_rgb ( 0.2 , 0.2 , 0.2 ) ) ,
433- )
434- . padding ( 4 )
435- . style ( |_| container:: Style {
436- background : Some ( Background :: Color ( Color :: from_rgb ( 0.9 , 0.9 , 1.0 ) ) ) ,
437- border : Border {
438- radius : 4.0 . into ( ) ,
439- width : 1.0 ,
440- color : Color :: from_rgb ( 0.7 , 0.7 , 0.9 ) ,
441- } ,
442- ..Default :: default ( )
443- } ) ,
444- tooltip:: Position :: Top ,
445- ) )
446- . padding ( [ 8 , 12 ] )
447- . style ( |_| container:: Style {
448- background : Some ( Background :: Color ( Color :: from_rgb ( 0.95 , 0.95 , 1.0 ) ) ) ,
449- border : Border {
450- radius : 8.0 . into ( ) ,
451- width : 1.0 ,
452- color : Color :: from_rgb ( 0.8 , 0.8 , 0.9 ) ,
453- } ,
454- ..Default :: default ( )
455- } )
456- . center_x ( Length :: Fill )
457- } else {
458- container ( Text :: new ( "" ) )
459- } ;
460-
461433 container (
462- Column :: new ( )
463- . push (
464- container ( scroll_view ( content) )
465- . style ( |_| container:: Style {
466- background : Some ( Background :: Color ( Color :: from_rgb (
467- 0.98 , 0.98 , 0.98 ,
468- ) ) ) ,
469- ..Default :: default ( )
470- } )
471- . padding ( 2 )
472- . width ( Length :: Fill )
473- . height ( Length :: Fill ) ,
474- )
475- . push ( footer) ,
434+ Column :: new ( ) . push (
435+ container ( scroll_view ( content) )
436+ . style ( |_| container:: Style {
437+ background : Some ( Background :: Color ( Color :: from_rgb (
438+ 0.98 , 0.98 , 0.98 ,
439+ ) ) ) ,
440+ ..Default :: default ( )
441+ } )
442+ . padding ( 2 )
443+ . width ( Length :: Fill )
444+ . height ( Length :: Fill ) ,
445+ ) ,
476446 )
477447 . width ( Length :: Fill )
478448 . height ( Length :: Fill )
@@ -483,7 +453,10 @@ impl Gomi {
483453 browser,
484454 profile_text,
485455 } => {
486- let mut content = Column :: new ( ) . spacing ( 20 ) . padding ( 20 ) . width ( Length :: Fill ) ;
456+ let mut content = Column :: new ( )
457+ . padding ( Padding :: new ( 12.0 ) )
458+ . width ( Length :: Fill )
459+ . height ( Length :: Fill ) ;
487460
488461 let profile_list =
489462 profiles
@@ -510,23 +483,29 @@ impl Gomi {
510483 } ,
511484 ICON :: Remove ,
512485 Message :: DeleteProfile ( profile. profile . clone ( ) ) ,
486+ "Delete profile" . to_string ( ) ,
513487 ) ;
514488 column. push ( profile_row)
515489 } ) ;
516- content = content. push ( scroll_view ( profile_list) . height ( 200.0 ) ) ;
490+ content = content. push (
491+ container ( scroll_view ( profile_list) )
492+ . height ( Length :: Fill )
493+ . width ( Length :: Fill ) ,
494+ ) ;
517495
518- let add_row = row ! [
519- icon_button( ICON :: Back , Message :: Back ) ,
496+ let input_row = row ! [
497+ icon_button( ICON :: Back , Message :: Back , "Back to home page" . to_string ( ) ) ,
520498 text_input( "New Profile" , & profile_text)
521499 . on_input( Message :: TypeProfileText )
522500 . on_submit( Message :: AddProfile )
523501 . width( Length :: Fill ) ,
524- icon_button( ICON :: Add , Message :: AddProfile )
502+ icon_button( ICON :: Add , Message :: AddProfile , "Add profile" . to_string ( ) )
525503 ]
526504 . spacing ( 12 )
527- . align_y ( Alignment :: Center ) ;
505+ . align_y ( Alignment :: Center )
506+ . height ( 30.0 ) ;
528507
529- content = content. push ( add_row ) ;
508+ content = content. push ( input_row ) ;
530509
531510 container ( content)
532511 . width ( Length :: Fill )
@@ -544,7 +523,11 @@ impl Gomi {
544523 . width ( Length :: Fill )
545524 . height ( Length :: Fill ) ;
546525 let footer = row ! [
547- icon_button( ICON :: Back , Message :: Back ) ,
526+ icon_button(
527+ ICON :: Back ,
528+ Message :: Back ,
529+ "Back to previous page" . to_string( )
530+ ) ,
548531 button( Text :: new( "Save And Open" ) . size( 14 ) . style( |_| text:: Style {
549532 color: Some ( Color :: from_rgb( 1.0 , 1.0 , 1.0 ) ) ,
550533 } ) )
@@ -569,10 +552,11 @@ impl Gomi {
569552 container ( content)
570553 }
571554 } ;
572- content. into ( )
555+ let footer = footer ( self . current_url . clone ( ) , Message :: RefreshApplication ) ;
556+ Column :: new ( ) . push ( content) . push ( footer) . into ( )
573557 }
574558
575- fn theme ( & self , window : window:: Id ) -> Theme {
559+ fn theme ( & self , _ : window:: Id ) -> Theme {
576560 Theme :: default ( )
577561 }
578562
0 commit comments