mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'pr854'
This commit is contained in:
commit
4c379640b8
13
src/main.cpp
13
src/main.cpp
|
@ -66,9 +66,12 @@ int main(int argc, char *argv[])
|
|||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("uri", QObject::tr("Tox URI to parse"));
|
||||
parser.addOption(QCommandLineOption("P", QObject::tr("Starts new instance and loads specified profile."), QObject::tr("profile")));
|
||||
parser.process(a);
|
||||
|
||||
Settings::getInstance(); // Build our Settings singleton as soon as QApplication is ready, not before
|
||||
if(parser.isSet("P"))
|
||||
Settings::getInstance().setCurrentProfile(parser.value("P"));
|
||||
|
||||
sodium_init(); // For the auto-updater
|
||||
|
||||
|
@ -110,6 +113,7 @@ int main(int argc, char *argv[])
|
|||
IPC ipc;
|
||||
ipc.registerEventHandler(&toxURIEventHandler);
|
||||
ipc.registerEventHandler(&toxSaveEventHandler);
|
||||
ipc.registerEventHandler(&toxActivateEventHandler);
|
||||
|
||||
if (parser.positionalArguments().size() > 0)
|
||||
{
|
||||
|
@ -152,9 +156,16 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if(!ipc.isCurrentOwner() && !parser.isSet("P"))
|
||||
{
|
||||
time_t event = ipc.postEvent("$activate");
|
||||
ipc.waitUntilProcessed(event);
|
||||
if (!ipc.isCurrentOwner())
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// Run
|
||||
Widget* w = Widget::getInstance();
|
||||
Widget* w = Widget::getInstance();
|
||||
int errorcode = a.exec();
|
||||
|
||||
delete w;
|
||||
|
|
|
@ -51,6 +51,14 @@
|
|||
#include <QTranslator>
|
||||
#include <tox/tox.h>
|
||||
|
||||
void toxActivateEventHandler(const QByteArray& data)
|
||||
{
|
||||
if(data != "$activate")
|
||||
return;
|
||||
Widget::getInstance()->show();
|
||||
Widget::getInstance()->activateWindow();
|
||||
}
|
||||
|
||||
Widget *Widget::instance{nullptr};
|
||||
|
||||
Widget::Widget(QWidget *parent)
|
||||
|
@ -561,7 +569,10 @@ void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason)
|
|||
switch (reason) {
|
||||
case QSystemTrayIcon::Trigger:
|
||||
if(this->isHidden() == true)
|
||||
{
|
||||
this->show();
|
||||
this->activateWindow();
|
||||
}
|
||||
else
|
||||
this->hide();
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
|
|
|
@ -168,4 +168,6 @@ private:
|
|||
QTranslator* translator;
|
||||
};
|
||||
|
||||
void toxActivateEventHandler(const QByteArray& data);
|
||||
|
||||
#endif // WIDGET_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user