diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 29cf4f7b7..c92df7e20 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -556,6 +556,30 @@ void restartTheApp() qApp->exit(-1); } +void startLaunchOnExit(const std::vector& originalCommandLine) +{ + QStringList fgArgs; + for (const auto& arg : originalCommandLine) { + fgArgs.append(QString::fromStdString(arg)); + } + + QProcess proc; +#if defined(Q_OS_MAC) + QDir dir(qApp->applicationDirPath()); // returns the 'MacOS' dir + dir.cdUp(); // up to 'contents' dir + dir.cdUp(); // up to .app dir + + QStringList args; + // see 'man open' for details, but '-n' ensures we launch a new instance, + // and we want to pass remaining arguments to us, not open. + args << "-n" << dir.absolutePath() << "--args" << fgArgs; + qDebug() << "args" << args; + proc.startDetached("open", args); +#else + proc.startDetached(qApp->applicationFilePath(), fgArgs); +#endif +} + void launcherSetSceneryPaths() { globals->clear_fg_scenery(); diff --git a/src/GUI/QtLauncher.hxx b/src/GUI/QtLauncher.hxx index 6bb1f0a5d..6c07875d9 100644 --- a/src/GUI/QtLauncher.hxx +++ b/src/GUI/QtLauncher.hxx @@ -20,6 +20,9 @@ #pragma once +#include +#include + class SGPath; namespace flightgear @@ -58,6 +61,11 @@ namespace flightgear */ void restartTheApp(); + /** + @ brief helper to re-open the launcher once FLightGear exits cleanly + */ + void startLaunchOnExit(const std::vector& originalCommandLine); + void launcherSetSceneryPaths(); bool showSetupRootDialog(bool usingDefaultRoot); diff --git a/src/GUI/qml/Settings.qml b/src/GUI/qml/Settings.qml index 6652738d0..8db1ac4ff 100644 --- a/src/GUI/qml/Settings.qml +++ b/src/GUI/qml/Settings.qml @@ -161,6 +161,14 @@ Item { defaultValue: false keywords: ["develop", "developer"] setting: "develop" + }, + + SettingCheckbox { + id: restartLauncher + label: qsTr("Re-open FlightGear on exit") + description: qsTr("Re-open this window when exiting FlightGear, to start another flight immediately.") + keywords: ["restart", "reopen"] + setting: "restart-launcher" } ] @@ -168,6 +176,7 @@ Item { if (!showConsoleWin.hidden && showConsoleWin.checked) _config.setArg("console"); _config.setEnableDisableOption("sentry", enableCrashReporting.checked); if (developerMode.checked) _config.setArg("developer"); + if (restartLauncher.checked) _config.setArg("restart-launcher"); } } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index f739dbc8f..00e8ea8af 100755 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -807,8 +807,10 @@ int fgMainInit( int argc, char **argv ) fgOSCloseWindow(); fgShutdownHome(); - - simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(mln_stopped); + + const bool requestLauncherRestart = fgGetBool("/sim/restart-launcher-on-exit"); + + simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(mln_stopped); simgear::clearEffectCache(); @@ -821,5 +823,15 @@ int fgMainInit( int argc, char **argv ) // objects (eg, airports, navaids, runways). delete flightgear::NavDataCache::instance(); +#if defined(HAVE_QT) + if (requestLauncherRestart) { + string_list originalArgs; + for (int arg = 1; arg < argc; ++arg) { + originalArgs.push_back(argv[arg]); + } + flightgear::addSentryBreadcrumb("Requested to restart launcher", "info"); + flightgear::startLaunchOnExit(originalArgs); + } +#endif return result; } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 6c9165669..52bc2ab70 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -2001,12 +2001,12 @@ struct OptionDesc { {"developer", true, OPTION_IGNORE | OPTION_BOOL, "", false, "", nullptr }, {"jsbsim-output-directive-file", true, OPTION_STRING, "/sim/jsbsim/output-directive-file", false, "", nullptr }, {"disable-gui", false, OPTION_FUNC, "", false, "", fgOptDisableGUI }, - {"graphics-preset", true, OPTION_STRING, "/sim/rendering/preset", false, "", nullptr}, + {"graphics-preset", true, OPTION_STRING, "/sim/rendering/preset", false, "", nullptr}, {"composite-viewer", true, OPTION_INT, "/sim/rendering/composite-viewer-enabled", false, "", nullptr}, + {"restart-launcher", false, OPTION_BOOL, "/sim/restart-launcher-on-exit", true, "", nullptr}, {nullptr, false, 0, nullptr, false, nullptr, nullptr} }; - namespace flightgear {