@@ -109,57 +109,61 @@ def _close():
109109 if self ._progress_dlg :
110110 self ._progress_dlg .close ()
111111 self ._progress_dlg = None
112+
112113 self ._invoke_gui (_close )
113114
114- def install_packages_linux (self , packages : list [str ]) -> Optional [QProcess ]:
115- pm = self .detect_linux_package_manager ()
116- if not pm :
117- self .msg_error ("Gestionnaire de paquets non détecté." , "Package manager not detected." )
115+ def install_packages (self , packages : list [str ]) -> Optional [QProcess ]:
116+ """
117+ Unified entry point for package installation with GUI feedback.
118+ """
119+ cmd = self .get_install_command (packages )
120+ if not cmd :
121+ self .msg_error (
122+ "Impossible de générer la commande d'installation (Gestionnaire de paquets manquant)." ,
123+ "Cannot generate installation command (Missing package manager)." ,
124+ )
118125 return None
119126
120- pkgs = " " .join (packages )
121- cmd = f"{ pm } install -y { pkgs } "
122-
123- self ._show_progress ("Installation système" , "System installation" , "Installation des dépendances..." , "Installing dependencies..." )
127+ self ._show_progress (
128+ "Installation système" ,
129+ "System installation" ,
130+ "Installation des dépendances..." ,
131+ "Installing dependencies..." ,
132+ )
124133
125134 def _on_output (text : str ):
126135 lines = [l for l in text .strip ().splitlines () if l .strip ()]
127- if lines : self ._update_progress (lines [- 1 ][:100 ])
136+ if lines :
137+ self ._update_progress (lines [- 1 ][:100 ])
128138
129139 def _on_finished (ec , es ):
130140 self ._close_progress ()
131- if ec != 0 : self .msg_error ("L'installation a échoué." , "Installation failed." )
141+ if ec != 0 :
142+ self .msg_error (
143+ "L'installation a échoué." , "Installation failed."
144+ )
132145
133- return self .run_elevated_shell (cmd , on_output = _on_output , on_finished = _on_finished )
146+ # Elevation is required for system packages
147+ proc = self .run_elevated_shell (
148+ cmd , on_output = _on_output , on_finished = _on_finished
149+ )
134150
135- def install_packages_windows (self , packages : list [dict ]) -> Optional [QProcess ]:
136- if not shutil .which ("winget" ):
137- self .msg_error ("winget est requis sur Windows." , "winget is required on Windows." )
138- return None
151+ if proc and self ._progress_dlg :
152+ # Handle cancellation: if user cancels the dialog, kill the process
153+ self ._progress_dlg .canceled .connect (proc .terminate )
139154
140- ids = [pkg .get ("id" ) for pkg in packages if pkg .get ("id" )]
141- if not ids : return None
142-
143- cmd_parts = [f"winget install --id { pid } --silent --accept-source-agreements --accept-package-agreements" for pid in ids ]
144- full_cmd = " && " .join (cmd_parts )
145-
146- self ._show_progress ("Installation Windows" , "Windows installation" , "Préparation de winget..." , "Preparing winget..." )
155+ return proc
147156
148- def _on_output ( text : str ) :
149- lines = [ l for l in text . strip (). splitlines () if l . strip ()]
150- if lines : self ._update_progress ( lines [ - 1 ][: 100 ] )
157+ def install_packages_linux ( self , packages : list [ str ]) -> Optional [ QProcess ] :
158+ # Deprecated: use install_packages
159+ return self .install_packages ( packages )
151160
152- def _on_finished (ec , es ):
153- self ._close_progress ()
154- if ec != 0 : self .msg_error ("L'installation winget a échoué." , "winget installation failed." )
161+ def install_packages_windows (self , packages : list [dict ]) -> Optional [QProcess ]:
162+ # Deprecated: use install_packages
163+ ids = [pkg .get ("id" ) for pkg in packages if pkg .get ("id" )]
164+ return self .install_packages (ids )
155165
156- return self .shell_run (full_cmd , on_output = _on_output , on_finished = _on_finished )
157166
158167def install_system_packages (packages : list [str ], gui ) -> bool :
159168 mgr = SysDependencyUI (gui )
160- if platform .system () == "Linux" :
161- return mgr .install_packages_linux (packages ) is not None
162- elif platform .system () == "Windows" :
163- win_pkgs = [{"id" : p } for p in packages ]
164- return mgr .install_packages_windows (win_pkgs ) is not None
165- return False
169+ return mgr .install_packages (packages ) is not None
0 commit comments