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

add support for macos app bundles / dirs retrieval at runtime #470

Merged
merged 13 commits into from
Mar 10, 2023

Conversation

flxzt
Copy link
Owner

@flxzt flxzt commented Jan 24, 2023

This add some configuration to make app bundles in macos work. addresses #41

@dehesselle
Copy link

Hi @flxzt ,
I've picked up work on the app again. For some reason I've had mixed results with this branch which I cannot really explain/reproduce, so before getting too deep into it, can I ask you to rebase this on current master?

One thing is already clear though: I forgot that there is one more change necessary. This needs to be made dynamic as well:

let resource = gio::Resource::load(Path::new(config::RESOURCES_FILE))

The resources file (resources.gresource) needs to be loaded from a location relative to the application binary as well. Since we're already setting XDG_DATA_DIRS, you can use that, e.g. XDG_DATA_DIRS/rnote/resources.gresource.
I am aware that this suggestion is risky as XDG_DATA_DIRS is supposed to contain a list of directories, but since that is something we control at this point (i.e. a list with one element), it would be safe. (Alternatively you'd have to iterate through the list of directories and try everyone of them to locate the resources.gresource file.)

@flxzt flxzt force-pushed the macos-app-bundle-prep branch from 787f251 to b2a09ab Compare March 8, 2023 21:10
rnote-ui/src/main.rs Outdated Show resolved Hide resolved
rnote-ui/src/main.rs Outdated Show resolved Hide resolved
@flxzt flxzt force-pushed the macos-app-bundle-prep branch from ce4a1ef to 06749a0 Compare March 9, 2023 07:21
@flxzt flxzt force-pushed the macos-app-bundle-prep branch from 4f41281 to 4f20b6a Compare March 9, 2023 07:33
@flxzt
Copy link
Owner Author

flxzt commented Mar 9, 2023

to address your other comment, I refactored to retrieve all the relevant directories at runtime. Is it valid that the <dirname of main_executable>/../Resources/lib path can be considered the library directory in an app bundle?

@dehesselle
Copy link

Is it valid that the <dirname of main_executable>/../Resources/lib path can be considered the library directory in an app bundle?

Yes, that is correct. As packager I have some influence over where I put stuff (since this is not a native app built by Xcode), but this is quite common.

This is what the application bundle looks like:

Rnote.app
└── Contents
    ├── MacOS
    └── Resources
        ├── lib
        │   ├── gdk-pixbuf-2.0
        │   ├── girepository-1.0
        │   └── gtk-4.0
        └── share
            ├── gir-1.0
            ├── glib-2.0
            ├── gtk-4.0
            ├── locale
            └── rnote

@flxzt
Copy link
Owner Author

flxzt commented Mar 9, 2023

okay, the mentioned issues should be solved now.

What will the result be of your efforts, a script that can be executed on macos to create the bundle?

@dehesselle
Copy link

Great, I'll test it again later today.

The result will be this: https://gitlab.com/dehesselle/rnote_macos
(Still work in progress, see https://gitlab.com/dehesselle/zim_macos for a polished example.)

I'm using GitLab as I have CI infrastructure there (and GitHub's CI is sadly rather unstable for me).

@dehesselle
Copy link

dehesselle commented Mar 9, 2023

Almost there. Location of the main binary in this case is /Users/Shared/work/Rnote.app/Contents/MacOS/Rnote. This is the output I'm getting (I have added two println!() statements for data_dir and lib_dir):

data_dir=/../Resources/share
lib_dir=/../Resources/lib

(Rnote:51502): GLib-GIO-CRITICAL **: 23:23:31.465: g_settings_schema_source_lookup: assertion 'source != NULL' failed

(Rnote:51502): GLib-GIO-CRITICAL **: 23:23:31.465: g_settings_schema_source_lookup: assertion 'source != NULL' failed
thread 'main' panicked at 'Could not load gresource file: Error { domain: g-file-error-quark, code: 4, message: "Failed to open file “/../Resources/share/rnote/resources.gresource”: open() failed: No such file or directory" }', rnote-ui/src/app/mod.rs:155:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@flxzt
Copy link
Owner Author

flxzt commented Mar 10, 2023

argh, missed to remove those slashes while doing the refactoring. The executable dir name doesn't appear in your print output, but it is apparently lost when joining with the (invalid) absolute path (see here ) so I expect that it appears again with the fixed path.

@flxzt flxzt changed the title add setup_macos_env() for macos app bundles add support for macos app bundles / dirs retrieval at runtime Mar 10, 2023
update windows instructions
@flxzt flxzt marked this pull request as ready for review March 10, 2023 10:36
@dehesselle
Copy link

Sorry you have to check this once more, now it wants to open

MacOS/../Resources/share/rnote/resources.gresource

This needs to be the full canonical path.

@flxzt
Copy link
Owner Author

flxzt commented Mar 10, 2023

Okay.

@dehesselle
Copy link

dehesselle commented Mar 10, 2023

Apologies for the confusion, the intention was to "think like coreutils", e.g.

dirname /whatever/path/to/some/random/binary

To clarify: we need absolute paths for data_dir and lib_dir, derived from the location of the main executable.

@flxzt
Copy link
Owner Author

flxzt commented Mar 10, 2023

no worries, I read it wrong in the sense of "folder name" .

Okay, now it should give /Users/Shared/work/Rnote.app/Contents/MacOS/../Resources/lib and share respectively

Edit: I tweaked the icon some time ago, would be great if it would be updated for the bundle :)

@dehesselle
Copy link

Awesome, Rnote works now out of the box as macOS app! 🎉

I'll have to do some more polishing on my end, but you can basically merge this to master and with 0.5.17 (or whatever comes next) you have a macOS app.

One more thing though, which is either for me to figure out or it might be related to what we've been doing here: can you tell me from where the logo in the about screen is supposed to come from?
image

@flxzt
Copy link
Owner Author

flxzt commented Mar 10, 2023

Thanks a lot for doing this!

I want to mention and link to it in the README & on the website, do you have any suggestions for that / a formulation for macos users how to install / use it? Is it possible to have a permalink to the latest release?

can you tell me from where the logo in the about screen is supposed to come from?

That should be the icon which gets installed to <data dir>/icons/hicolor/scalable/apps/com.github.flxzt.rnote.svg

@flxzt flxzt merged commit 41c0aaf into main Mar 10, 2023
@flxzt flxzt deleted the macos-app-bundle-prep branch March 10, 2023 14:40
@dehesselle
Copy link

You can link to the latest release by using

https://gitlab.com/dehesselle/rnote_macos/-/releases/permalink/latest

This doesn't work yet since I haven't created a release yet. I can create a release this weekend if you are good to go on 0.5.17.

I'll put everything that people need to know in the readme, so for that you can link to the GitLab repo (see zim_macos as example).

You can add it to your readme/website as you see fit. My first guess is to add it to "Installation" below Flathub? "Rnote is available for macOS here:".

@dehesselle
Copy link

@flxzt final addendum: first release is live!

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

Successfully merging this pull request may close these issues.

2 participants