Skip to content

Commit c3de222

Browse files
committed
Init with GTK Rust Template
0 parents  commit c3de222

34 files changed

+1335
-0
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
root = true
2+
[*]
3+
indent_style = space
4+
end_of_line = lf
5+
trim_trailing_whitespace = true
6+
insert_final_newline = true
7+
charset = utf-8
8+
9+
[*.{build,css,doap,scss,ui,xml,xml.in,xml.in.in,yaml,yml}]
10+
indent_size = 2
11+
12+
[*.{json,py,rs}]
13+
indent_size = 4
14+
15+
[*.{c,h,h.in}]
16+
indent_size = 2
17+
max_line_length = 80
18+
19+
[NEWS]
20+
indent_size = 2
21+
max_line_length = 72

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
on:
2+
push:
3+
branches: [main]
4+
pull_request:
5+
6+
name: CI
7+
8+
jobs:
9+
rustfmt:
10+
name: Rustfmt
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
profile: minimal
17+
toolchain: stable
18+
override: true
19+
components: rustfmt
20+
- name: Create blank versions of configured file
21+
run: echo -e "" >> src/config.rs
22+
- name: Run cargo fmt
23+
run: cargo fmt --all -- --check
24+
25+
flatpak:
26+
name: Flatpak
27+
runs-on: ubuntu-latest
28+
container:
29+
image: bilelmoussaoui/flatpak-github-actions:gnome-nightly
30+
options: --privileged
31+
steps:
32+
- uses: actions/checkout@v3
33+
- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v6
34+
with:
35+
bundle: notify.flatpak
36+
manifest-path: build-aux/com.ranfdev.Notify.Devel.json
37+
repository-name: "flathub-beta"
38+
run-tests: true
39+
cache-key: flatpak-builder-${{ github.sha }}

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/target/
2+
/build/
3+
/_build/
4+
/builddir/
5+
/build-aux/app
6+
/build-aux/.flatpak-builder/
7+
/src/config.rs
8+
*.ui.in~
9+
*.ui~
10+
/.flatpak/
11+
/vendor
12+
/.vscode
13+
/subprojects/blueprint-compiler

