Skip to content

Commit c3eab4b

Browse files
committed
fix: Placeholder linux icon in the taskbar
This will publish the main class in the package.json file, which is used by the linux installer to set the StartupWMClass property of the desktop file on linux. This is used to set the icon on the status bar, as reported in #273
1 parent a74e89d commit c3eab4b

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

cli/src/main/java/ca/weblite/jdeploy/publishing/BasePublishDriver.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import java.io.File;
1616
import java.io.IOException;
1717
import java.io.UnsupportedEncodingException;
18+
import java.util.jar.Attributes;
19+
import java.util.jar.JarFile;
20+
import java.util.jar.Manifest;
1821

1922
@Singleton
2023
public class BasePublishDriver implements PublishDriverInterface {
@@ -94,6 +97,28 @@ public void prepare(
9497
checksums.put("installsplash.png", MD5.getMD5Checksum(installSplash));
9598
}
9699

100+
// Extract main class from JAR manifest and add to jdeploy object
101+
// This will be used for the Linux StartupWMClass desktop entry
102+
if (!jdeployObj.has("mainClass") && jdeployObj.has("jar")) {
103+
try {
104+
File mainJarFile = new File(publishJdeployBundleDir, new File(jdeployObj.getString("jar")).getName());
105+
if (mainJarFile.exists()) {
106+
try (JarFile jarFile = new JarFile(mainJarFile)) {
107+
Manifest manifest = jarFile.getManifest();
108+
if (manifest != null) {
109+
String mainClass = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
110+
if (mainClass != null && !mainClass.isEmpty()) {
111+
jdeployObj.put("mainClass", mainClass);
112+
}
113+
}
114+
}
115+
}
116+
} catch (Exception e) {
117+
// Log but don't fail - main class is optional for Linux desktop entry
118+
System.err.println("Warning: Could not extract main class from JAR manifest: " + e.getMessage());
119+
}
120+
}
121+
97122
FileUtils.writeStringToFile(new File(context.getPublishDir(),"package.json"), packageJSON.toString(), "UTF-8");
98123

99124
if (context.packagingContext.isPackageSigningEnabled()) {

installer/src/main/java/ca/weblite/jdeploy/installer/Main.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,15 @@ private void install() throws IOException {
804804
}
805805

806806
private void writeLinuxDesktopFile(File dest, String appTitle, File appIcon, File launcher) throws IOException {
807+
// Derive StartupWMClass from the npm package name
808+
String wmClass = npmPackageVersion().getMainClass();
809+
if (wmClass != null) {
810+
wmClass = wmClass.replaceAll("\\.", "-");
811+
}
812+
if (npmPackageVersion().getWmClassName() != null) {
813+
wmClass = npmPackageVersion().getWmClassName();
814+
}
815+
807816
String contents = "[Desktop Entry]\n" +
808817
"Version=1.0\n" +
809818
"Type=Application\n" +
@@ -813,6 +822,11 @@ private void writeLinuxDesktopFile(File dest, String appTitle, File appIcon, Fil
813822
"Comment=Launch {{APP_TITLE}}\n" +
814823
"Terminal=false\n";
815824

825+
// Add StartupWMClass if we have a valid value
826+
if (wmClass != null && !wmClass.isEmpty()) {
827+
contents += "StartupWMClass=" + wmClass + "\n";
828+
}
829+
816830
if (appInfo().hasDocumentTypes() || appInfo().hasUrlSchemes()) {
817831
StringBuilder mimetypes = new StringBuilder();
818832
if (appInfo().hasDocumentTypes()) {

installer/src/main/java/ca/weblite/jdeploy/installer/npm/NPMPackage.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public String getName() {
1818
return packageInfo.getString("name");
1919
}
2020

21-
22-
2321
private static boolean isPrerelease(String version) {
2422
if (!version.contains("-")) return false;
2523
String lcVersion = version.toLowerCase();
@@ -135,7 +133,4 @@ public NPMPackageVersion getLatestVersion(boolean prerelease, String semVer) {
135133
}
136134
return new NPMPackageVersion(this, versionNumber, packageInfo.getJSONObject("versions").getJSONObject(versionNumber));
137135
}
138-
139-
140-
141136
}

installer/src/main/java/ca/weblite/jdeploy/installer/npm/NPMPackageVersion.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,18 @@ public String getInstallerTheme() {
100100
public Map<PermissionRequest, String> getPermissionRequests() {
101101
return new PermissionRequestService().getPermissionRequests(packageJson);
102102
}
103+
104+
public String getMainClass() {
105+
if (jdeploy().has("mainClass")) {
106+
return jdeploy().getString("mainClass");
107+
}
108+
return null;
109+
}
110+
111+
public String getWmClassName() {
112+
if (jdeploy().has("linux") && jdeploy().getJSONObject("linux").has("wmClassName")) {
113+
return jdeploy().getJSONObject("linux").getString("wmClassName");
114+
}
115+
return null;
116+
}
103117
}

0 commit comments

Comments
 (0)