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

Feat(build): Bundle native application using Tauri #92

Merged
merged 7 commits into from
Jun 6, 2024

Conversation

jbcpollak
Copy link
Contributor

@jbcpollak jbcpollak commented Jun 5, 2024

This uses Tauri to build a native app. Its based on Rust and having had experience with Electron, this seems way smoother. I picked the beta version (v2) because it is adding support for mobile platforms, although I haven't gotten that far yet. This is another strength because the alternative would be something bonkers like Electron for desktop and Ionic for mobile and then it would be a complete mess.

All in all, I'm pretty shocked at how easy this was.

Pre-Reqs

  • No changes necessary if you just want to keep doing the web-dev stuff
  • For native compilation you need to install a few prerequisites, mostly on Linux some dev-dependencies, MacOS probably nothing, Windows you'll need Rust, Node and the free MS compiler

Notable Changes

  • I had to upgrade the devcontainer from bullseye to bookworm. This is because libwebkit2gtk-4.1-dev is not available in bullseye. Overall this change seems harmless.
  • the base url changed from CADmium to just ./. This is because the binary build couldn't resolve the paths. It doesn't affect the regular web dev environment, if it has implications for hosting I'd suggest changing the hosting, this seems to be the "right" way to setup vite.

Other than that, this is all new functionality, the core code didn't change beyond the above.

Usage

  • pnpm tauri dev - HRM using the vite dev server
  • pnpm tauri build - build the native application and installers (deb, rpm, AppImage, Windows installers, etc)

Testing

Tested

(dev, binary and install)

  • native Windows 11
  • WSL + devcontainer
  • native MacOS

Untested

  • Native Linux

TODO

  • the binary is named cadmium-native, which is set in the Cargo.toml. I don't see how to override that in the Tauri config and I didn't know the implications of changing the package name in the main Cadmium Cargo.toml so I didn't want to touch it. I was thinking of calling that cadmium-core if renaming it is an option.
  • I didn't update the devcontainer with the Linux dev dependencies, I can do that if there's a desire for it.
  • I just noticed the app icons are the Tauri defaults, those could be updated.

@av8ta
Copy link
Collaborator

av8ta commented Jun 5, 2024

image

Awesome!

Do you know if tauri apps can accept input from stdin?

@dzervas
Copy link
Collaborator

dzervas commented Jun 5, 2024

Can we add a build:tauri command to the root package.json?
I imagine we don't want to build tauri by default (same for dev)

EDIT: Sorry just realized that neither build nor dev build tauri, only pnpm tauri build do that

@av8ta
Copy link
Collaborator

av8ta commented Jun 5, 2024

@jbcpollak agree that using the cadmium icons would be good and getting all the dependencies sorted in the devcontainer is a good idea too.

Also, updating readme to suit. I found I had to come here for build instructions, and like @dzervas I was looking for a package.json script to kick it off for me!

Awesome work btw. Works great on my machine :)

@jbcpollak
Copy link
Contributor Author

@dzervas @av8ta - thanks for the feedback, I'll work on those things!

@av8ta
Copy link
Collaborator

av8ta commented Jun 6, 2024

Hey just realised we'll need a solution for the base url as well. We're using github pages atm and pretty happy with it.

@jbcpollak
Copy link
Contributor Author

hum, I'll look into that, been a while since I've used GitHub pages - pretty sure we can figure that out

@jbcpollak
Copy link
Contributor Author

Hey just realised we'll need a solution for the base url as well. We're using github pages atm and pretty happy with it.

@av8ta - so I looked at this for a bit and I think it will be fine. I will try and setup the action to run on my fork and verify first but here's my thinking:

the app URL is https://cadmium-co.github.io/CADmium/, and index.html (and all assets) are deployed to the CADmium/ directory on the server.

Currently index.html has absolute paths like this:

<link rel="apple-touch-icon" sizes="180x180" href="/CADmium/assets/apple-touch-icon-DDWPlyIz.png">

this PR changes the URLs to relative resolution:

<link rel="apple-touch-icon" sizes="180x180" href="./assets/apple-touch-icon-DDWPlyIz.png">

since we still load .../CADmium/index.html relative resolution will be .../CADmium/./<whatever>.

so pretty sure its 👍 , but I'll double check if I can get actions running on my fork

@jbcpollak
Copy link
Contributor Author

Confirmed, you can see it working with relative paths here: https://code.joshpollak.com/CADmium/

@jbcpollak
Copy link
Contributor Author

Also MacOS works fine:

Screenshot 2024-06-05 at 10 43 03 PM

generate icons with `pnpm tauri icon applications/web/public/cadmium_logo_min.svg`

see: https://tauri.app/v1/guides/features/icons/
@jbcpollak
Copy link
Contributor Author

I've added icons and updated the readme.

About the dependencies in the devcontainer - to install the GUI libraries takes a ton of space, and in the interest of making the devcontainer light and accessible, I'm sort of inclined not to install the dependencies. Especially in the on-create.sh where they can't be cached as a Docker layer, but even if they could be, I feel like they are best left out of that environment.

It can be done though, I'm just not sure who and how many people are using the devcontainer and I don't want to be disruptive to them.

Thoughts?

@av8ta
Copy link
Collaborator

av8ta commented Jun 6, 2024

Not a biggie to leave the deps out of devcontainer for now. So long as folks can develop with the devcontainer in the browser that should be fine.

@av8ta av8ta merged commit b49a389 into CADmium-Co:main Jun 6, 2024
2 checks passed
@jbcpollak
Copy link
Contributor Author

🎉

@jbcpollak jbcpollak deleted the feat/tauri branch June 6, 2024 03:41
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.

3 participants