@@ -7,6 +7,7 @@ mod config;
77mod data_types;
88mod embed_data;
99mod gresource;
10+ mod installer;
1011mod localization;
1112mod logger;
1213mod pages;
@@ -17,7 +18,6 @@ use data_types::*;
1718use utils:: * ;
1819
1920use std:: collections:: HashMap ;
20- use std:: io:: { BufRead , BufReader } ;
2121use std:: path:: Path ;
2222use std:: sync:: { Arc , Mutex } ;
2323use std:: { fs, str} ;
@@ -31,8 +31,7 @@ use gtk::{gdk, glib, Builder, HeaderBar, Window};
3131use i18n_embed:: DesktopLanguageRequester ;
3232use once_cell:: sync:: Lazy ;
3333use serde_json:: json;
34- use subprocess:: { Exec , Redirection } ;
35- use tracing:: { debug, error, info} ;
34+ use tracing:: { debug, error} ;
3635use unic_langid:: LanguageIdentifier ;
3736
3837const RESPREFIX : & str = "/org/cachyos/hello" ;
@@ -43,155 +42,6 @@ static G_SAVE_JSON: Lazy<Mutex<serde_json::Value>> = Lazy::new(|| {
4342} ) ;
4443static mut G_HELLO_WINDOW : Option < Arc < HelloWindow > > = None ;
4544
46- #[ derive( serde:: Deserialize ) ]
47- struct Versions {
48- #[ serde( rename = "desktopISOVersion" ) ]
49- desktop_iso_version : String ,
50- #[ serde( rename = "handheldISOVersion" ) ]
51- handheld_iso_version : String ,
52- }
53-
54- fn outdated_version_check ( message : String ) -> bool {
55- let edition_tag: String =
56- fs:: read_to_string ( "/etc/edition-tag" ) . unwrap_or ( "desktop" . into ( ) ) . trim ( ) . into ( ) ;
57- let version_tag: String =
58- fs:: read_to_string ( "/etc/version-tag" ) . unwrap_or ( "testing" . into ( ) ) . trim ( ) . into ( ) ;
59-
60- let window_ref = unsafe { & G_HELLO_WINDOW . as_ref ( ) . unwrap ( ) . window } ;
61-
62- if version_tag. contains ( "testing" ) {
63- utils:: show_simple_dialog (
64- window_ref,
65- gtk:: MessageType :: Warning ,
66- & fl ! ( "testing-iso-warning" ) ,
67- message. clone ( ) ,
68- ) ;
69- return true ;
70- }
71-
72- let response = reqwest:: blocking:: get ( "https://cachyos.org/versions.json" ) ;
73-
74- if response. is_err ( ) {
75- utils:: show_simple_dialog (
76- window_ref,
77- gtk:: MessageType :: Warning ,
78- & fl ! ( "offline-error" ) ,
79- message. clone ( ) ,
80- ) ;
81- return false ;
82- }
83-
84- let versions = response. unwrap ( ) . json :: < Versions > ( ) . unwrap ( ) ;
85-
86- let latest_version = if edition_tag. contains ( "desktop" ) {
87- versions. desktop_iso_version
88- } else {
89- versions. handheld_iso_version
90- }
91- . trim ( )
92- . to_owned ( ) ;
93-
94- if version_tag != latest_version {
95- utils:: show_simple_dialog (
96- window_ref,
97- gtk:: MessageType :: Warning ,
98- & fl ! ( "outdated-version-warning" ) ,
99- message. clone ( ) ,
100- ) ;
101- }
102- true
103- }
104-
105- fn edition_compat_check ( message : String ) -> bool {
106- let edition_tag = fs:: read_to_string ( "/etc/edition-tag" ) . unwrap_or ( "desktop" . to_string ( ) ) ;
107-
108- if edition_tag == "handheld" {
109- let profiles_path =
110- format ! ( "{}/handhelds/profiles.toml" , chwd:: consts:: CHWD_PCI_CONFIG_DIR ) ;
111-
112- let handheld_profiles =
113- chwd:: profile:: parse_profiles ( & profiles_path) . expect ( "Failed to parse profiles" ) ;
114- let handheld_profile_names: Vec < _ > =
115- handheld_profiles. iter ( ) . map ( |profile| & profile. name ) . collect ( ) ;
116-
117- let available_profiles = chwd:: profile:: get_available_profiles ( false ) ;
118-
119- if available_profiles. iter ( ) . any ( |profile| handheld_profile_names. contains ( & & profile. name ) )
120- {
121- let window_ref = unsafe { & G_HELLO_WINDOW . as_ref ( ) . unwrap ( ) . window } ;
122- utils:: show_simple_dialog (
123- window_ref,
124- gtk:: MessageType :: Warning ,
125- & fl ! ( "unsupported-hw-warning" ) ,
126- message. clone ( ) ,
127- ) ;
128- return true ;
129- }
130- }
131- true
132- }
133-
134- fn connectivity_check ( message : String ) -> bool {
135- let status = match reqwest:: blocking:: get ( "https://cachyos.org" ) {
136- Ok ( resp) => resp. status ( ) . is_success ( ) || resp. status ( ) . is_server_error ( ) ,
137- _ => false ,
138- } ;
139-
140- if !status {
141- let window_ref = unsafe { & G_HELLO_WINDOW . as_ref ( ) . unwrap ( ) . window } ;
142- utils:: show_simple_dialog (
143- window_ref,
144- gtk:: MessageType :: Error ,
145- & fl ! ( "offline-error" ) ,
146- message,
147- ) ;
148- return false ;
149- }
150- true
151- }
152-
153- fn quick_message ( message : String ) {
154- // Spawn child process in separate thread.
155- std:: thread:: spawn ( move || {
156- let builder = unsafe { & G_HELLO_WINDOW . as_ref ( ) . unwrap ( ) . builder } ;
157-
158- let install_btn: gtk:: Button = builder. object ( "install" ) . unwrap ( ) ;
159- install_btn. set_sensitive ( false ) ;
160-
161- let checks = [ connectivity_check, edition_compat_check, outdated_version_check] ;
162- if !checks. iter ( ) . all ( |x| x ( message. clone ( ) ) ) {
163- // if any check failed, return
164- info ! ( "Some ISO check failed!" ) ;
165- install_btn. set_sensitive ( true ) ;
166- return ;
167- }
168-
169- // Spawning child process
170- info ! ( "ISO checks passed! Starting Installer.." ) ;
171- let mut child = Exec :: cmd ( "/usr/local/bin/calamares-online.sh" )
172- . stdout ( Redirection :: Pipe )
173- . stderr ( Redirection :: Merge )
174- . popen ( )
175- . expect ( "Failed to spawn installer" ) ;
176-
177- let child_out = child. stdout . take ( ) . unwrap ( ) ;
178- let child_read = BufReader :: new ( child_out) ;
179-
180- // Read the output line by line until EOF
181- for line_result in child_read. lines ( ) {
182- match line_result {
183- Ok ( line) => info ! ( "{line}" ) ,
184- Err ( e) => error ! ( "Error reading output: {e}" ) ,
185- }
186- }
187-
188- let status = child. wait ( ) . expect ( "Failed to waiting for child" ) ;
189- info ! ( "Installer finished with status: {:?}" , status) ;
190-
191- install_btn. set_sensitive ( true ) ;
192- } ) ;
193- }
194-
19545fn show_about_dialog ( ) {
19646 let main_window: & Window = unsafe { G_HELLO_WINDOW . as_ref ( ) . unwrap ( ) . window . as_ref ( ) } ;
19747 let logo_path = format ! ( "/usr/share/icons/hicolor/scalable/apps/{APP_ID}.svg" ) ;
@@ -422,9 +272,7 @@ fn build_ui(application: >k::Application) {
422272 autostart_switch. set_active ( autostart) ;
423273
424274 // Live systems
425- if ( Path :: new ( & preferences[ "live_path" ] . as_str ( ) . unwrap ( ) ) . exists ( ) )
426- && ( check_regular_file ( preferences[ "installer_path" ] . as_str ( ) . unwrap ( ) ) )
427- {
275+ if installer:: is_iso ( & preferences) {
428276 let installlabel: gtk:: Label = builder. object ( "installlabel" ) . unwrap ( ) ;
429277 installlabel. set_visible ( true ) ;
430278
@@ -610,7 +458,7 @@ fn on_action_clicked(param: &[glib::Value]) -> Option<glib::Value> {
610458 let widget = param[ 0 ] . get :: < gtk:: Widget > ( ) . unwrap ( ) ;
611459 match widget. widget_name ( ) . as_str ( ) {
612460 "install" => {
613- quick_message ( fl ! ( "calamares-install-type" ) ) ;
461+ installer :: launch_installer ( fl ! ( "calamares-install-type" ) ) ;
614462 None
615463 } ,
616464 "autostart" => {
0 commit comments