Launcher: add ‘restart on exit’ option
This commit is contained in:
parent
bdcb30d785
commit
e407ba75ef
5 changed files with 57 additions and 4 deletions
|
@ -556,6 +556,30 @@ void restartTheApp()
|
||||||
qApp->exit(-1);
|
qApp->exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startLaunchOnExit(const std::vector<std::string>& 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()
|
void launcherSetSceneryPaths()
|
||||||
{
|
{
|
||||||
globals->clear_fg_scenery();
|
globals->clear_fg_scenery();
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class SGPath;
|
class SGPath;
|
||||||
|
|
||||||
namespace flightgear
|
namespace flightgear
|
||||||
|
@ -58,6 +61,11 @@ namespace flightgear
|
||||||
*/
|
*/
|
||||||
void restartTheApp();
|
void restartTheApp();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@ brief helper to re-open the launcher once FLightGear exits cleanly
|
||||||
|
*/
|
||||||
|
void startLaunchOnExit(const std::vector<std::string>& originalCommandLine);
|
||||||
|
|
||||||
void launcherSetSceneryPaths();
|
void launcherSetSceneryPaths();
|
||||||
|
|
||||||
bool showSetupRootDialog(bool usingDefaultRoot);
|
bool showSetupRootDialog(bool usingDefaultRoot);
|
||||||
|
|
|
@ -161,6 +161,14 @@ Item {
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
keywords: ["develop", "developer"]
|
keywords: ["develop", "developer"]
|
||||||
setting: "develop"
|
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");
|
if (!showConsoleWin.hidden && showConsoleWin.checked) _config.setArg("console");
|
||||||
_config.setEnableDisableOption("sentry", enableCrashReporting.checked);
|
_config.setEnableDisableOption("sentry", enableCrashReporting.checked);
|
||||||
if (developerMode.checked) _config.setArg("developer");
|
if (developerMode.checked) _config.setArg("developer");
|
||||||
|
if (restartLauncher.checked) _config.setArg("restart-launcher");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -807,8 +807,10 @@ int fgMainInit( int argc, char **argv )
|
||||||
|
|
||||||
fgOSCloseWindow();
|
fgOSCloseWindow();
|
||||||
fgShutdownHome();
|
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();
|
simgear::clearEffectCache();
|
||||||
|
|
||||||
|
@ -821,5 +823,15 @@ int fgMainInit( int argc, char **argv )
|
||||||
// objects (eg, airports, navaids, runways).
|
// objects (eg, airports, navaids, runways).
|
||||||
delete flightgear::NavDataCache::instance();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2001,12 +2001,12 @@ struct OptionDesc {
|
||||||
{"developer", true, OPTION_IGNORE | OPTION_BOOL, "", false, "", nullptr },
|
{"developer", true, OPTION_IGNORE | OPTION_BOOL, "", false, "", nullptr },
|
||||||
{"jsbsim-output-directive-file", true, OPTION_STRING, "/sim/jsbsim/output-directive-file", false, "", nullptr },
|
{"jsbsim-output-directive-file", true, OPTION_STRING, "/sim/jsbsim/output-directive-file", false, "", nullptr },
|
||||||
{"disable-gui", false, OPTION_FUNC, "", false, "", fgOptDisableGUI },
|
{"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},
|
{"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}
|
{nullptr, false, 0, nullptr, false, nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace flightgear
|
namespace flightgear
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue