From eb5a488b57d4e0528d4fc3724ff1f77a6894ab61 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Wed, 25 Jun 2025 11:09:44 -0500 Subject: [PATCH] clean up duplicated code in installation of desktop services --- dist/linux/app.desktop.in | 4 +- .../com.mitchellh.ghostty.metainfo.xml.in | 4 +- dist/linux/dbus.service.in | 4 +- dist/linux/systemd.service.in | 4 +- src/build/GhosttyResources.zig | 81 ++++++++++--------- 5 files changed, 49 insertions(+), 48 deletions(-) diff --git a/dist/linux/app.desktop.in b/dist/linux/app.desktop.in index 17d7b65e3..aefb5c9cd 100644 --- a/dist/linux/app.desktop.in +++ b/dist/linux/app.desktop.in @@ -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 diff --git a/dist/linux/com.mitchellh.ghostty.metainfo.xml.in b/dist/linux/com.mitchellh.ghostty.metainfo.xml.in index 46b370bb8..97598c215 100644 --- a/dist/linux/com.mitchellh.ghostty.metainfo.xml.in +++ b/dist/linux/com.mitchellh.ghostty.metainfo.xml.in @@ -1,7 +1,7 @@ - com.mitchellh.ghostty@@DEBUG@@ - com.mitchellh.ghostty@@DEBUG@@.desktop + @@APPID@@ + @@APPID@@.desktop Ghostty https://ghostty.org https://ghostty.org/docs diff --git a/dist/linux/dbus.service.in b/dist/linux/dbus.service.in index f9c5ce7a4..a11ab2c13 100644 --- a/dist/linux/dbus.service.in +++ b/dist/linux/dbus.service.in @@ -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 diff --git a/dist/linux/systemd.service.in b/dist/linux/systemd.service.in index 2d1acdaea..ede2174a2 100644 --- a/dist/linux/systemd.service.in +++ b/dist/linux/systemd.service.in @@ -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 diff --git a/src/build/GhosttyResources.zig b/src/build/GhosttyResources.zig index f52c2e810..a62ba0528 100644 --- a/src/build/GhosttyResources.zig +++ b/src/build/GhosttyResources.zig @@ -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",