.gitlab-ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
stages:
2+
- check
3+
- test
4+
5+
flatpak:
6+
image: 'quay.io/gnome_infrastructure/gnome-runtime-images:gnome-43'
7+
stage: test
8+
tags:
9+
- flatpak
10+
variables:
11+
BUNDLE: "notify-nightly.flatpak"
12+
MANIFEST_PATH: "build-aux/com.ranfdev.Notify.Devel.json"
13+
FLATPAK_MODULE: "notify"
14+
APP_ID: "com.ranfdev.Notify.Devel"
15+
RUNTIME_REPO: "https://nightly.gnome.org/gnome-nightly.flatpakrepo"
16+
script:
17+
- flatpak install --user --noninteractive org.freedesktop.Sdk.Extension.llvm14//21.08
18+
- >
19+
xvfb-run -a -s "-screen 0 1024x768x24"
20+
flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse flatpak_app --repo=repo ${BRANCH:+--default-branch=$BRANCH} ${MANIFEST_PATH}
21+
- flatpak build-bundle repo ${BUNDLE} --runtime-repo=${RUNTIME_REPO} ${APP_ID} ${BRANCH}
22+
artifacts:
23+
name: 'Flatpak artifacts'
24+
expose_as: 'Get Flatpak bundle here'
25+
when: 'always'
26+
paths:
27+
- "${BUNDLE}"
28+
- '.flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/meson-logs/meson-log.txt'
29+
- '.flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/meson-logs/testlog.txt'
30+
expire_in: 14 days
31+
32+
# Configure and run rustfmt
33+
# Exits and builds fails if on bad format
34+
rustfmt:
35+
image: "rust:slim"
36+
script:
37+
- rustup component add rustfmt
38+
# Create blank versions of our configured files
39+
# so rustfmt does not yell about non-existent files or completely empty files
40+
- echo -e "" >> src/config.rs
41+
- rustc -Vv && cargo -Vv
42+
- cargo fmt --version
43+
- cargo fmt --all -- --color=always --check

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "notify"
3+
version = "0.1.0"
4+
authors = ["ranfdev <[email protected]>"]
5+
edition = "2021"
6+
7+
[profile.release]
8+
lto = true
9+
10+
[dependencies]
11+
gettext-rs = { version = "0.7", features = ["gettext-system"] }
12+
gtk = { version = "0.6", package = "gtk4", features = ["v4_8"] }
13+
once_cell = "1.14"
14+
tracing = "0.1.37"
15+
tracing-subscriber = "0.3"
16+
adw = { version = "0.4", package = "libadwaita", features = ["v1_4"] }

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# GTK + Libadwaita + Blueprint + Rust + Meson + Flatpak = <3
2+
3+
A boilerplate template to get started with GTK, Libadwaita, Blueprint, Rust, Meson, Flatpak made for GNOME.
4+
5+
![Main window](data/resources/screenshots/screenshot1.png "Main window")
6+
7+
## What does it contains?
8+
9+
- A simple window with a headerbar
10+
- Bunch of useful files that you SHOULD ship with your application on Linux:
11+
- Metainfo: describe your application for the different application stores out there;
12+
- Desktop: the application launcher;
13+
- Icons: This repo contains three icons, a normal, a nightly & monochromatic icon (symbolic) per the GNOME HIG, exported using [App Icon Preview](https://flathub.org/apps/details/org.gnome.design.AppIconPreview).
14+
- Flatpak Manifest for nightly builds
15+
- Dual installation support
16+
- Uses Meson for building the application
17+
- Bundles the UI files & the CSS using gresources
18+
- A pre-commit hook to run rustfmt on your code
19+
- Tests to validate your Metainfo, Schemas & Desktop files
20+
- Gsettings to store the window state, more settings could be added
21+
- Gitlab CI to produce flatpak nightlies
22+
- i18n support
23+
24+
## How to init a project ?
25+
26+
The template ships a simple python script to init a project easily. It asks you a few questions and replaces & renames all the necessary files.
27+
28+
The script requires having `git` installed on your system.
29+
30+
You can run it with,
31+
32+
```shell
33+
python3 create-project.py
34+
```
35+
36+
```shell
37+
➜ python3 create-project.py
38+
Welcome to GTK Rust Template
39+
Name: Contrast
40+
Project Name: contrast
41+
Application ID (e.g. org.domain.MyAwesomeApp, see: https://developer.gnome.org/ChooseApplicationID/): org.gnome.design.Contrast
42+
Author: Bilal Elmoussaoui
43+
44+
```
45+
46+
A new directory named `contrast` containing the generated project
47+
48+
## Building the project
49+
50+
Make sure you have `flatpak` and `flatpak-builder` installed. Then run the commands below. Replace `<application_id>` with the value you entered during project creation. Please note that these commands are just for demonstration purposes. Normally this would be handled by your IDE, such as GNOME Builder or VS Code with the Flatpak extension.
51+
52+
```
53+
flatpak install --user org.gnome.Sdk//master org.freedesktop.Sdk.Extension.rust-stable org.gnome.Platform//master org.freedesktop.Sdk.Extension.llvm16
54+
flatpak-builder --user flatpak_app build-aux/<application_id>.Devel.json
55+
```
56+
57+
## Running the project
58+
59+
Once the project is build, run the command below. Replace Replace `<application_id>` and `<project_name>` with the values you entered during project creation. Please note that these commands are just for demonstration purposes. Normally this would be handled by your IDE, such as GNOME Builder or VS Code with the Flatpak extension.
60+
61+
```
62+
flatpak-builder --run flatpak_app build-aux/<application_id>.Devel.json <project_name>
63+
```
64+
65+
## Community
66+
67+
Join the GNOME and gtk-rs community!
68+
- [Matrix chat](https://matrix.to/#/#rust:gnome.org): chat with other developers using gtk-rs
69+
- [Discourse forum](https://discourse.gnome.org/tag/rust): topics tagged with `rust` on the GNOME forum.
70+
- [GNOME circle](https://circle.gnome.org/): take inspiration from applications and libraries already extending the GNOME ecosystem.
71+
72+
## Credits
73+
74+
- [Podcasts](https://gitlab.gnome.org/World/podcasts)
75+
- [Shortwave](https://gitlab.gnome.org/World/Shortwave)
76+
- [gtk-rust-template without libadwaita and blueprint](https://gitlab.gnome.org/World/Rust/gtk-rust-template)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"id": "com.ranfdev.Notify.Devel",
3+
"runtime": "org.gnome.Platform",
4+
"runtime-version": "master",
5+
"sdk": "org.gnome.Sdk",
6+
"sdk-extensions": [
7+
"org.freedesktop.Sdk.Extension.rust-stable",
8+
"org.freedesktop.Sdk.Extension.llvm16"
9+
],
10+
"command": "notify",
11+
"finish-args": [
12+
"--share=ipc",
13+
"--socket=fallback-x11",
14+
"--socket=wayland",
15+
"--device=dri",
16+
"--env=RUST_LOG=notify=debug",
17+
"--env=G_MESSAGES_DEBUG=none",
18+
"--env=RUST_BACKTRACE=1"
19+
],
20+
"build-options": {
21+
"append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm16/bin",
22+
"build-args": [
23+
"--share=network"
24+
],
25+
"env": {
26+
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL": "sparse",
27+
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER": "clang",
28+
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold",
29+
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER": "clang",
30+
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold"
31+
},
32+
"test-args": [
33+
"--socket=x11",
34+
"--share=network"
35+
]
36+
},
37+
"modules": [
38+
{
39+
"name": "notify",
40+
"buildsystem": "meson",
41+
"run-tests": true,
42+
"config-opts": [
43+
"-Dprofile=development"
44+
],
45+
"sources": [
46+
{
47+
"type": "dir",
48+
"path": "../"
49+
}
50+
]
51+
}
52+
]
53+
}

build-aux/dist-vendor.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
export DIST="$1"
3+
export SOURCE_ROOT="$2"
4+
5+
cd "$SOURCE_ROOT"
6+
mkdir "$DIST"/.cargo
7+
cargo vendor | sed 's/^directory = ".*"/directory = "vendor"/g' > $DIST/.cargo/config
8+
# Move vendor into dist tarball directory
9+
mv vendor "$DIST"
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Desktop Entry]
2+
Name=Notify
3+
Comment=Write a GTK + Rust application
4+
Type=Application
5+
Exec=notify
6+
Terminal=false
7+
Categories=GNOME;GTK;
8+
# Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon!
9+
Keywords=Gnome;GTK;
10+
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
11+
Icon=@icon@
12+
StartupNotify=true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<schemalist>
3+
<schema path="/com/ranfdev/Notify/" id="@app-id@" gettext-domain="@gettext-package@">
4+
<key name="window-width" type="i">
5+
<default>600</default>
6+
<summary>Window width</summary>
7+
</key>
8+
<key name="window-height" type="i">
9+
<default>400</default>
10+
<summary>Window height</summary>
11+
</key>
12+
<key name="is-maximized" type="b">
13+
<default>false</default>
14+
<summary>Window maximized state</summary>
15+
</key>
16+
</schema>
17+
</schemalist>

0 commit comments

Comments
 (0)