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);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
globals->clear_fg_scenery();
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<std::string>& originalCommandLine);
|
||||
|
||||
void launcherSetSceneryPaths();
|
||||
|
||||
bool showSetupRootDialog(bool usingDefaultRoot);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -808,6 +808,8 @@ int fgMainInit( int argc, char **argv )
|
|||
fgOSCloseWindow();
|
||||
fgShutdownHome();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -2003,10 +2003,10 @@ struct OptionDesc {
|
|||
{"disable-gui", false, OPTION_FUNC, "", false, "", fgOptDisableGUI },
|
||||
{"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
|
||||
{
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue