clean up duplicated code in installation of desktop services

pull/7679/head
Jeffrey C. Ollie 2025-06-25 11:09:44 -05:00 committed by Mitchell Hashimoto
parent 9c95ce28ae
commit eb5a488b57
5 changed files with 49 additions and 48 deletions

View File

@ -1,6 +1,6 @@
[Desktop Entry]
Version=1.0
Name=Ghostty@@NAME@@
Name=@@NAME@@
Type=Application
Comment=A terminal emulator
TryExec=@@GHOSTTY@@
@ -9,7 +9,7 @@ Icon=com.mitchellh.ghostty
Categories=System;TerminalEmulator;
Keywords=terminal;tty;pty;
StartupNotify=true
StartupWMClass=com.mitchellh.ghostty@@DEBUG@@
StartupWMClass=@@APPID@@
Terminal=false
Actions=new-window;
X-GNOME-UsesNotifications=true

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>com.mitchellh.ghostty@@DEBUG@@</id>
<launchable type="desktop-id">com.mitchellh.ghostty@@DEBUG@@.desktop</launchable>
<id>@@APPID@@</id>
<launchable type="desktop-id">@@APPID@@.desktop</launchable>
<name>Ghostty</name>
<url type="homepage">https://ghostty.org</url>
<url type="help">https://ghostty.org/docs</url>

View File

@ -1,4 +1,4 @@
[D-BUS Service]
Name=com.mitchellh.ghostty@@DEBUG@@
SystemdService=com.mitchellh.ghostty@@DEBUG@@.service
Name=@@APPID@@
SystemdService=@@APPID@@.service
Exec=@@GHOSTTY@@ --launched-from=dbus

View File

@ -1,7 +1,7 @@
[Unit]
Description=Ghostty@@NAME@@
Description=@@NAME@@
[Service]
Type=dbus
BusName=com.mitchellh.ghostty@@DEBUG@@
BusName=@@APPID@@
ExecStart=@@GHOSTTY@@ --launched-from=systemd

View File

@ -223,20 +223,31 @@ pub fn init(b: *std.Build, cfg: *const Config) !GhosttyResources {
if (cfg.target.result.os.tag == .linux) {
// https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html
const name = b.fmt("Ghostty{s}", .{
switch (cfg.optimize) {
.Debug, .ReleaseSafe => " (Debug)",
.ReleaseFast, .ReleaseSmall => "",
},
});
const app_id = b.fmt("com.mitchellh.ghostty{s}", .{
switch (cfg.optimize) {
.Debug, .ReleaseSafe => "-debug",
.ReleaseFast, .ReleaseSmall => "",
},
});
// Desktop file so that we have an icon and other metadata
try steps.append(
formatService(
b,
cfg,
name,
app_id,
b.path("dist/linux/app.desktop.in"),
b.fmt(
"share/applications/com.mitchellh.ghostty{s}.desktop",
.{
switch (cfg.optimize) {
.Debug, .ReleaseSafe => "-debug",
.ReleaseFast, .ReleaseSmall => "",
},
},
"share/applications/{s}.desktop",
.{app_id},
),
),
);
@ -245,15 +256,12 @@ pub fn init(b: *std.Build, cfg: *const Config) !GhosttyResources {
formatService(
b,
cfg,
name,
app_id,
b.path("dist/linux/dbus.service.in"),
b.fmt(
"share/dbus-1/services/com.mitchellh.ghostty{s}.service",
.{
switch (cfg.optimize) {
.Debug, .ReleaseSafe => "-debug",
.ReleaseFast, .ReleaseSmall => "",
},
},
"share/dbus-1/services/{s}.service",
.{app_id},
),
),
);
@ -263,15 +271,14 @@ pub fn init(b: *std.Build, cfg: *const Config) !GhosttyResources {
formatService(
b,
cfg,
name,
app_id,
b.path("dist/linux/systemd.service.in"),
b.fmt(
"{s}/systemd/user/com.mitchellh.ghostty{s}.service",
"{s}/systemd/user/{s}.service",
.{
if (b.graph.system_package_mode) "lib" else "share",
switch (cfg.optimize) {
.Debug, .ReleaseSafe => "-debug",
.ReleaseFast, .ReleaseSmall => "",
},
app_id,
},
),
),
@ -282,15 +289,12 @@ pub fn init(b: *std.Build, cfg: *const Config) !GhosttyResources {
formatService(
b,
cfg,
name,
app_id,
b.path("dist/linux/com.mitchellh.ghostty.metainfo.xml.in"),
b.fmt(
"share/metainfo/com.mitchellh.ghostty{s}.metainfo.xml",
.{
switch (cfg.optimize) {
.Debug, .ReleaseSafe => "-debug",
.ReleaseFast, .ReleaseSmall => "",
},
},
"share/metainfo/{s}.metainfo.xml",
.{app_id},
),
),
);
@ -364,28 +368,25 @@ pub fn install(self: *const GhosttyResources) void {
for (self.steps) |step| b.getInstallStep().dependOn(step);
}
pub fn formatService(b: *std.Build, cfg: *const Config, src: std.Build.LazyPath, dest: []const u8) *std.Build.Step {
pub fn formatService(
b: *std.Build,
cfg: *const Config,
name: []const u8,
app_id: []const u8,
src: std.Build.LazyPath,
dest: []const u8,
) *std.Build.Step {
var cmd = b.addSystemCommand(&.{"sed"});
cmd.setStdIn(.{ .lazy_path = src });
const output = cmd.captureStdOut();
cmd.addArg(b.fmt(
"-e s!@@NAME@@!{s}!g",
.{
switch (cfg.optimize) {
.Debug, .ReleaseSafe => " (Debug)",
.ReleaseFast, .ReleaseSmall => "",
},
},
.{name},
));
cmd.addArg(b.fmt(
"-e s!@@DEBUG@@!{s}!g",
.{
switch (cfg.optimize) {
.Debug, .ReleaseSafe => "-debug",
.ReleaseFast, .ReleaseSmall => "",
},
},
"-e s!@@APPID@@!{s}!g",
.{app_id},
));
cmd.addArg(b.fmt(
"-e s!@@GHOSTTY@@!{s}/bin/ghostty!g",