Bug 1914807: Prevent duplicate Dock icons when restarting applications on macOS. r=mac-reviewers,application-update-reviewers,bradwerth,nalexander
Differential Revision: https://phabricator.services.mozilla.com/D222326
This commit is contained in:
@@ -3025,6 +3025,15 @@ int NS_main(int argc, NS_tchar** argv) {
|
||||
bool isDMGInstall = false;
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
if (argc > 2 && NS_tstrcmp(argv[1], NS_T("--openAppBundle")) == 0) {
|
||||
// We have been asked to open a .app bundle. The path to the .app bundle and
|
||||
// any command line arguments have been passed to us as arguments after
|
||||
// "--openAppBundle", so remove the first two arguments and launch the .app
|
||||
// bundle.
|
||||
LaunchMacApp(argc - 2, (const char**)argv + 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We want to control file permissions explicitly, or else we could end up
|
||||
// corrupting installs for other users on the system. Accordingly, set the
|
||||
// umask to 0 for all file creations below and reset it on exit. See Bug
|
||||
|
||||
@@ -119,6 +119,10 @@ void LaunchMacApp(int aArgc, char** aArgv) {
|
||||
MacAutoreleasePool pool;
|
||||
|
||||
NSString* launchPath = [NSString stringWithUTF8String:aArgv[0]];
|
||||
if (![launchPath hasSuffix:@".app"]) {
|
||||
LaunchChildMac(aArgc, aArgv, 0);
|
||||
return;
|
||||
}
|
||||
NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:aArgc - 1];
|
||||
for (int i = 1; i < aArgc; i++) {
|
||||
[arguments addObject:[NSString stringWithUTF8String:aArgv[i]]];
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "MacApplicationDelegate.h"
|
||||
#include "MacAutoreleasePool.h"
|
||||
#include <cstring>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
@@ -41,6 +42,8 @@ void AddToCommandLine(const char* inArgText) {
|
||||
// Caller has ownership of argv and is responsible for freeing the allocated
|
||||
// memory.
|
||||
void SetupMacCommandLine(int& argc, char**& argv, bool forRestart) {
|
||||
mozilla::MacAutoreleasePool pool;
|
||||
|
||||
sArgs = static_cast<char**>(malloc(kArgsGrowSize * sizeof(char*)));
|
||||
if (!sArgs) {
|
||||
return;
|
||||
@@ -50,6 +53,19 @@ void SetupMacCommandLine(int& argc, char**& argv, bool forRestart) {
|
||||
sArgsUsed = 0;
|
||||
|
||||
NSString* path = [NSString stringWithUTF8String:argv[0]];
|
||||
if (forRestart &&
|
||||
[path hasSuffix:[NSString stringWithUTF8String:MOZ_APP_NAME]]) {
|
||||
// When we restart, we ask the updater binary to restart us instead.
|
||||
// This avoids duplicate Dock icons, by giving this process a chance to
|
||||
// shut down before the new process is launched.
|
||||
// Essentially, we are using the updater as a relauncher process.
|
||||
NSString* updaterPath = [[path stringByDeletingLastPathComponent]
|
||||
stringByAppendingPathComponent:
|
||||
@"updater.app/Contents/MacOS/org.mozilla.updater"];
|
||||
AddToCommandLine(updaterPath.UTF8String);
|
||||
AddToCommandLine("--openAppBundle");
|
||||
}
|
||||
|
||||
// We adjust the path to point to the .app bundle, rather than the executable
|
||||
// itself, to allow for the use of the NSWorkspace API for launching and
|
||||
// relaunching the application. We intentionally exclude the
|
||||
|
||||
Reference in New Issue
Block a user