diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-11 02:20:33 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-18 08:20:08 -0500 |
| commit | 1c4d09d9e13571cf7cd7f1ed502bc069d27ed399 (patch) | |
| tree | 143f37d174316e3aa995d9276e5fbf4adc4876df /src | |
| parent | 16ba428e44e22680ae255d46f5e928a4e6ff591a (diff) | |
comments
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 31 | ||||
| -rw-r--r-- | src/moapplication.h | 20 |
2 files changed, 42 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp index adb33d91..ba808db3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,8 +15,6 @@ using namespace MOBase; thread_local LPTOP_LEVEL_EXCEPTION_FILTER g_prevExceptionFilter = nullptr; thread_local std::terminate_handler g_prevTerminateHandler = nullptr; -int forwardToPrimary(MOMultiProcess& multiProcess, const cl::CommandLine& cl); - int main(int argc, char *argv[]) { MOShared::SetThisThreadName("main"); @@ -30,24 +28,33 @@ int main(int argc, char *argv[]) initLogging(); // must be after logging - TimeThis tt("main()"); + TimeThis tt("main() multiprocess"); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); MOApplication app(argc, argv); + + // check if there's another process running MOMultiProcess multiProcess(cl.multiple()); + if (multiProcess.ephemeral()) { + // this is not the primary process + if (cl.forwardToPrimary(multiProcess)) { + // but there's something on the command line that could be forwarded to + // it, so just exit return 0; - } else { - QMessageBox::information( - nullptr, QObject::tr("Mod Organizer"), - QObject::tr("An instance of Mod Organizer is already running")); } - return 0; + QMessageBox::information( + nullptr, QObject::tr("Mod Organizer"), + QObject::tr("An instance of Mod Organizer is already running")); + + return 1; } + + // check if the command line wants to run something right now if (auto r=cl.runPostMultiProcess(multiProcess)) { return *r; } @@ -55,6 +62,7 @@ int main(int argc, char *argv[]) tt.stop(); + // stuff that's done only once, even if MO restarts in the loop below app.firstTimeSetup(multiProcess); @@ -74,6 +82,8 @@ int main(int argc, char *argv[]) m.overrideProfile(*cl.profile()); } + + // set up plugins, OrganizerCore, etc. { const auto r = app.setup(multiProcess); @@ -88,12 +98,17 @@ int main(int argc, char *argv[]) } } + + // check if the command line wants to run something right now if (auto r=cl.runPostOrganizer(app.core())) { return *r; } + + // run the main window const auto r = app.run(multiProcess); + if (r == RestartExitCode) { // resets things when MO is "restarted" app.resetForRestart(); diff --git a/src/moapplication.h b/src/moapplication.h index 2fe3409b..65180ece 100644 --- a/src/moapplication.h +++ b/src/moapplication.h @@ -40,14 +40,32 @@ class MOApplication : public QApplication public:
MOApplication(int& argc, char** argv);
+ // called from main() only once for stuff that persists across "restarts"
+ //
void firstTimeSetup(MOMultiProcess& multiProcess);
+
+ // called from main() each time MO "restarts", loads settings, plugins,
+ // OrganizerCore and the current instance
+ //
int setup(MOMultiProcess& multiProcess);
+
+ // shows splash, starts an api check, shows the main window and blocks until
+ // MO exits
+ //
int run(MOMultiProcess& multiProcess);
+
+ // called from main() when MO "restarts", must clean up everything so setup()
+ // starts fresh
+ //
void resetForRestart();
+ // undefined if setup() wasn't called
+ //
OrganizerCore& core();
- virtual bool notify(QObject* receiver, QEvent* event);
+ // wraps QApplication::notify() in a catch, reports errors and ignores them
+ //
+ bool notify(QObject* receiver, QEvent* event) override;
public slots:
bool setStyleFile(const QString& style);
|
