mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Starting client activates existing instance if such exists
This commit is contained in:
parent
1ec67cb100
commit
beae534d66
10
src/main.cpp
10
src/main.cpp
|
@ -110,6 +110,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 +153,16 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if(!ipc.isCurrentOwner())
|
||||
{
|
||||
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)
|
||||
|
@ -563,7 +571,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