@@ -129,11 +129,8 @@ export class FirefoxExtensionInstaller {
129129 */
130130 getFirefoxProfiles ( ) {
131131 try {
132- const baseDir = this . getDefaultFirefoxProfilesDir ( ) ;
133132 // Path to the profiles.ini file
134- const profilesIniPath = join ( baseDir , "profiles.ini" ) ;
135-
136- this . log ( "debug" , `Looking for profiles.ini at: ${ profilesIniPath } ` ) ;
133+ const profilesIniPath = join ( this . getDefaultFirefoxProfilesDir ( ) , "profiles.ini" ) ;
137134
138135 if ( ! existsSync ( profilesIniPath ) ) {
139136 this . log ( "error" , `Firefox profiles.ini not found at ${ profilesIniPath } ` ) ;
@@ -154,26 +151,6 @@ export class FirefoxExtensionInstaller {
154151 }
155152 }
156153
157- // Try alternative locations on Linux
158- if ( process . platform === "linux" ) {
159- const homeDir = homedir ( ) ;
160- const altLocations = [
161- join ( homeDir , ".mozilla" , "firefox" , "profiles.ini" ) ,
162- join ( homeDir , "snap" , "firefox" , "common" , ".mozilla" , "firefox" , "profiles.ini" ) ,
163- join ( homeDir , ".var" , "app" , "org.mozilla.firefox" , "data" , "mozilla" , "firefox" , "profiles.ini" ) ,
164- ] ;
165-
166- for ( const altPath of altLocations ) {
167- this . log ( "debug" , `Trying alternative location: ${ altPath } ` ) ;
168- if ( existsSync ( altPath ) ) {
169- this . log ( "info" , `Found profiles.ini at alternative location: ${ altPath } ` ) ;
170- const profilesIni = readFileSync ( altPath , "utf8" ) ;
171- return this . parseProfilesIni ( profilesIni , dirname ( altPath ) ) ;
172- }
173- }
174- }
175-
176- this . log ( "error" , "No profiles.ini found in any location" ) ;
177154 return [ ] ;
178155 }
179156
@@ -278,21 +255,31 @@ export class FirefoxExtensionInstaller {
278255 let command : string ;
279256
280257 if ( process . platform === "win32" ) {
281- command = "tasklist | findstr firefox" ;
258+ // Windows - check for firefox.exe
259+ command = 'tasklist /FI "IMAGENAME eq firefox.exe" /NH | findstr firefox' ;
282260 } else if ( process . platform === "darwin" ) {
283- command = 'pgrep -x "firefox" || pgrep -x "Firefox"' ;
261+ // macOS - check for Firefox.app
262+ command = 'pgrep -lf "Firefox.app/Contents/MacOS/firefox" | head -1' ;
284263 } else {
285- // Linux - check multiple possible process names
286- command = 'pgrep -f "firefox|firefox-bin" || pgrep -x "firefox" || pgrep -x "firefox-esr"' ;
264+ // Linux - check for main firefox process, exclude helper processes
265+ // Use pgrep with full command line to be more accurate
266+ command = 'pgrep -f "^/.*firefox$|^firefox$" | head -1' ;
287267 }
288268
269+ this . log ( "debug" , `Vérification si Firefox est en cours d'exécution: ${ command } ` ) ;
289270 const { stdout } = await execAsync ( command ) ;
290- const isRunning = stdout . trim ( ) . length > 0 ;
291- this . log ( "debug" , `Firefox running check: ${ isRunning ? "running" : "not running" } ` ) ;
292- return isRunning ;
271+
272+ const result = stdout . trim ( ) ;
273+ if ( result . length > 0 ) {
274+ this . log ( "debug" , `Firefox semble être en cours d'exécution: ${ result } ` ) ;
275+ return true ;
276+ }
277+
278+ this . log ( "debug" , "Firefox n'est pas en cours d'exécution" ) ;
279+ return false ;
293280 } catch ( error ) {
294- // Process not found - this is expected when Firefox is not running
295- this . log ( "debug" , "Firefox not running (process not found) " ) ;
281+ // Command failed (exit code != 0) usually means no process found
282+ this . log ( "debug" , "Aucun processus Firefox détecté " ) ;
296283 return false ;
297284 }
298285 }
@@ -668,49 +655,60 @@ export class FirefoxExtensionInstaller {
668655 async uninstallExtension ( extensionId : string ) {
669656 try {
670657 this . log ( "info" , `Début de la désinstallation de l'extension ${ extensionId } ` ) ;
671-
672- // Fermer Firefox avant la désinstallation
658+
659+ // Vérifier si Firefox est en cours d'exécution
673660 const isRunning = await this . isFirefoxRunning ( ) ;
661+
674662 if ( isRunning ) {
675- this . log ( "warn" , "Firefox est en cours d'exécution. Tentative de fermeture..." ) ;
663+ this . log ( "warn" , "Firefox semble être en cours d'exécution. Tentative de fermeture automatique..." ) ;
664+
676665 try {
666+ // Tenter de fermer Firefox
677667 await BrowserController . close ( "firefox" ) ;
668+
678669 // Attendre que Firefox se ferme complètement
670+ this . log ( "debug" , "Attente de 3 secondes pour que Firefox se ferme complètement..." ) ;
679671 await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) ) ;
680-
681- // Vérifier à nouveau
672+
673+ // Vérifier à nouveau si Firefox est fermé
682674 const stillRunning = await this . isFirefoxRunning ( ) ;
675+
683676 if ( stillRunning ) {
684- this . log ( "error" , "Firefox est toujours en cours d'exécution. Veuillez le fermer manuellement." ) ;
685- throw new Error ( "Firefox doit être fermé pour désinstaller l'extension" ) ;
677+ this . log ( "warn" , "Firefox est toujours en cours d'exécution après la tentative de fermeture." ) ;
678+ this . log ( "info" , "Tentative de désinstallation malgré tout..." ) ;
679+ } else {
680+ this . log ( "info" , "Firefox a été fermé avec succès" ) ;
686681 }
687682 } catch ( error ) {
688- this . log ( "error " , `Impossible de fermer Firefox automatiquement: ${ error } ` ) ;
689- throw new Error ( "Veuillez fermer Firefox manuellement avant de désinstaller l'extension ") ;
683+ this . log ( "warn " , `Impossible de fermer Firefox automatiquement: ${ error } ` ) ;
684+ this . log ( "info" , "Tentative de désinstallation malgré tout... ") ;
690685 }
686+ } else {
687+ this . log ( "debug" , "Firefox n'est pas en cours d'exécution, poursuite de la désinstallation" ) ;
691688 }
692689
693690 const profiles = this . getFirefoxProfiles ( ) ;
694-
691+
695692 if ( profiles . length === 0 ) {
696693 throw new Error ( "Aucun profil Firefox trouvé" ) ;
697694 }
698-
699- this . log ( "info" , `Désinstallation de l'extension ${ extensionId } pour ${ profiles . length } profils Firefox...` ) ;
695+
696+ this . log ( "info" , `Désinstallation de l'extension ${ extensionId } pour ${ profiles . length } profil(s) Firefox...` ) ;
700697
701698 let foundAny = false ;
702-
699+ let successCount = 0 ;
700+
703701 for ( const profile of profiles ) {
704702 this . log ( "debug" , `Traitement du profil: ${ profile . name } (${ profile . path } )` ) ;
705-
703+
706704 const profilePath = profile . path ;
707-
705+
708706 // Vérifier que le profil existe
709707 if ( ! existsSync ( profilePath ) ) {
710708 this . log ( "warn" , `Le profil ${ profile . name } n'existe pas à ${ profilePath } ` ) ;
711709 continue ;
712710 }
713-
711+
714712 const extensionsDir = join ( profilePath , "extensions" ) ;
715713 const extensionPath = join ( extensionsDir , `${ extensionId } .xpi` ) ;
716714
@@ -720,10 +718,11 @@ export class FirefoxExtensionInstaller {
720718 try {
721719 rmSync ( extensionPath , { force : true } ) ;
722720 foundAny = true ;
723- this . log ( "info" , `Extension supprimée avec succès de ${ profile . name } ` ) ;
721+ successCount ++ ;
722+ this . log ( "info" , `✓ Extension supprimée avec succès du profil ${ profile . name } ` ) ;
724723 } catch ( error ) {
725- this . log ( "error" , `Impossible de supprimer ${ extensionPath } : ${ error } ` ) ;
726- throw new Error ( `Erreur de permissions: impossible de supprimer ${ extensionPath } . Vérifiez les permissions ou exécutez avec sudo.` ) ;
724+ this . log ( "error" , `✗ Impossible de supprimer ${ extensionPath } : ${ error } ` ) ;
725+ this . log ( "warn" , "Cela peut être dû à des permissions insuffisantes ou à Firefox verrouillant le fichier." ) ;
727726 }
728727 } else {
729728 this . log ( "debug" , `Extension non trouvée dans ${ profile . name } : ${ extensionPath } ` ) ;
@@ -743,7 +742,7 @@ export class FirefoxExtensionInstaller {
743742 if ( extensionsData . addons . length < initialLength ) {
744743 writeFileSync ( extensionsJsonPath , JSON . stringify ( extensionsData , null , 2 ) ) ;
745744 foundAny = true ;
746- this . log ( "info" , `Extension supprimée de extensions.json pour le profil: ${ profile . name } ` ) ;
745+ this . log ( "info" , `✓ Extension supprimée de extensions.json pour le profil: ${ profile . name } ` ) ;
747746 } else {
748747 this . log ( "debug" , `Extension ${ extensionId } non trouvée dans extensions.json` ) ;
749748 }
@@ -758,9 +757,10 @@ export class FirefoxExtensionInstaller {
758757
759758 if ( ! foundAny ) {
760759 this . log ( "warn" , `L'extension ${ extensionId } n'a été trouvée dans aucun profil Firefox` ) ;
761- this . log ( "info" , "Cela peut être normal si l'extension n'était pas installée ou a déjà été désinstallée ." ) ;
760+ this . log ( "info" , "Cela peut être normal si l'extension n'était pas installée." ) ;
762761 } else {
763- this . log ( "info" , "Désinstallation terminée avec succès. Veuillez redémarrer Firefox pour appliquer les changements." ) ;
762+ this . log ( "info" , `✓ Désinstallation terminée avec succès (${ successCount } profil(s) traité(s))` ) ;
763+ this . log ( "info" , "Vous pouvez maintenant rouvrir Firefox." ) ;
764764 }
765765 } catch ( error ) {
766766 this . log ( "error" , `Erreur dans Firefox.uninstallExtension: ${ error } ` ) ;
0 commit comments