Skip to content

Commit 38bbe9f

Browse files
committed
Linux: overhaul desktop files
Make the menu entry start the updater rather than daemon. This necessitated splitting the desktop file into two; the other is a hidden entry which directly runs `daemon -connect` for the protocol handler. Update the desktop files to specification version 1.5. Use %u (single link) rather than %U (multple links) for the protocol handler. Add GPU preference key (although I doubt whether it will be effective). Use the commands xdg-mime and update-desktop-database to register the unv:// protocol handler. This combination is what worked for me on Debian GNOME3.
1 parent 6e595d7 commit 38bbe9f

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

qml.qrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<file>resources/header.png</file>
1818
<file>resources/logo.png</file>
1919
<file>resources/tyrant.png</file>
20-
<file>resources/unvanquished.desktop</file>
20+
<file>resources/net.unvanquished.Unvanquished.desktop</file>
21+
<file>resources/net.unvanquished.UnvanquishedProtocolHandler.desktop</file>
2122
<file>resources/disconnected_posts.json</file>
2223
</qresource>
2324
</RCC>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[Desktop Entry]
2-
Version=1.0
2+
Version=1.5
33
Name=Unvanquished
44
Comment=FPS/RTS Game - Aliens vs. Humans
55
Icon=unvanquished
66
Terminal=false
77
Type=Application
8-
Exec=%1/daemon -connect %U
8+
Exec="%1/updater"
99
Categories=Game;ActionGame;StrategyGame;
10-
MimeType=x-scheme-handler/unv
10+
# Probably doesn't work since the updater is initially launched, not daemon
11+
PrefersNonDefaultGPU=true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Desktop Entry]
2+
Version=1.5
3+
Name=Unvanquished (protocol handler)
4+
NoDisplay=true
5+
Terminal=false
6+
Type=Application
7+
Exec="%1/daemon" -connect %u
8+
MimeType=x-scheme-handler/unv
9+
# Unclear if this will work when Breakpad is enabled
10+
PrefersNonDefaultGPU=true

unix.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,36 @@ bool install()
7474
{
7575
// Set up menu and protocol handler
7676
Settings settings;
77-
QFile desktopFile(":resources/unvanquished.desktop");
78-
if (!desktopFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
79-
return false;
80-
}
81-
QString desktopStr = QString(desktopFile.readAll().data())
82-
.arg(settings.installPath());
83-
QFile outputFile(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/unvanquished.desktop");
84-
if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
85-
desktopFile.close();
86-
return false;
77+
QString desktopDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
78+
QFile::remove(desktopDir + "/unvanquished.desktop"); // updater v0.0.5 and before
79+
for (QString desktopFileName :
80+
{QString("net.unvanquished.Unvanquished.desktop"),
81+
QString("net.unvanquished.UnvanquishedProtocolHandler.desktop")}) {
82+
QFile desktopFile(":resources/" + desktopFileName);
83+
if (!desktopFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
84+
qDebug() << "missing resource" << desktopFileName;
85+
return false;
86+
}
87+
QString desktopStr = QString(desktopFile.readAll().data())
88+
.arg(settings.installPath());
89+
QFile outputFile(desktopDir + "/" + desktopFileName);
90+
if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
91+
qDebug() << "error opening" << desktopFileName;
92+
return false;
93+
}
94+
if (outputFile.write(desktopStr.toUtf8().constData(), desktopStr.size())
95+
!= desktopStr.size()) {
96+
qDebug() << "error writing" << desktopFileName;
97+
return false;
98+
}
8799
}
88-
outputFile.write(desktopStr.toUtf8().constData(), desktopStr.size());
89-
outputFile.close();
100+
int ret = QProcess::execute("xdg-mime",
101+
{QString("default"),
102+
desktopDir + "/net.unvanquished.UnvanquishedProtocolHandler.desktop",
103+
QString("x-scheme-handler/unv")});
104+
qDebug() << "xdg-mime returned" << ret;
105+
ret = QProcess::execute("update-desktop-database", {desktopDir});
106+
qDebug() << "update-desktop-database returned" << ret;
90107

91108
// install icon
92109
QString iconDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/icons/hicolor/128x128/apps/";

0 commit comments

Comments
 (0)