Skip to content

Commit

Permalink
Linux: overhaul desktop files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slipher committed Jan 17, 2021
1 parent 6e595d7 commit 38bbe9f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
3 changes: 2 additions & 1 deletion qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<file>resources/header.png</file>
<file>resources/logo.png</file>
<file>resources/tyrant.png</file>
<file>resources/unvanquished.desktop</file>
<file>resources/net.unvanquished.Unvanquished.desktop</file>
<file>resources/net.unvanquished.UnvanquishedProtocolHandler.desktop</file>
<file>resources/disconnected_posts.json</file>
</qresource>
</RCC>
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[Desktop Entry]
Version=1.0
Version=1.5
Name=Unvanquished
Comment=FPS/RTS Game - Aliens vs. Humans
Icon=unvanquished
Terminal=false
Type=Application
Exec=%1/daemon -connect %U
Exec="%1/updater"
Categories=Game;ActionGame;StrategyGame;
MimeType=x-scheme-handler/unv
# Probably doesn't work since the updater is initially launched, not daemon
PrefersNonDefaultGPU=true
10 changes: 10 additions & 0 deletions resources/net.unvanquished.UnvanquishedProtocolHandler.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Version=1.5
Name=Unvanquished (protocol handler)
NoDisplay=true
Terminal=false
Type=Application
Exec="%1/daemon" -connect %u
MimeType=x-scheme-handler/unv
# Unclear if this will work when Breakpad is enabled
PrefersNonDefaultGPU=true
41 changes: 29 additions & 12 deletions unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,36 @@ bool install()
{
// Set up menu and protocol handler
Settings settings;
QFile desktopFile(":resources/unvanquished.desktop");
if (!desktopFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
return false;
}
QString desktopStr = QString(desktopFile.readAll().data())
.arg(settings.installPath());
QFile outputFile(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/unvanquished.desktop");
if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
desktopFile.close();
return false;
QString desktopDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
QFile::remove(desktopDir + "/unvanquished.desktop"); // updater v0.0.5 and before
for (QString desktopFileName :
{QString("net.unvanquished.Unvanquished.desktop"),
QString("net.unvanquished.UnvanquishedProtocolHandler.desktop")}) {
QFile desktopFile(":resources/" + desktopFileName);
if (!desktopFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "missing resource" << desktopFileName;
return false;
}
QString desktopStr = QString(desktopFile.readAll().data())
.arg(settings.installPath());
QFile outputFile(desktopDir + "/" + desktopFileName);
if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
qDebug() << "error opening" << desktopFileName;
return false;
}
if (outputFile.write(desktopStr.toUtf8().constData(), desktopStr.size())
!= desktopStr.size()) {
qDebug() << "error writing" << desktopFileName;
return false;
}
}
outputFile.write(desktopStr.toUtf8().constData(), desktopStr.size());
outputFile.close();
int ret = QProcess::execute("xdg-mime",
{QString("default"),
desktopDir + "/net.unvanquished.UnvanquishedProtocolHandler.desktop",
QString("x-scheme-handler/unv")});
qDebug() << "xdg-mime returned" << ret;
ret = QProcess::execute("update-desktop-database", {desktopDir});
qDebug() << "update-desktop-database returned" << ret;

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

0 comments on commit 38bbe9f

Please sign in to comment.