@@ -604,6 +604,147 @@ def clear_screen():
604604 os .system ("clear" )
605605
606606
607+ def is_laptop ():
608+ try :
609+ with open ("/sys/class/dmi/id/chassis_type" , "r" ) as f :
610+ chassis_type = int (f .read ().strip ())
611+ laptop_types = [8 , 9 , 10 , 11 , 14 , 30 , 31 ]
612+ return chassis_type in laptop_types
613+ except :
614+ return False
615+
616+
617+ def start_iwd_service ():
618+ try :
619+ subprocess .run (["systemctl" , "start" , "iwd" ], check = True )
620+ time .sleep (2 )
621+ return True
622+ except subprocess .CalledProcessError :
623+ return False
624+
625+
626+ def get_wifi_networks ():
627+ try :
628+ result = subprocess .run (
629+ ["iwctl" , "station" , "wlan0" , "scan" ],
630+ capture_output = True ,
631+ text = True ,
632+ timeout = 10 ,
633+ )
634+ time .sleep (3 )
635+ result = subprocess .run (
636+ ["iwctl" , "station" , "wlan0" , "get-networks" ],
637+ capture_output = True ,
638+ text = True ,
639+ timeout = 10 ,
640+ )
641+ if result .returncode == 0 :
642+ networks = []
643+ lines = result .stdout .split ("\n " )
644+ for line in lines [4 :]:
645+ if line .strip () and "PSK" in line or "Open" in line :
646+ parts = line .split ()
647+ if parts :
648+ ssid = parts [0 ]
649+ security = "PSK" if "PSK" in line else "Open"
650+ networks .append (f"{ ssid } ({ security } )" )
651+ return networks
652+ except :
653+ pass
654+ return []
655+
656+
657+ def connect_wifi (ssid , password = None ):
658+ try :
659+ if password :
660+ result = subprocess .run (
661+ ["iwctl" , "--password" , password , "station" , "wlan0" , "connect" , ssid ],
662+ capture_output = True ,
663+ text = True ,
664+ timeout = 15 ,
665+ )
666+ else :
667+ result = subprocess .run (
668+ ["iwctl" , "station" , "wlan0" , "connect" , ssid ],
669+ capture_output = True ,
670+ text = True ,
671+ timeout = 15 ,
672+ )
673+ return result .returncode == 0
674+ except :
675+ return False
676+
677+
678+ def wifi_configuration_menu ():
679+ clear_screen ()
680+ draw_header ()
681+ print ("\n " * 2 )
682+ print_centered ("WiFi Configuration" , Colors .BRIGHT_WHITE + Colors .BOLD )
683+
684+ if not is_laptop ():
685+ print_centered ("No laptop detected" , Colors .WARNING )
686+ print_centered ("WiFi configuration is only available on laptops" , Colors .DIM )
687+ print ("\n " * 2 )
688+ print_centered ("Press any key to continue..." , Colors .DIM )
689+ get_key ()
690+ return False
691+
692+ print_centered ("Starting iwd service..." , Colors .BRIGHT_CYAN )
693+ if not start_iwd_service ():
694+ print_centered ("Failed to start iwd service" , Colors .FAIL )
695+ print ("\n " * 2 )
696+ print_centered ("Press any key to continue..." , Colors .DIM )
697+ get_key ()
698+ return False
699+
700+ print_centered ("Scanning for networks..." , Colors .BRIGHT_CYAN )
701+ networks = get_wifi_networks ()
702+
703+ if not networks :
704+ print_centered ("No WiFi networks found" , Colors .WARNING )
705+ print ("\n " * 2 )
706+ print_centered ("Press any key to continue..." , Colors .DIM )
707+ get_key ()
708+ return False
709+
710+ wifi_options = networks + ["Rescan" , "Back" ]
711+ choice = selection_menu (
712+ "Select WiFi Network" , wifi_options , "Choose a network to connect to"
713+ )
714+
715+ if choice is None or choice == "Back" :
716+ return False
717+
718+ if choice == "Rescan" :
719+ return wifi_configuration_menu ()
720+
721+ ssid = choice .split (" (" )[0 ]
722+ security = choice .split (" (" )[1 ].rstrip (")" )
723+
724+ password = None
725+ if security == "PSK" :
726+ clear_screen ()
727+ draw_header ()
728+ print ("\n " * 2 )
729+ print_centered (f"Enter password for { ssid } " , Colors .BRIGHT_WHITE + Colors .BOLD )
730+ print_centered ("Password will not be shown as you type" , Colors .DIM )
731+ print ("\n " )
732+ password = input ("Password: " )
733+
734+ clear_screen ()
735+ print_centered ("Connecting to WiFi..." , Colors .BRIGHT_CYAN )
736+ if connect_wifi (ssid , password ):
737+ print_centered (f"Connected to { ssid } successfully!" , Colors .BRIGHT_GREEN )
738+ time .sleep (2 )
739+ return True
740+ else :
741+ print_centered (f"Failed to connect to { ssid } " , Colors .FAIL )
742+ print ("\n " * 2 )
743+ print_centered ("Press any key to continue..." , Colors .DIM )
744+ get_key ()
745+ return False
746+
747+
607748def advanced_settings_menu ():
608749 partition_sizes = DEFAULT_PARTITION_SIZES .copy ()
609750 file_system_type = "ext4"
@@ -707,6 +848,17 @@ def installation_flow(action):
707848 partition_sizes = advanced_settings_result ["partition_sizes" ]
708849 file_system_type = advanced_settings_result ["file_system_type" ]
709850
851+ if is_laptop ():
852+ wifi_choice = selection_menu (
853+ "WiFi Configuration" ,
854+ ["Configure WiFi" , "Skip WiFi" ],
855+ "Set up wireless network connection before installation?" ,
856+ )
857+ if wifi_choice is None :
858+ return
859+ if wifi_choice == "Configure WiFi" :
860+ wifi_configuration_menu ()
861+
710862 disks = get_disks ()
711863 if not disks :
712864 clear_screen ()
0 commit comments