Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac menu items use class name, instead of program name #127

Open
vewert opened this issue May 24, 2022 · 8 comments
Open

Mac menu items use class name, instead of program name #127

vewert opened this issue May 24, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@vewert
Copy link

vewert commented May 24, 2022

I am creating a .app image for macOS. Everything works fine, but when I run the application, and click on the Mac Menu, the About, and Quit menu items use the main class name, instead of the Application name (see screen shot):

2022-05-24_15-52-04

So the actual menu name show correctly as PWMinder, but the About and Quit using 'MainProgram' instead of 'PWMinder'. Note: the Dock name is also correct.

Below is relevant part of my build script:

jpackage {
        skipInstaller = true
        imageOptions = listOf(
          "--app-version", "${project.version}",
          "--description", description,
          "--copyright", "$copyrightYear $company",
          "--vendor", company,
          "--icon", "${imgDir.absolutePath}/logo.icns",
          "--mac-package-identifier", "ca.ewert.pwMinder",
          "--mac-package-name", project.name,
          "--mac-app-category", macAppCategory,
          "--mac-sign",
          "--mac-package-signing-prefix", macPackageSigningPrefix,
          "--mac-signing-key-user-name", macSigningKeyUserName,
          "--mac-entitlements", macEntitlementsFile.absolutePath,
          "--resource-dir", "${buildResourcesDir.absolutePath}/macBundle/resources",
          "--file-associations", macAssociationsFile.absolutePath
        )
      }

and below is the generated info.plist:

<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
 <dict>
  <key>LSEnvironment</key>
 	<dict>
 		<key>DYLD_FRAMEWORK_PATH</key>
 		<string>../Frameworks:/System/Library/Frameworks:/System/Library/Frameworks/JavaVM.framework/Frameworks</string>
 	</dict>
  <key>LSMinimumSystemVersion</key>
  <string>10.11</string>
  <key>CFBundleDevelopmentRegion</key>
  <string>English</string>
  <key>CFBundleAllowMixedLocalizations</key>
  <true/>
  <key>CFBundleExecutable</key>
  <string>PWMinder</string>
  <key>CFBundleIconFile</key>
  <string>PWMinder.icns</string>
  <key>CFBundleIdentifier</key>
  <string>ca.ewert.pwMinder</string>
  <key>CFBundleInfoDictionaryVersion</key>
  <string>6.0</string>
  <key>CFBundleName</key>
  <string>PWMinder</string>
  <key>CFBundlePackageType</key>
  <string>APPL</string>
  <key>CFBundleShortVersionString</key>
  <string>3.2.2</string>
  <key>CFBundleSignature</key>
  <string>????</string>
  <!-- See https://developer.apple.com/app-store/categories/ for list of AppStore categories -->
  <key>LSApplicationCategoryType</key>
  <string>public.app-category.utilities</string>
  <key>CFBundleVersion</key>
  <string>3.2.2</string>
  <key>NSHumanReadableCopyright</key>
  <string>2022 Ewert Technologies</string>
  <key>CFBundleDocumentTypes</key>
  <array>
 <dict>
  <key>LSItemContentTypes</key>
   <array>
    <string>ca.ewert.pwMinder.pwm</string>
   </array>
  <key>CFBundleTypeName</key>
  <string>PWMinder Vault File</string>

  <key>LSHandlerRank</key>
  <string>Owner</string>

  <key>CFBundleTypeRole</key>
  <string>Editor</string>

  <key>LSIsAppleDefaultForType</key>
  <true/>

  </dict>
  </array>

  <key>UTExportedTypeDeclarations</key>
  <array>
  <dict>
  <key>UTTypeIdentifier</key>
  <string>ca.ewert.pwMinder.pwm</string>

  <key>UTTypeDescription</key>
  <string>PWMinder Vault File</string>

  <key>UTTypeConformsTo</key>
   <array>
    <string>public.data</string>
   </array>

  <key>UTTypeTagSpecification</key>
  <dict>

  <key>public.filename-extension</key>
   <array>
    <string>pwm</string>
   </array>
  <key>public.mime-type</key>
   <array>
    <string>application/x-vnd.PWMinderVaultFile</string>
   </array>
  </dict>
 </dict>
  </array>

  <key>NSHighResolutionCapable</key>
  <string>true</string>
  <key>NSMicrophoneUsageDescription</key>
  <string>The application PWMinder is requesting access to the microphone.</string>
 </dict>
</plist>

I was previously using ant and appbundler, and using that setup I used to be able to the that About and Quit to show correctly, but I'm now trying to upgrade my build tools to using Gradle and JLink/JPackage.

I'm not sure if this is a problem with jpackage or with the plug-in, or if I've configured something incorrectly.

Any help or insight would be appreciated.

@vewert
Copy link
Author

vewert commented Aug 5, 2022

I inadvertently fixed this by adding the following System property:

System.setProperty( "apple.awt.application.name", "PWMinder" );

I'm not sure, however, of the difference between the above System Property and:

com.apple.mrj.application.apple.menu.about.name

which I was already using.

Maybe the first one is newer. Anyway, I'm glad I got this working

@hakanai
Copy link
Collaborator

hakanai commented Jan 15, 2023

