fix:use a different socketname

This commit is contained in:
xiaoyifang 2023-05-05 21:38:29 +08:00
parent 62584afee8
commit ce8f5eeb7f
2 changed files with 10 additions and 23 deletions

View file

@ -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" );

View file

@ -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
}