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

macOS application bundle for qStudio.app is available #102

Open
richb-hanover opened this issue Oct 12, 2024 · 2 comments
Open

macOS application bundle for qStudio.app is available #102

richb-hanover opened this issue Oct 12, 2024 · 2 comments

Comments

@richb-hanover
Copy link
Contributor

richb-hanover commented Oct 12, 2024

Apple has bamboozled us... They make makes it hard to get a signed binary (you actually do have to buy into their entire development environment, and buy - as in pay money - to become a Developer).

But anyone can create a double-clickable macOS application bundle that contains all the bits and pieces required to run qStudio and execute PRQL queries. On first launch, you will have to click through a "unverified developer" warning, but after that, it works great. (Thanks, ChatGPT for removing so many of the mysteries).

The Create qStudio macOS app repo has a main script that assembles the bits and pieces - downloading the specified versions of qStudio and prqlc from their own repo's, then adding and tweaking a few more resources to make the complete bundle.

The script is not dependent on macOS. In fact, my most recent bundle was built on a RPi4 running Ubuntu 24.04. The resulting bundle, when copied back to a Mac, works fine on both Intel and Apple Silicon.

Perhaps this could become part of the qStudio release system so that Mac users can get their own binary that is just double-clickable.

Note: The current build of the macOS bundle is at: https://randomneuronsfiring.com/wp-content/uploads/qStudio.zip

@richb-hanover
Copy link
Contributor Author

@ryanhamilton The qStudio "macOS app" seems to be working well for me. I've reported a couple "infelicities" elsewhere, but I'm pretty happy.

One fussy comment: The macOS bundle displays the qStudio icon in the dock as desired. But when it launches, macOS swaps the logo for the generic Java application icon. Here's a screen shot:

qStudio macOS Dock Icon

I asked Mr. ChatGPT how to substitute the icon, and found this...


Q: How can a java program show a different icon in the macOS dock?

A: To set a custom icon in the macOS Dock for a Java application, you can use the setDockIconImage method from the com.apple.eawt.Application class, which is part of Apple's Java extensions for macOS. Here’s a step-by-step guide:

1. Ensure the Mac-Specific Libraries Are Available

Ensure you are using a JVM that includes Apple's macOS-specific extensions. Modern OpenJDK distributions (like AdoptOpenJDK or Zulu) generally support these extensions on macOS.

2. Set the Dock Icon

You can set the icon using the following code:

import com.apple.eawt.Application;
import javax.swing.ImageIcon;
import java.awt.Image;

public class DockIconExample {
    public static void main(String[] args) {
        // Load the image for the dock icon
        ImageIcon icon = new ImageIcon("path/to/icon.png");
        Image image = icon.getImage();
        
        // Get the Application instance (macOS-specific)
        Application app = Application.getApplication();
        
        // Set the Dock icon
        app.setDockIconImage(image);
    }
}

3. Add the Image to Your Project

Ensure that the icon.png is included in your resources, and the path to it is correct.

4. Package and Run the Application

Make sure the application is run in a macOS environment. This call is a no-op in non-macOS systems, meaning it won’t affect behavior on Windows or Linux.

Notes:

  • com.apple.eawt.Application is available only on macOS, so you should either check the OS at runtime or ensure the code runs only on macOS.
  • For cross-platform compatibility, you can use reflection to load the macOS-specific API dynamically.

This method works well for Java applications that require a custom Dock icon on macOS.

@richb-hanover richb-hanover changed the title Build qStudio.app for macOS macOS application bundle for qStudio.app is available Nov 24, 2024
@richb-hanover
Copy link
Contributor Author

@ryanhamilton I'm beginning to think that it's not necessary to fiddle with the application icon when the app is running. Using the macOS application bundle (above) on macOS 15.1, the icon remains as the stylized "Q". No further work required...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant