diff --git a/src/main.cc b/src/main.cc index c1032002..22d4229d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -252,7 +252,7 @@ int main( int argc, char ** argv ) newArgv[ argc ] = ARG_DISABLE_WEB_SECURITY; newArgv[ argc + 1 ] = nullptr; - QHotkeyApplication app( "GoldenDict", newArgc, newArgv ); + QHotkeyApplication app( "GoldenDict-ng", newArgc, newArgv ); QHotkeyApplication::setApplicationName( "GoldenDict-ng" ); QHotkeyApplication::setOrganizationDomain( "https://github.com/xiaoyifang/goldendict-ng" ); diff --git a/thirdparty/qtsingleapplication/src/qtlocalpeer.cpp b/thirdparty/qtsingleapplication/src/qtlocalpeer.cpp index 8fa9ad1a..1de2290c 100644 --- a/thirdparty/qtsingleapplication/src/qtlocalpeer.cpp +++ b/thirdparty/qtsingleapplication/src/qtlocalpeer.cpp @@ -62,36 +62,22 @@ const char* QtLocalPeer::ack = "ack"; QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) : QObject(parent), id(appId) { - QString prefix = id; if (id.isEmpty()) { - id = QCoreApplication::applicationFilePath(); -#if defined(Q_OS_WIN) - id = id.toLower(); -#endif - prefix = id.section(QLatin1Char('/'), -1); + id = QCoreApplication::applicationName(); } + QString prefix = id; +#if defined( Q_OS_WIN ) + prefix = prefix.toLower(); +#endif + prefix.remove(QRegularExpression("[^a-zA-Z]")); prefix.truncate(6); - QByteArray idc = id.toUtf8(); + QByteArray idc = QDir::home().dirName().toUtf8(); quint16 idNum = qChecksum(idc.constData(), idc.size()); - socketName = QLatin1String("qtsingleapp-") + prefix + socketName = QLatin1String("single-") + prefix + QLatin1Char('-') + QString::number(idNum, 16); -#if defined(Q_OS_WIN) - if (!pProcessIdToSessionId) { - QLibrary lib("kernel32"); - pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); - } - if (pProcessIdToSessionId) { - DWORD sessionId = 0; - pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); - socketName += QLatin1Char('-') + QString::number(sessionId, 16); - } -#else - socketName += QLatin1Char('-') + QString::number(::getuid(), 16); -#endif - server = new QLocalServer(this); QString lockName = QDir(QDir::tempPath()).absolutePath() + QLatin1Char('/') + socketName @@ -194,5 +180,6 @@ void QtLocalPeer::receiveConnection() } QtLocalPeer::~QtLocalPeer() { + server->close(); lockFile->unlock(); // Ensure file unlocked }