Commit Graph

67 Commits

Author SHA1 Message Date
Jonas Kvinge
2678b4dcf5 Use new QNativeIpcKey based QSharedMemory constructor with Qt 6.6 and higher
Switch to the new QNativeIpcKey based QSharedMemory constructor with Qt 6.6 and higher, the old constructor will be deprecated.
This also makes the library work again with the upcoming Qt 6.6 release and higher.
However, there are still issues with releasing the existing memory in cases where the application is forcefully quit or crashed.
2023-09-28 18:30:56 +02:00
Itay Grudev
a5cc738641 MIT, but No Machine Learning Allowed 2023-03-24 12:09:12 +02:00
Christoph Cullmann
611e48abbb
Provide API for blocking sendMessage (#154) 2022-04-05 23:46:42 +03:00
Nils Jeisecke
0c458ec8c9 Add simple acknowledge protocol to ensure the server has received all data
The server now acknowledges every received message by sending a \r.

By waiting for the acknowledgement, clients should no longer terminate
too early, causing bytes getting lost in Qt's internal socket handling.

Message handling in the server is simplified because we can now rely
on the readyRead signal being raised for every frame.

This should finally solve #125 and #121.

What remains is to correctly handle data sent using
SingleApplication::sendMessage.
2021-05-31 16:12:32 +02:00
Shatur95
4aeac8fa3e Mark getters as const 2021-01-25 01:36:36 +02:00
Shatur95
7bdb497a83 Pass usedData by const reference 2020-12-21 19:07:36 +02:00
Loren Burkholder
f236032cf9 Allow adding unique userdata to instances 2020-12-16 22:17:24 -05:00
Shatur95
f3de0114f4 Remove extra Q_D
No longer needed as getUsername() is now static.
2020-10-15 23:16:21 +03:00
Shatur95
e17c715faf Fix Clang Tidy warnings
readability-convert-member-functions-to-static
readability-static-accessed-through-instance
readability-make-member-function-const
readability-inconsistent-declaration-parameter-name
2020-10-15 21:41:00 +03:00
Itay Grudev
be013eff5c Mitigated QSharedMemory initialization failures
Mitigated QSharedMemory initialization failures  due to large amount of processes attempting to get hold of the shared memory block at the same time
2020-09-09 02:29:00 +01:00
Itay Grudev
3e83f5ce13 Improved the connectToPrimary() method and fixed issue with instanceStarted() not getting emitted 2020-09-09 02:28:07 +01:00
Itay Grudev
eca5803665 Moved the random sleep functionality to SingleApplicationPrivate 2020-09-09 02:23:42 +01:00
Itay Grudev
fb9c0bd2ef Removed extra qDebug statements 2020-09-09 00:48:55 +01:00
Itay Grudev
e4282f2476 Mitigated possible race condition during app startup 2020-09-09 00:28:02 +01:00
Itay Grudev
81052d9a61 Bug Fix: Fixed situation in which the memory block is left unlocked 2020-09-08 23:15:17 +01:00
Itay Grudev
a136c734c9 Updated code style and added inline documentation to public methods 2020-09-08 23:08:14 +01:00
Shatur95
fcd4fcab21 Fix Clang Tidy warnings 2020-05-17 17:50:27 +03:00
Itay Grudev
15e4bb589e
Update singleapplication.cpp 2020-04-22 00:58:39 +01:00
Leander Schulten
5fff2202b5 Add SingleApplication::currentUser() 2020-03-27 08:00:14 +01:00
Itay Grudev
81cc2719be v3.1.0a Added primaryUser()
Closes #95
2020-03-03 01:24:55 +00:00
Shatur95
724efd7fdd Fix obsolete code warnings 2020-01-05 18:27:24 +02:00
Itay Grudev
117336df79 Fallback for iOS as well 2019-10-13 10:34:28 +03:00
Itay Grudev
5e223a7f74 Disables SingleApplication support on Android. Fixes #52 2019-10-11 16:50:52 +03:00
Jonas Kvinge
1aad265585 Fix return value of sendMessage() (#68) 2019-08-23 23:02:50 +03:00
Patrizio Bekerle
2fac2a3804 fixed a typo (#55) 2018-11-30 16:08:31 +00:00
Itay Grudev
46b2204a3f
Proposed SA changes still containing a race condition (#48) 2018-07-27 04:29:55 +03:00
Francis Giraldeau
f975da90cc Fix sendmessage (#46)
* Fix send message example

If a secondary instance sends a message immediately after connecting, the
message follows the init message. This causes the slotConnectionEstablished to
read and consume the tail of the message and interpret it as the checksum. The
checksum fails and the connection becomes invalid.

To avoid this race, we prefix the init message with its length. This way, we
consume only the data relevant to the init message.

This patch fixes the sending_arguments example.

Signed-off-by: Francis Giraldeau <francis.giraldeau@gmail.com>

* Fix include file case

Signed-off-by: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>
2018-07-27 02:10:14 +03:00
Jedidiah Buck McCready
a956ae47d1 removed c style casts and eliminated all clang warnings, ... (#38)
* removed c style casts and eliminated all clang warnings, fixed instanceId reading from only one byte in deserialization of message, cleaned up serialization code using QDataStream, changed connection type to use quint8 enum rather than char

* renamed SingleAppConnectionType to ConnectionType, added initialization values to all ConnectionType enum cases
2017-12-03 17:04:02 +00:00
Itay Grudev
4f03651072 Primary PID support (#36)
* Added the ability to bring the primary application window to the foreground on Windows systems by adding an option flag. THis option can only be used in Windows development and in applications derived from QApplication with a QMainWindow object.
Because the primary application needs to be instructed to go to the foreground, the option SecondaryNotification must also be set to use this functionality

* Changed the ability to bring the primary application window to the front as discussed in itay-grudev/SingleApplication#31.

Now the process ID of the primary application get stored and is accessible for other instances of the application. It is to the developer to bring the applications windows to the front. For convenience the accompanying readme now contains a paragraph with example of how to do this on Windows systems.

* v3.0.9 Added SingleApplicationPrivate::primaryPid()
2017-10-02 12:17:41 +01:00
BG4444
ca149f4436 bugfix - change QApplication to macro QAPPLICATION_CLASS (#34)
Bug fix - changed QApplication to macro QCoreApplication when invoking QApplication::instance()
2017-08-20 20:30:29 +03:00
Itay Grudev
c2a6faca68 Removed QMutex for thread safe behaviour and support for multiple SingleApplication instances
Problem raised by @retmas in #24
2017-04-23 14:31:32 +03:00
Vitaly Tonkacheyev
eee5d9544b Fixed compilation error: cannot convert wchar_t* to LPSTR {aka char*} (#29) 2017-02-23 13:41:11 +00:00
Evgeny
d561026d83 Remove magic chars from code - use more readable code style (#28) 2017-02-22 13:27:48 +00:00
Itay Grudev
4841681918 Reverted GetUserName API usage on Windows (#25)
* Added back support for getting username on Windows

* Fixed typo in singleapplication.pri

* Compiler specific Advapi32.lib links

* Removed username debug statement
2017-02-02 04:28:00 +00:00
Itay Grudev
cf347c47af Refactored SingleApplicationPrivate destructor.
Deleted the separate cleanUp method as it’s not used from anywhere but
the destructor.
2017-01-30 17:47:01 +00:00
retmas
b0078af7d3 Fix memory leak on SingleApplicationPrivate destruction (#23)
The issue is non critical as if the library is used properly this destructor is not called until the end of the program anyway.
2017-01-30 17:38:16 +00:00
pjwhams
c7b8e20905 Fixed shadow variable warning (#21) 2017-01-24 22:18:55 +00:00
Itay Grudev
6a4d89297b
Removed Windows specific code for getting username
On the absolute path to the home directory is now explicitly used.
2017-01-24 17:25:00 +00:00
Itay Grudev
60d30db837
Refactored slotConnectionEstablished()
The code is now shorter and easier to understand. Fixed an
uninitialised variable warning as reported in #20.
2017-01-24 16:54:53 +00:00
Le Liu
5aa7430f56 Fix crash when username contains Unicode characters on Windows (#17)
*   Fixed bug on Windows with username containing wide characters causing the
    library to crash.
    _Le Liu_
2016-11-27 11:09:42 +00:00
Le Liu
0f821d44f3 Allow data exclusion for the server name hash and Windows fixes (#16)
*   Allows the application path and version to be excluded from the server name
    hash. The following flags were added for this purpose:
      * `SingleApplication::Mode::ExcludeAppVersion`
      * `SingleApplication::Mode::ExcludeAppPath`
*   Allow a non elevated process to connect to a local server created by an
    elevated process run by the same user on Windows
*   Fixes a problem with upper case letters in paths on Windows
2016-11-26 17:40:47 +00:00
Svintsov Dmitry
06f5e17544 fix Windows warning about unused parameter 2016-08-24 16:04:49 +05:00
Svintsov Dmitry
ebcfabc3ae Added missing "QMutex" dependencies 2016-08-22 15:29:14 +05:00
Itay Grudev
5d867d77a5
Fix bug (and compiler error) on Windows - wchar username support 2016-08-18 18:28:57 +01:00
Itay Grudev
4e5c1647cc
SingleApplication v3.0a 2016-08-10 03:41:03 +01:00
Itay Grudev
b459c9247b Fixed signal formatting 2016-07-10 01:11:55 +01:00
Itay Grudev
1db662d0e6 Updated license dates. Explicit license statement in the header and source files 2016-07-04 18:19:48 +01:00
Itay Grudev
fe84b5663e SIGBUSS should be signal 10. Fixed comment 2016-05-14 20:38:15 +01:00
Itay Grudev
5e67bf9751 Code style improvements 2016-05-04 21:05:59 +01:00
Itay Grudev
6fe4403941 Bugfix no showUp notification. Some minor improvements 2016-05-04 20:51:06 +01:00