diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/main.cpp b/src/main.cpp index 00a57d5..870120e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,6 +84,13 @@ int main(int argc, char **argv) // set this, otherwise the webview becomes black when using a stylesheet app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); + if(app.isPrimary()) + qDebug("app is primary"); + else if(app.isSecondary()) + qDebug("app is secondary"); + else + qDebug("app is something?"); + // translator if(config->exists("browser.locale")) { auto *translator = new QTranslator(&app); @@ -127,28 +134,29 @@ int main(int argc, char **argv) } // set up socket - bool isSingleInstance = app.bindLocalSocket(socket.value()); - if(isSingleInstance) { -#ifdef QT_DEBUG - qDebug("Local socket bound"); -#endif - - QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession); - } + QObject::connect(&app, &Browser::receivedMessage, &app, [&app](quint32 instanceId, QByteArray message) { + auto doc = QJsonDocument::fromJson(message); + app.createSession(doc.object()); + }); - if(session) { + if(app.isPrimary()) { + app.createSession(Session::toJsonObject(profile.value(), urls)); + } 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; } else { qWarning("Could not open session [%s].", qUtf8Printable(sessionJson.fileName())); } - } else - app.sendMessage(Session::toJsonObject(profile.value(), urls)); - - if(isSingleInstance) - return app.exec(); - else + } 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(); } |