mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #2725 from 'r-ku:ipc-cleanup'
This commit is contained in:
commit
26019c20e2
|
@ -186,7 +186,8 @@ bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout/*=-1*/)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
time_t start = time(0);
|
time_t start = time(0);
|
||||||
forever {
|
forever
|
||||||
|
{
|
||||||
result = isEventAccepted(postTime);
|
result = isEventAccepted(postTime);
|
||||||
if (result || (timeout > 0 && difftime(time(0), start) >= timeout))
|
if (result || (timeout > 0 && difftime(time(0), start) >= timeout))
|
||||||
break;
|
break;
|
||||||
|
|
100
src/main.cpp
100
src/main.cpp
|
@ -157,105 +157,85 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
QString profileName;
|
||||||
|
bool autoLogin = Settings::getInstance().getAutoLogin();
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
// Inter-process communication
|
// Inter-process communication
|
||||||
ipc.registerEventHandler("uri", &toxURIEventHandler);
|
ipc.registerEventHandler("uri", &toxURIEventHandler);
|
||||||
ipc.registerEventHandler("save", &toxSaveEventHandler);
|
ipc.registerEventHandler("save", &toxSaveEventHandler);
|
||||||
ipc.registerEventHandler("activate", &toxActivateEventHandler);
|
ipc.registerEventHandler("activate", &toxActivateEventHandler);
|
||||||
|
|
||||||
|
uint32_t ipcDest = 0;
|
||||||
|
QString eventType, firstParam;
|
||||||
if (parser.isSet("p"))
|
if (parser.isSet("p"))
|
||||||
{
|
{
|
||||||
QString profileName = parser.value("p");
|
profileName = parser.value("p");
|
||||||
if (Profile::exists(profileName))
|
if (!Profile::exists(profileName))
|
||||||
{
|
|
||||||
qDebug() << "Setting profile to" << profileName;
|
|
||||||
if (Profile::isEncrypted(profileName))
|
|
||||||
{
|
|
||||||
Settings::getInstance().setCurrentProfile(profileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Profile* profile = Profile::loadProfile(profileName);
|
|
||||||
if (!profile)
|
|
||||||
{
|
|
||||||
qCritical() << "-p profile" << profileName + ".tox" << " couldn't be loaded";
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
Nexus::getInstance().setProfile(profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
qCritical() << "-p profile" << profileName + ".tox" << "doesn't exist";
|
qCritical() << "-p profile" << profileName + ".tox" << "doesn't exist";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
ipcDest = Settings::makeProfileId(profileName);
|
||||||
|
autoLogin = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
profileName = Settings::getInstance().getCurrentProfile();
|
||||||
|
|
||||||
if (parser.positionalArguments().size() > 0)
|
if (parser.positionalArguments().size() == 0)
|
||||||
|
eventType = "activate";
|
||||||
|
else
|
||||||
{
|
{
|
||||||
QString firstParam(parser.positionalArguments()[0]);
|
firstParam = parser.positionalArguments()[0];
|
||||||
// Tox URIs. If there's already another qTox instance running, we ask it to handle the URI and we exit
|
// Tox URIs. If there's already another qTox instance running, we ask it to handle the URI and we exit
|
||||||
// Otherwise we start a new qTox instance and process it ourselves
|
// Otherwise we start a new qTox instance and process it ourselves
|
||||||
if (firstParam.startsWith("tox:"))
|
if (firstParam.startsWith("tox:"))
|
||||||
{
|
eventType = "uri";
|
||||||
if (ipc.isCurrentOwner()) // Don't bother sending an event if we're going to process it ourselves
|
|
||||||
{
|
|
||||||
handleToxURI(firstParam.toUtf8());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
time_t event = ipc.postEvent("uri", firstParam.toUtf8());
|
|
||||||
ipc.waitUntilAccepted(event);
|
|
||||||
// If someone else processed it, we're done here, no need to actually start qTox
|
|
||||||
if (!ipc.isCurrentOwner())
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (firstParam.endsWith(".tox"))
|
else if (firstParam.endsWith(".tox"))
|
||||||
{
|
eventType = "save";
|
||||||
if (ipc.isCurrentOwner()) // Don't bother sending an event if we're going to process it ourselves
|
|
||||||
{
|
|
||||||
handleToxSave(firstParam.toUtf8());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
time_t event = ipc.postEvent("save", firstParam.toUtf8());
|
|
||||||
ipc.waitUntilAccepted(event);
|
|
||||||
// If someone else processed it, we're done here, no need to actually start qTox
|
|
||||||
if (!ipc.isCurrentOwner())
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Invalid argument\n");
|
qCritical() << "Invalid argument";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!ipc.isCurrentOwner() && !parser.isSet("p"))
|
|
||||||
|
if (!ipc.isCurrentOwner())
|
||||||
{
|
{
|
||||||
time_t event = ipc.postEvent("activate");
|
time_t event = ipc.postEvent(eventType, firstParam.toUtf8(), ipcDest);
|
||||||
if (!ipc.waitUntilAccepted(event, 2))
|
// If someone else processed it, we're done here, no need to actually start qTox
|
||||||
|
if (ipc.waitUntilAccepted(event, 2))
|
||||||
{
|
{
|
||||||
|
qDebug() << "Event" << eventType << "was handled by other client.";
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Autologin
|
// Autologin
|
||||||
if (Settings::getInstance().getAutoLogin())
|
if (autoLogin)
|
||||||
{
|
{
|
||||||
QString profileName = Settings::getInstance().getCurrentProfile();
|
if (Profile::exists(profileName))
|
||||||
if (Profile::exists(profileName) && !Profile::isEncrypted(profileName))
|
|
||||||
{
|
{
|
||||||
Profile* profile = Profile::loadProfile(profileName);
|
if (!Profile::isEncrypted(profileName))
|
||||||
if (profile)
|
{
|
||||||
Nexus::getInstance().setProfile(profile);
|
Profile* profile = Profile::loadProfile(profileName);
|
||||||
|
if (profile)
|
||||||
|
Nexus::getInstance().setProfile(profile);
|
||||||
|
}
|
||||||
|
Settings::getInstance().setCurrentProfile(profileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Nexus::getInstance().start();
|
Nexus::getInstance().start();
|
||||||
|
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
// Event was not handled by already running instance therefore we handle it ourselves
|
||||||
|
if (eventType == "uri")
|
||||||
|
handleToxURI(firstParam.toUtf8());
|
||||||
|
else if (eventType == "save")
|
||||||
|
handleToxSave(firstParam.toUtf8());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
int errorcode = a.exec();
|
int errorcode = a.exec();
|
||||||
|
|
||||||
|
|
|
@ -294,12 +294,13 @@ public:
|
||||||
setWidgetData(widget->objectName() + "State", widget->saveState());
|
setWidgetData(widget->objectName() + "State", widget->saveState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t makeProfileId(const QString& profile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings();
|
Settings();
|
||||||
~Settings();
|
~Settings();
|
||||||
Settings(Settings &settings) = delete;
|
Settings(Settings &settings) = delete;
|
||||||
Settings& operator=(const Settings&) = delete;
|
Settings& operator=(const Settings&) = delete;
|
||||||
static uint32_t makeProfileId(const QString& profile);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void savePersonal(QString profileName, QString password);
|
void savePersonal(QString profileName, QString password);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user