diff options
-rw-r--r-- | src/main.cpp | 40 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 3 |
2 files changed, 21 insertions, 22 deletions
diff --git a/src/main.cpp b/src/main.cpp index d7bcee0..405210f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char **argv) } // command line arguments - bool ignoreSecondary = config->exists("no-remote"); + bool isStandalone = config->exists("no-remote"); auto arguments = config->value<std::vector<std::string>>("args"); auto session = config->value<QString>("browser.session"); auto profile = config->value<QString>("profile.default"); @@ -138,34 +138,32 @@ int main(int argc, char **argv) } } - // - if(!ignoreSecondary) { + // if app is primary, create new sessions from received messages + if(app.isPrimary() && !isStandalone) { QObject::connect(&app, &Browser::receivedMessage, &app, [&app](quint32 instanceId, QByteArray message) { auto doc = QJsonDocument::fromJson(message); app.createSession(doc.object()); }); } - if(app.isPrimary()) { - app.createSession(Session::toJsonObject(profile.value(), urls)); - } else if(ignoreSecondary) { - // app is not primary (= secondary), and --ignore-secondary is set - return -1; - } else if(session) { - QFile sessionJson(session.value()); - if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { - app.sendMessage(sessionJson.readAll()); - sessionJson.close(); - qDebug("session data sent"); - return EXIT_SUCCESS; + { + QJsonObject sessionData; + if(session) { + QFile sessionJson(session.value()); + if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { + sessionData = QJsonDocument::fromJson(sessionJson.readAll()).object(); + sessionJson.close(); + } + } else { + sessionData = Session::toJsonObject(profile.value(), urls); + } + + if(app.isPrimary() || isStandalone) { + app.createSession(sessionData); } else { - qWarning("Could not open session [%s].", qUtf8Printable(sessionJson.fileName())); + // app is secondary and not standalone + return app.sendMessage(QJsonDocument(sessionData).toJson()); } - } else { - auto message = Session::toJsonObject(profile.value(), urls); - qDebug("sending message: %s", app.sendMessage(QJsonDocument(message).toJson()) ? "okay" : "failed"); - qDebug("message>>>\n%s", qUtf8Printable(QJsonDocument(message).toJson())); - return EXIT_SUCCESS; } return app.exec(); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 7f9cdcc..ccc5f1e 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -129,7 +129,8 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa QFile json(filename); if(json.open(QIODevice::ReadOnly | QIODevice::Text)) { auto *browser = qobject_cast<Browser *>(qApp); - browser->sendMessage(json.readAll()); + auto doc = QJsonDocument::fromJson(json.readAll()); + browser->createSession(doc.object()); json.close(); } }); |