From 61e56023d42dcb92ae0742ea973dca307a2a6c6f Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 2 Feb 2025 12:47:27 +0100 Subject: [PATCH] refactor(electron-forge/deb): make desktop.ejs easier to read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in theory we could use variables in ejs, but unfortunately electron uses lodash template to create the file, which itself DOES NOT like any let/const/var assignments – wasted a bit of time finding this out, before coming up with this solution --- bin/electron-forge/desktop.ejs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/bin/electron-forge/desktop.ejs b/bin/electron-forge/desktop.ejs index f803f37b2..32430cd2a 100644 --- a/bin/electron-forge/desktop.ejs +++ b/bin/electron-forge/desktop.ejs @@ -1,12 +1,17 @@ [Desktop Entry] -<% if (productName) { %>Name=<%= productName %> -<% } %><% if (description) { %>Comment=<%= description %> -<% } %><% if (genericName) { %>GenericName=<%= genericName %> -<% } %><% if (name) { %>Exec=<%= name %> %U -Icon=<%= name %> -<% } %>Type=Application -StartupNotify=true -<% if (productName) { %>StartupWMClass=<%= productName %> -<% } if (categories && categories.length) { %>Categories=<%= categories.join(';') %>; -<% } %><% if (mimeType && mimeType.length) { %>MimeType=<%= mimeType.join(';') %>; -<% } %> \ No newline at end of file +<%= +Object.entries({ + "Name": productName, + "Comment": description, + "GenericName": genericName, + "Exec": name ? `${name} %U` : undefined, + "Icon": name, + "Type": "Application", + "StartupNotify": "true", + "StartupWMClass": productName, + "Categories": categories?.length ? `${categories.join(";")};` : undefined, + "MimeType": mimeType?.length ? `${mimeType.join(";")};` : undefined +}) +.map(line => line[1] ? line.join("=") : undefined) +.filter(line => !!line) +.join("\n")%> \ No newline at end of file