@@ -7,20 +7,19 @@ use std::{fs, path::PathBuf, sync::Arc};
77use app_state:: AppState ;
88use components:: theme:: Theme ;
99use gpui:: * ;
10+ use http_client:: anyhow;
1011
11- struct Assets {
12- base : PathBuf ,
13- }
12+ # [ derive ( rust_embed :: RustEmbed ) ]
13+ # [ folder = "../../assets" ]
14+ struct Assets ;
1415
1516impl AssetSource for Assets {
1617 fn load ( & self , path : & str ) -> Result < Option < std:: borrow:: Cow < ' static , [ u8 ] > > > {
17- fs :: read ( self . base . join ( path) ) . map ( |data | Some ( std :: borrow :: Cow :: Owned ( data) ) ) . map_err ( |e| e . into ( ) )
18+ Self :: get ( path) . map ( |f | Some ( f . data ) ) . ok_or_else ( || anyhow ! ( "could not find asset at path \" {} \" " , path ) )
1819 }
1920
2021 fn list ( & self , path : & str ) -> Result < Vec < SharedString > > {
21- fs:: read_dir ( self . base . join ( path) )
22- . map ( |entries| entries. filter_map ( |entry| entry. ok ( ) . and_then ( |entry| entry. file_name ( ) . into_string ( ) . ok ( ) ) . map ( SharedString :: from) ) . collect ( ) )
23- . map_err ( |e| e. into ( ) )
22+ Ok ( Self :: iter ( ) . filter_map ( |p| if p. starts_with ( path) { Some ( p. into ( ) ) } else { None } ) . collect ( ) )
2423 }
2524}
2625
@@ -40,31 +39,26 @@ async fn main() {
4039
4140 let app_state = Arc :: new ( AppState { } ) ;
4241
43- App :: new ( )
44- . with_assets ( Assets {
45- base : PathBuf :: from ( "assets" ) ,
46- } )
47- . with_http_client ( Arc :: new ( reqwest_client:: ReqwestClient :: new ( ) ) )
48- . run ( move |cx : & mut AppContext | {
49- AppState :: set_global ( Arc :: downgrade ( & app_state) , cx) ;
50-
51- if let Err ( e) = init ( app_state. clone ( ) , cx) {
52- log:: error!( "{}" , e) ;
53- return ;
54- }
55-
56- Theme :: sync_system_appearance ( cx) ;
57-
58- let opts = WindowOptions {
59- window_decorations : Some ( WindowDecorations :: Client ) ,
60- titlebar : Some ( TitlebarOptions {
61- appears_transparent : true ,
62- title : Some ( SharedString :: new_static ( "scope" ) ) ,
63- ..Default :: default ( )
64- } ) ,
42+ App :: new ( ) . with_assets ( Assets ) . with_http_client ( Arc :: new ( reqwest_client:: ReqwestClient :: new ( ) ) ) . run ( move |cx : & mut AppContext | {
43+ AppState :: set_global ( Arc :: downgrade ( & app_state) , cx) ;
44+
45+ if let Err ( e) = init ( app_state. clone ( ) , cx) {
46+ log:: error!( "{}" , e) ;
47+ return ;
48+ }
49+
50+ Theme :: sync_system_appearance ( cx) ;
51+
52+ let opts = WindowOptions {
53+ window_decorations : Some ( WindowDecorations :: Client ) ,
54+ titlebar : Some ( TitlebarOptions {
55+ appears_transparent : true ,
56+ title : Some ( SharedString :: new_static ( "scope" ) ) ,
6557 ..Default :: default ( )
66- } ;
58+ } ) ,
59+ ..Default :: default ( )
60+ } ;
6761
68- cx. open_window ( opts, |cx| cx. new_view ( |cx| crate :: app:: App :: new ( cx) ) ) . unwrap ( ) ;
69- } ) ;
62+ cx. open_window ( opts, |cx| cx. new_view ( |cx| crate :: app:: App :: new ( cx) ) ) . unwrap ( ) ;
63+ } ) ;
7064}
0 commit comments