|
| 1 | +--- |
| 2 | +title: Flathub |
| 3 | +sidebar: |
| 4 | + order: 1 |
| 5 | +--- |
| 6 | + |
| 7 | +import { Tabs, TabItem, Card } from '@astrojs/starlight/components'; |
| 8 | + |
| 9 | +<Tabs> |
| 10 | + <TabItem label="Open Source"> |
| 11 | +1. Get your required tools. |
| 12 | +```sh |
| 13 | +git submodule add https://github.com/flatpak/flatpak-builder-tools.git |
| 14 | +cd flatpak-builder-tools/node/flatpak_node_generator |
| 15 | +pipx install . # Change this to your prefered installation method |
| 16 | +``` |
| 17 | +2. Generate your sources |
| 18 | +<Tabs> |
| 19 | +<TabItem label="Yarn"> |
| 20 | +```sh |
| 21 | +# Generate your Node Sources |
| 22 | +flatpak-node-generator --no-requests-cache -o node-sources.json yarn /path/to/your/lock/file/yarn.lock |
| 23 | + |
| 24 | +# Generate your cargo sources |
| 25 | +python3 flatpak-builder-tools/cargo/flatpak-cargo-generator.py -o cargo-sources.json src-tauri/Cargo.lock |
| 26 | +``` |
| 27 | +</TabItem> |
| 28 | +<TabItem label="NPM"> |
| 29 | +```sh |
| 30 | +# Generate your Node Sources |
| 31 | +flatpak-node-generator --no-requests-cache -o node-sources.json npm /path/to/your/lock/file/package-lock.json |
| 32 | + |
| 33 | +# Generate your cargo sources |
| 34 | +python3 flatpak-builder-tools/cargo/flatpak-cargo-generator.py -o cargo-sources.json src-tauri/Cargo.lock |
| 35 | +``` |
| 36 | +</TabItem> |
| 37 | +</Tabs> |
| 38 | +3. Create your metainfo |
| 39 | +Make sure to replace the relevant fields. |
| 40 | +```xml |
| 41 | +<?xml version="1.0" encoding="UTF-8"?> |
| 42 | +<component type="desktop-application"> |
| 43 | + <id>org.your.id</id> |
| 44 | + <launchable type="desktop-id">org.your.id.desktop</launchable> |
| 45 | + <name>Your Apps Name</name> |
| 46 | + <developer id="io.github.roseblume.rosemusic"> |
| 47 | + <name>Your Name</name> |
| 48 | + </developer> |
| 49 | + <content_rating type="oars-1.1"> |
| 50 | + </content_rating> |
| 51 | + <keywords> |
| 52 | + <keyword>Keyword1</keyword> |
| 53 | + <keyword>Keyword2</keyword> |
| 54 | + </keywords> |
| 55 | + <branding> |
| 56 | + <color type="primary" scheme_preference="light">#00ffff</color> |
| 57 | + <color type="primary" scheme_preference="dark">#0c9aff</color> |
| 58 | + </branding> |
| 59 | + <recommends> |
| 60 | + <display_length compare="ge">360</display_length> |
| 61 | + </recommends> |
| 62 | + <summary>Your Summary</summary> |
| 63 | + |
| 64 | + <metadata_license>MIT</metadata_license> |
| 65 | + <project_license>MIT</project_license> |
| 66 | + <url type="homepage">https://github.com/Your-Username/Your-Repo</url> |
| 67 | + |
| 68 | + <supports> |
| 69 | + <control>pointing</control> |
| 70 | + <control>keyboard</control> |
| 71 | + <control>touch</control> |
| 72 | + </supports> |
| 73 | + |
| 74 | + <description> |
| 75 | + <p> |
| 76 | + Your Description |
| 77 | + </p> |
| 78 | + </description> |
| 79 | + <screenshots> |
| 80 | + <screenshot type="default"> |
| 81 | + <image>https://site.com/your-image.png</image> |
| 82 | + <caption>Your Caption</caption> |
| 83 | + </screenshot> |
| 84 | + </screenshots> |
| 85 | + <releases> |
| 86 | + <release version="1.0.0" date="2024-11-02" > |
| 87 | + <description> |
| 88 | + <ul> |
| 89 | + <li>Updated UI</li> |
| 90 | + <li>Added Electronic Genre</li> |
| 91 | + </ul> |
| 92 | + </description> |
| 93 | + </release> |
| 94 | + </releases> |
| 95 | + <update_contact>your-email@place.com</update_contact> |
| 96 | +</component> |
| 97 | +``` |
| 98 | +Your metadata is recommended to be included into your debian bundle although it is not required. This can be done by adjusting your bundle configuration like so. |
| 99 | +```json |
| 100 | +"linux": { |
| 101 | + "deb": { |
| 102 | + "files": { |
| 103 | + "/usr/share/metainfo/org.your.id.metainfo.xml": "relative/path/from/your/tauri.conf.json/to/your/org.your.id.metainfo.xml" |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +``` |
| 108 | +4. Create your manifest |
| 109 | +```yaml |
| 110 | +id: org.your.id |
| 111 | + |
| 112 | +runtime: org.gnome.Platform |
| 113 | +runtime-version: '47' |
| 114 | +sdk: org.gnome.Sdk |
| 115 | + |
| 116 | +command: tauri-app |
| 117 | +finish-args: |
| 118 | + - --socket=wayland # Permission needed to show the window |
| 119 | + - --socket=fallback-x11 # Permission needed to show the window |
| 120 | + - --device=dri # OpenGL, not necessary for all projects |
| 121 | + - --share=ipc |
| 122 | +sdk-extensions: |
| 123 | + - org.freedesktop.Sdk.Extension.node20 |
| 124 | + - org.freedesktop.Sdk.Extension.rust-stable |
| 125 | +build-options: |
| 126 | + append-path: /usr/lib/sdk/node20/bin:/usr/lib/sdk/rust-stable/bin |
| 127 | + |
| 128 | +modules: |
| 129 | + - name: your-command |
| 130 | + buildsystem: simple |
| 131 | + env: |
| 132 | + HOME: /run/build/your-module |
| 133 | + CARGO_HOME: /run/build/your-module/src-tauri |
| 134 | + XDG_CACHE_HOME: /run/build/your-module/flatpak-node/cache |
| 135 | + yarn_config_offline: 'true' |
| 136 | + yarn_config_cache: /run/build/your-module/flatpak-node/yarn-cache |
| 137 | + sources: |
| 138 | + - type: git |
| 139 | + url: https://github.com/Your-Github-Username/Your-Git-Repo.git |
| 140 | + tag: v1.2.2 |
| 141 | + - cargo-sources.json |
| 142 | + - node-sources.json |
| 143 | + build-commands: |
| 144 | + - echo -e 'yarn-offline-mirror "/run/build/your-module/flatpak-node/yarn-mirror"\nyarn-offline-mirror-pruning true' > /run/build/your-module/.yarnrc |
| 145 | + - mkdir -p src-tauri/.cargo && echo -e '[source.crates-io]\nreplace-with = "vendored-sources"\n\n[source.vendored-sources]\ndirectory = "/run/build/your-module/cargo/vendor"' > src-tauri/.cargo/config.toml |
| 146 | + - yarn install --offline --immutable --immutable-cache --inline-builds |
| 147 | + - yarn run tauri build -- -b deb |
| 148 | + - ar -x src-tauri/target/release/bundle/deb/*.deb |
| 149 | + - tar -xf src-tauri/target/release/bundle/deb/your-app/data.tar.gz |
| 150 | + - install -Dm755 src-tauri/target/release/bundle/deb/your-app/data/usr/bin/your-command /app/bin/your-command |
| 151 | + - install -Dm644 src-tauri/target/release/bundle/deb/your-app/data/usr/share/applications/your-app.desktop /app/share/applications/org.your.id.desktop |
| 152 | + - install -Dm644 src-tauri/target/release/bundle/deb/your-app/data/usr/share/icons/hicolor/128x128/apps/your-app.png /app/share/icons/hicolor/128x128/apps/your-app.png |
| 153 | + - install -Dm644 src-tauri/target/release/bundle/deb/your-app/data/usr/share/icons/hicolor/32x32/apps/your-app.png /app/share/icons/hicolor/32x32/apps/your-app.png |
| 154 | + - install -Dm644 src-tauri/target/release/bundle/deb/your-app/data/usr/share/icons/hicolor/256x256@2/apps/your-app.png /app/share/icons/hicolor/512x512/apps/your-app.png |
| 155 | + - install -Dm644 src-tauri/target/release/bundle/deb/your-app/data/usr/share/icons/hicolor/scalable/apps/your-app.svg /app/share/icons/hicolor/scalable/apps/your-app.svg |
| 156 | + |
| 157 | + - install -Dm644 src-tauri/target/release/bundle/deb/your-app/data/usr/share/metainfo/org.your.id /app/share/metainfo/org.your.id |
| 158 | +``` |
| 159 | +## Submitting To Flathub |
| 160 | +**_1. Fork The [Flathub Repository](https://github.com/flathub/flathub/fork)_** |
| 161 | +
|
| 162 | +**_2. Clone the Fork_** |
| 163 | +
|
| 164 | +```shell |
| 165 | +git clone --branch=new-pr git@github.com:your_github_username/flathub.git |
| 166 | +``` |
| 167 | + |
| 168 | +**_3. Enter the repository_** |
| 169 | + |
| 170 | +```shell |
| 171 | +cd flathub |
| 172 | +``` |
| 173 | + |
| 174 | +**_4. Create a new branch_** |
| 175 | + |
| 176 | +```shell |
| 177 | +git checkout -b your_app_name |
| 178 | +``` |
| 179 | + |
| 180 | +**_5. Open a pull request against the `new-pr` branch on github_** |
| 181 | + |
| 182 | +**_6. Your app will now enter the review process in which you may be asked to make changes to your project._** |
| 183 | + </TabItem> |
| 184 | + <TabItem label="Closed Source"> |
| 185 | +For detailed information on how Flatpak works, you can read [Building your first Flatpak](https://docs.flatpak.org/en/latest/first-build.html) |
| 186 | + |
| 187 | +This guide assumes you want to distribute your Flatpak via [Flathub](https://flathub.org/), the most commonly used platform for Flatpak distribution. If you plan on using other platforms, please consult their documentation instead. |
| 188 | + |
| 189 | +## Prerequisites |
| 190 | + |
| 191 | +To test your app inside the Flatpak runtime you can build the Flatpak locally first before uploading your app to Flathub. This can also be helpful if you want to quickly share development builds. |
| 192 | + |
| 193 | +**1. Install `flatpak` and `flatpak-builder`** |
| 194 | + |
| 195 | +To build Flatpaks locally you need the `flatpak` and `flatpak-builder` tools. For example on Ubuntu you can run this command: |
| 196 | + |
| 197 | +<Tabs syncKey="distro"> |
| 198 | + <TabItem label="Debian"> |
| 199 | + |
| 200 | +```sh |
| 201 | +sudo apt install flatpak flatpak-builder |
| 202 | +``` |
| 203 | + |
| 204 | + </TabItem> |
| 205 | + <TabItem label="Arch"> |
| 206 | + |
| 207 | +```sh |
| 208 | +sudo pacman -S --needed flatpak flatpak-builder |
| 209 | +``` |
| 210 | + |
| 211 | + </TabItem> |
| 212 | + <TabItem label="Fedora"> |
| 213 | + |
| 214 | +```sh |
| 215 | +sudo dnf install flatpak flatpak-builder |
| 216 | +``` |
| 217 | + |
| 218 | + </TabItem> |
| 219 | + <TabItem label="Gentoo"> |
| 220 | + |
| 221 | +```sh |
| 222 | +sudo emerge --ask \ |
| 223 | +sys-apps/flatpak \ |
| 224 | +dev-util/flatpak-builder |
| 225 | +``` |
| 226 | + |
| 227 | + </TabItem> |
| 228 | +</Tabs> |
| 229 | + |
| 230 | +**2. Install the Flatpak Runtime** |
| 231 | + |
| 232 | +```shell |
| 233 | +flatpak install flathub org.gnome.Platform//46 org.gnome.Sdk//46 |
| 234 | +``` |
| 235 | + |
| 236 | +**3. [Build the .deb of your tauri-app](https://deploy-preview-2279--tauri-v2.netlify.app/reference/config/#bundleconfig)** |
| 237 | + |
| 238 | +**4. Create the manifest** |
| 239 | + |
| 240 | +```yaml |
| 241 | +id: org.your.id |
| 242 | + |
| 243 | +runtime: org.gnome.Platform |
| 244 | +runtime-version: '47' |
| 245 | +sdk: org.gnome.Sdk |
| 246 | + |
| 247 | +command: tauri-app |
| 248 | +finish-args: |
| 249 | + - --socket=wayland # Permission needed to show the window |
| 250 | + - --socket=fallback-x11 # Permission needed to show the window |
| 251 | + - --device=dri # OpenGL, not necessary for all projects |
| 252 | + - --share=ipc |
| 253 | + |
| 254 | +modules: |
| 255 | + - name: binary |
| 256 | + buildsystem: simple |
| 257 | + sources: |
| 258 | + - type: file |
| 259 | + url: https://github.com/your_username/your_repository/releases/download/v1.0.1/yourapp_1.0.1_amd64.deb |
| 260 | + sha256: 08305b5521e2cf0622e084f2b8f7f31f8a989fc7f407a7050fa3649facd61469 # This is required if you are using a remote source |
| 261 | + only-arches: [x86_64] #This source is only used on x86_64 Computers |
| 262 | + # This path points to the binary file which was created in the .deb bundle. |
| 263 | + # Tauri also creates a folder which corresponds to the content of the unpacked .deb. |
| 264 | + build-commands: |
| 265 | + - ar -x *.deb |
| 266 | + - tar -xf data.tar.gz |
| 267 | + - 'install -Dm755 usr/bin/tauri-app /app/bin/tauri-app' |
| 268 | + - install -Dm644 usr/share/applications/yourapp.desktop /app/share/applications/org.your.id.desktop |
| 269 | + - install -Dm644 usr/share/icons/hicolor/128x128/apps/yourapp.png /app/share/icons/hicolor/128x128/apps/org.your.id.png |
| 270 | + - install -Dm644 usr/share/icons/hicolor/32x32/apps/yourapp.png /app/share/icons/hicolor/32x32/apps/org.your.id.png |
| 271 | + - install -Dm644 usr/share/icons/hicolor/256x256@2/apps/yourapp.png /app/share/icons/hicolor/256x256@2/apps/org.your.id.png |
| 272 | + - install -Dm644 org.your.id.metainfo.xml /app/share/metainfo/org.your.id.rosary.metainfo.xml |
| 273 | +``` |
| 274 | +
|
| 275 | +The Gnome 46 runtime includes all dependencies of the standard Tauri app with their correct versions. |
| 276 | +
|
| 277 | +**5. Install, and Test the app** |
| 278 | +
|
| 279 | +```shell |
| 280 | + |
| 281 | +# Install the flatpak |
| 282 | +flatpak -y --user install <local repo name> <your flatpak id> |
| 283 | + |
| 284 | +# Run it |
| 285 | +flatpak run <your flatpak id> |
| 286 | + |
| 287 | +# Update it |
| 288 | +flatpak -y --user update <your flatpak id> |
| 289 | +``` |
| 290 | + |
| 291 | +## Adding additional libraries |
| 292 | + |
| 293 | +If your final binary requires more libraries than the default tauri app, you need to add them in your flatpak manifest. |
| 294 | +There are two ways to do this. For fast local development, it may work to simply include the already built library file (`.so`) from your local system. |
| 295 | +However, this is not recommended for the final build of the flatpak, as your local library file is not built for the flatpak runtime environment. |
| 296 | +This can introduce various bugs that can be very hard to find. |
| 297 | +Therefore, it is recommended to build the library your program depends on from source inside the flatpak as a build step. |
| 298 | + |
| 299 | +## Submitting to flathub |
| 300 | + |
| 301 | +**_1. Fork The [Flathub Repository](https://github.com/flathub/flathub/fork)_** |
| 302 | + |
| 303 | +**_2. Clone the Fork_** |
| 304 | + |
| 305 | +```shell |
| 306 | +git clone --branch=new-pr git@github.com:your_github_username/flathub.git |
| 307 | +``` |
| 308 | + |
| 309 | +**_3. Enter the repository_** |
| 310 | + |
| 311 | +```shell |
| 312 | +cd flathub |
| 313 | +``` |
| 314 | + |
| 315 | +**_4. Create a new branch_** |
| 316 | + |
| 317 | +```shell |
| 318 | +git checkout -b your_app_name |
| 319 | +``` |
| 320 | + |
| 321 | +**_5. Add your apps manifest to the branch. Commit your changes, and then push them._** |
| 322 | + |
| 323 | +**_6. Open a pull request against the `new-pr` branch on github_** |
| 324 | + |
| 325 | +**_7. Your app will now enter the review process in which you may be asked to make changes to your project._** |
| 326 | + |
| 327 | +When your pull request is approved then you will receive an invitation to edit your apps repository. From here on you can update your app continuously. |
| 328 | + |
| 329 | +You can read more about this [in the flatpak documentation](https://docs.flatpak.org/en/latest/dependencies.html#bundling) |
| 330 | + </TabItem> |
| 331 | +</Tabs> |
0 commit comments