@@ -27,7 +27,76 @@ async fn open_lines (path: &str) -> Result<Lines<BufReader<File>>, Box<dyn Error
2727 Ok ( reader)
2828}
2929
30+ fn print_section ( title : & str ) {
31+ println ! ( "\n \x1b [90m{}\x1b [0m" , "─" . repeat( 50 ) ) ;
32+ println ! ( "\x1b [90m{}\x1b [0m" , title. to_uppercase( ) ) ;
33+ }
34+
3035impl Config {
36+ pub async fn first_time_setup ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
37+ print_section ( "Autostart" ) ;
38+ let autostart_question = dialoguer:: Confirm :: new ( ) . with_prompt ( "▸ Start automatically on login?" ) . default ( false ) . interact ( ) ?;
39+ print_section ( "Discord Webhook" ) ;
40+ let webhook_url: String = dialoguer:: Input :: new ( ) . with_prompt ( "▸ Webhook URL (optional, Enter to skip)" ) . allow_empty ( true ) . interact_text ( ) ?;
41+
42+ //proxies list input
43+ print_section ( "Proxies" ) ;
44+ let mut proxies_vec = Vec :: new ( ) ;
45+ loop {
46+ let proxy: String = dialoguer:: Input :: new ( ) . with_prompt ( "▸ Add proxy (Enter to finish)" ) . allow_empty ( true ) . validate_with ( |input : & String | {
47+ let trimmed = input. trim ( ) ;
48+ if trimmed. is_empty ( ) {
49+ return Ok ( ( ) ) ;
50+ }
51+ if proxies_vec. contains ( & trimmed. to_string ( ) ) {
52+ Err ( "This proxy is already in the list." )
53+ } else {
54+ Ok ( ( ) )
55+ }
56+ } ) . interact_text ( ) ?;
57+ if proxy. trim ( ) . is_empty ( ) {
58+ break ;
59+ }
60+ proxies_vec. push ( proxy) ;
61+ }
62+
63+ //games list input
64+ print_section ( "Game priority list" ) ;
65+ let mut games_vec: VecDeque < String > = VecDeque :: new ( ) ;
66+
67+ loop {
68+ let prompt = if games_vec. is_empty ( ) {
69+ "▸ First game (Enter to skip)" . to_string ( )
70+ } else {
71+ format ! ( "▸ #{}" , games_vec. len( ) + 1 )
72+ } ;
73+ let game: String = dialoguer:: Input :: new ( ) . with_prompt ( prompt) . allow_empty ( true ) . validate_with ( |input : & String | {
74+ let trimmed = input. trim ( ) ;
75+
76+ if trimmed. is_empty ( ) {
77+ return Ok ( ( ) ) ;
78+ }
79+
80+ if games_vec. contains ( & trimmed. to_string ( ) ) {
81+ Err ( "This game is already in the list." )
82+ } else {
83+ Ok ( ( ) )
84+ }
85+ } ) . interact_text ( ) ?;
86+
87+ if game. trim ( ) . is_empty ( ) {
88+ break ;
89+ }
90+ games_vec. push_back ( game. trim ( ) . to_string ( ) ) ;
91+ }
92+
93+ self . save_games_list ( & games_vec) . await ?;
94+ self . save_proxies_list ( & proxies_vec) . await ?;
95+ self . autostart = autostart_question;
96+ self . discord_webhook_url = webhook_url;
97+ Ok ( ( ) )
98+ }
99+
31100 pub fn configure_autostart ( & self ) -> Result < ( ) , Box < dyn Error > > {
32101 let app_path = {
33102 let path = env:: current_exe ( ) ?;
@@ -91,6 +160,18 @@ impl Config {
91160 Ok ( config)
92161 }
93162
163+ async fn save_games_list ( & self , games : & VecDeque < String > ) -> Result < ( ) , Box < dyn Error > > {
164+ let to_write = games. iter ( ) . map ( |g| format ! ( "{}\n " , g) ) . collect :: < String > ( ) ;
165+ fs:: write ( & self . games_path , to_write) . await ?;
166+ Ok ( ( ) )
167+ }
168+
169+ async fn save_proxies_list ( & self , proxies : & Vec < String > ) -> Result < ( ) , Box < dyn Error > > {
170+ let to_write = proxies. iter ( ) . map ( |p| format ! ( "{}\n " , p) ) . collect :: < String > ( ) ;
171+ fs:: write ( & self . proxies_path , to_write) . await ?;
172+ Ok ( ( ) )
173+ }
174+
94175 pub async fn load_proxies_list ( & self ) -> Result < Vec < String > , Box < dyn Error > > {
95176 let mut reader = open_lines ( & self . proxies_path ) . await ?;
96177
0 commit comments