mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-29 05:10:20 +02:00
Shorten LocalPeer socket names
On most systems supporting Unix sockets, the maximum length of a socket name is quite low (e.g. on macOS 104 characters and on Linux 108). If the name is too long, the sockets will not work and thus sending messages to a running instance of the launcher will not work. Signed-off-by: Kenneth Chew <79120643+kthchew@users.noreply.github.com>
This commit is contained in:
parent
a8e5e8dcfc
commit
7d4034cfa5
@ -375,19 +375,20 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
|||||||
m_peerInstance = new LocalPeer(this, appID);
|
m_peerInstance = new LocalPeer(this, appID);
|
||||||
connect(m_peerInstance, &LocalPeer::messageReceived, this, &Application::messageReceived);
|
connect(m_peerInstance, &LocalPeer::messageReceived, this, &Application::messageReceived);
|
||||||
if (m_peerInstance->isClient()) {
|
if (m_peerInstance->isClient()) {
|
||||||
|
bool sentMessage = false;
|
||||||
int timeout = 2000;
|
int timeout = 2000;
|
||||||
|
|
||||||
if (m_instanceIdToLaunch.isEmpty()) {
|
if (m_instanceIdToLaunch.isEmpty()) {
|
||||||
ApplicationMessage activate;
|
ApplicationMessage activate;
|
||||||
activate.command = "activate";
|
activate.command = "activate";
|
||||||
m_peerInstance->sendMessage(activate.serialize(), timeout);
|
sentMessage = m_peerInstance->sendMessage(activate.serialize(), timeout);
|
||||||
|
|
||||||
if (!m_urlsToImport.isEmpty()) {
|
if (!m_urlsToImport.isEmpty()) {
|
||||||
for (auto url : m_urlsToImport) {
|
for (auto url : m_urlsToImport) {
|
||||||
ApplicationMessage import;
|
ApplicationMessage import;
|
||||||
import.command = "import";
|
import.command = "import";
|
||||||
import.args.insert("url", url.toString());
|
import.args.insert("url", url.toString());
|
||||||
m_peerInstance->sendMessage(import.serialize(), timeout);
|
sentMessage = m_peerInstance->sendMessage(import.serialize(), timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -407,10 +408,16 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
|||||||
launch.args["offline_enabled"] = "true";
|
launch.args["offline_enabled"] = "true";
|
||||||
launch.args["offline_name"] = m_offlineName;
|
launch.args["offline_name"] = m_offlineName;
|
||||||
}
|
}
|
||||||
m_peerInstance->sendMessage(launch.serialize(), timeout);
|
sentMessage = m_peerInstance->sendMessage(launch.serialize(), timeout);
|
||||||
|
}
|
||||||
|
if (sentMessage) {
|
||||||
|
m_status = Application::Succeeded;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Unable to redirect command to already running instance\n";
|
||||||
|
// C function not Qt function - event loop not started yet
|
||||||
|
::exit(1);
|
||||||
}
|
}
|
||||||
m_status = Application::Succeeded;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ ApplicationId ApplicationId::fromTraditionalApp()
|
|||||||
prefix.truncate(6);
|
prefix.truncate(6);
|
||||||
QByteArray idc = protoId.toUtf8();
|
QByteArray idc = protoId.toUtf8();
|
||||||
quint16 idNum = qChecksum(idc.constData(), idc.size());
|
quint16 idNum = qChecksum(idc.constData(), idc.size());
|
||||||
auto socketName = QLatin1String("qtsingleapp-") + prefix + QLatin1Char('-') + QString::number(idNum, 16);
|
auto socketName = QLatin1String("pl") + prefix + QLatin1Char('-') + QString::number(idNum, 16).left(12);
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
if (!pProcessIdToSessionId) {
|
if (!pProcessIdToSessionId) {
|
||||||
QLibrary lib("kernel32");
|
QLibrary lib("kernel32");
|
||||||
@ -98,12 +98,12 @@ ApplicationId ApplicationId::fromPathAndVersion(const QString& dataPath, const Q
|
|||||||
QCryptographicHash shasum(QCryptographicHash::Algorithm::Sha1);
|
QCryptographicHash shasum(QCryptographicHash::Algorithm::Sha1);
|
||||||
QString result = dataPath + QLatin1Char('-') + version;
|
QString result = dataPath + QLatin1Char('-') + version;
|
||||||
shasum.addData(result.toUtf8());
|
shasum.addData(result.toUtf8());
|
||||||
return ApplicationId(QLatin1String("qtsingleapp-") + QString::fromLatin1(shasum.result().toHex()));
|
return ApplicationId(QLatin1String("pl") + QString::fromLatin1(shasum.result().toHex()).left(12));
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationId ApplicationId::fromCustomId(const QString& id)
|
ApplicationId ApplicationId::fromCustomId(const QString& id)
|
||||||
{
|
{
|
||||||
return ApplicationId(QLatin1String("qtsingleapp-") + id);
|
return ApplicationId(QLatin1String("pl") + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationId ApplicationId::fromRawString(const QString& id)
|
ApplicationId ApplicationId::fromRawString(const QString& id)
|
||||||
@ -139,7 +139,7 @@ bool LocalPeer::isClient()
|
|||||||
#if defined(Q_OS_UNIX)
|
#if defined(Q_OS_UNIX)
|
||||||
// ### Workaround
|
// ### Workaround
|
||||||
if (!res && server->serverError() == QAbstractSocket::AddressInUseError) {
|
if (!res && server->serverError() == QAbstractSocket::AddressInUseError) {
|
||||||
QFile::remove(QDir::cleanPath(QDir::tempPath()) + QLatin1Char('/') + socketName);
|
QLocalServer::removeServer(socketName);
|
||||||
res = server->listen(socketName);
|
res = server->listen(socketName);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user