Restart the application bundle instead of the underlying executable when crashing on macOS (#3268)

On macOS, programs are contained in ".app" application bundles. When chatterino restarts on a crash, it currently just looks for the executable path obtained via QApplication::applicationFilePath() and starts that again, which for macOS is the underlying unix executable inside of the application bundle. Unfortunately, for macOS those 2 are absolutely different, resulting in i.e. a second chatterino icon being added to the dock, due to the OS not recognizing that it is the same application.
This commit is contained in:
LosFarmosCTL
2021-10-02 12:58:28 +02:00
committed by GitHub
parent 9b9fd7d403
commit acc573a8c5
2 changed files with 26 additions and 0 deletions
+25
View File
@@ -28,6 +28,10 @@
# include <QBreakpadHandler.h>
#endif
#ifdef Q_OS_MAC
# include "corefoundation/CFBundle.h"
#endif
namespace chatterino {
namespace {
void installCustomPalette()
@@ -122,8 +126,29 @@ namespace {
std::chrono::steady_clock::now() - signalsInitTime > 30s)
{
QProcess proc;
#ifdef Q_OS_MAC
// On macOS, programs are bundled into ".app" Application bundles,
// when restarting chatterino that bundle should be opened with the "open"
// terminal command instead of directly starting the underlying executable,
// as those are 2 different things for the OS and i.e. do not use
// the same dock icon (resulting in a second chatterino icon on restarting)
CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFStringRef macPath =
CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle);
const char *pathPtr =
CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());
proc.setProgram("open");
proc.setArguments({pathPtr, "--args", "--crash-recovery"});
CFRelease(appUrlRef);
CFRelease(macPath);
#else
proc.setProgram(QApplication::applicationFilePath());
proc.setArguments({"--crash-recovery"});
#endif
proc.startDetached();
}