Is this ticket still an issue? If not, can you close it? Or is there something we can do to streamline this one?

Really, to me it seems like getting the right application name should be something jpackage does without us having to tell it anything.

@hakanai hakanai added the question Further information is requested label Jan 15, 2023
@vewert
Copy link
Author

vewert commented Jan 16, 2023

Firstly, thank you @hakanai for stepping up, to help with this project.

As for this issue, the problem still exists as described. If I don't include

System.setProperty("apple.awt.application.name", "PWMinder" );

when I run the .app bundle, created by jpackage (using the plugin), the About and Quit Menu Items say "MainProgram". Setting the property does "fix" this, but I'm not sure if that means this issue should be closed or not.

@hakanai
Copy link
Collaborator

hakanai commented Jan 17, 2023

It's gonna be one of 3 possibilities:

  1. jpackage is supposed to be doing it, and isn't, making it their issue
  2. jpackage exposes a proper command-line flag for setting it, and this plugin isn't passing it
  3. jpackage doesn't support a way to set it, and this plugin could possibly set that property automatically.

So from here, I'd have to get on a Mac and play with jpackage a bit to see if I can figure out how it's supposed to happen. It really seems like they should be doing it out of the box, but maybe this plugin isn't setting the application name or something.

Setting the application name should really affect Windows and Linux as well... for Windows you'd want the executable name to match, and probably the metadata inside the executable. Even for Linux, there is some kind of desktop shortcut file which should be named after the application.

What's weird though is, the name is right for the menu itself.

@hakanai hakanai added bug Something isn't working and removed question Further information is requested labels Jan 17, 2023
@hakanai
Copy link
Collaborator

hakanai commented Jan 18, 2023

I've done some testing on macOS, and the findings:

  • For the sample app provided (badass-runtime-example-javafx), which is based on JavaFX:

    • The name of the app is hellofx on the menu
    • The name of the app is hellofx inside the menu as well
    • Attempting to change this name by changing applicationName in the build appears to have no effect (!!)
    • Attempting to change it by changing the "mac-package-name" in the build also appears to have no effect (!!)
    • The names at least match but don't appear to be customisable and appear to come from the raw project name.
  • For a modified app I made in Swing instead:

    • The name of the app is helloswing on the menu
    • The name of the app is Launcher inside the menu
    • Same as before, attempting to change this by correcting the build has no effect
    • Name in the menu still comes from the raw project name, name inside the menu comes from the raw classname.

So the first thing to note is that it behaves differently depending on whether the app is Swing or JavaFX.

Running with --debug to see what jpackage command is actually being run, and I see:

/path/to/jdk/bin/jpackage
--type app-image
--input /path/to/project/build/install/Full app name/lib
--main-jar hellofx.jar
--main-class org.example.hellofx.Launcher
--dest /path/to/project/build/jpackage
--name hellofx
--runtime-image /path/to/project/build/jre
--icon src/main/resources/hellofx.icns

So the custom name specified in applicationName is not being passed to --name in the first place, for some reason. Figure out how to fix that, and it will probably fix everything.

@hakanai
Copy link
Collaborator

hakanai commented Jan 18, 2023

Digging in the code...

  • The value passed to --name comes from jpd.installerNameOrDefault
  • This appears to resolve to JPackageData#getInstallerNameOrDefault
  • That uses this.@installerName ?: project.name

So it looks to me like there are 2 possibilities for the fix:

  1. Modify this code to also look at applicationName
  2. Put some code somewhere to make sure installerName is properly being set from applicationName.
  3. Decide that setting installerName is the developer's responsibility and update the examples to set it.

I don't know which one is the closer to the original intent so I'll let @siordache choose which way to go. Maybe there's some code setting up JPackageData already which I'm unaware of.

@vewert
Copy link
Author

vewert commented Jan 18, 2023

Thanks for your diligent work, especially for finding the difference between JavaFX and Swing. I also, just wanted to confirm, that the application I found this for, is a Swing application, which seems to match with the findings you described.

@hakanai
Copy link
Collaborator

hakanai commented Jan 19, 2023

Looks like I'm somewhat confused as well. It turns out there are two properties to set, both in the jpackage block.

  1. imageName - affects the name of the image directory, the executable, etc. and probably fixes the macOS menu too (haven't tried yet, currently sitting on Windows)
  2. installerName - affects the name given to the installer files

Neither of these fall back to the applicationName, and I think it makes sense for both of them to do so.

That said, the current behaviour matches the docs perfectly. So in that sense at least it was behaving correctly. But, the application plugin's mainClass value is used by this plugin as a default for that, so it makes sense for this corresponding value to be treated similarly.

Currently testing this stuff to see if updates to the code actually work in a real project seems to be difficult because the Gradle versions don't match between all the sample projects and this project - and it looks like the version of Gradle being used by this project isn't new enough for JDK17, which adds to the mess. I'm trying to do something about that but it's Groovy so it's slow going...

hakanai added a commit to hakanai/badass-runtime-plugin that referenced this issue Jan 19, 2023
…allerName.

applicationName is intended to be the display name of the application, so it makes sense for this to be used by default.

Intended to fix beryx#127 but needs testing on macOS to be absolutely certain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants