mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
fix:use a different socketname
This commit is contained in:
parent
62584afee8
commit
ce8f5eeb7f
|
@ -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" );
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue