* @brief SingleApplication::sendMessage send a message (from commandline) to an * already running QtPass instance. * @param message * @return */
| 72 | * @return |
| 73 | */ |
| 74 | auto SingleApplication::sendMessage(const QString &message) -> bool { |
| 75 | if (!_isRunning) { |
| 76 | return false; |
| 77 | } |
| 78 | QLocalSocket localSocket(this); |
| 79 | localSocket.connectToServer(_uniqueKey, QIODevice::WriteOnly); |
| 80 | if (!localSocket.waitForConnected(timeout)) { |
| 81 | #ifdef QT_DEBUG |
| 82 | dbg() << localSocket.errorString().toLatin1(); |
| 83 | #endif |
| 84 | return false; |
| 85 | } |
| 86 | QByteArray payload = message.toUtf8(); |
| 87 | if (payload.isEmpty()) { |
| 88 | payload = QByteArray(1, '\0'); |
| 89 | } |
| 90 | localSocket.write(payload); |
| 91 | if (!localSocket.waitForBytesWritten(timeout)) { |
| 92 | #ifdef QT_DEBUG |
| 93 | dbg() << localSocket.errorString().toLatin1(); |
| 94 | #endif |
| 95 | return false; |
| 96 | } |
| 97 | localSocket.disconnectFromServer(); |
| 98 | return true; |
| 99 | } |