Skip to content

Commit a3e9678

Browse files
authored
Initial commit
0 parents  commit a3e9678

61 files changed

Lines changed: 5378 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.editorconfig‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.{kt,kts}]
12+
max_line_length = 140
13+
14+
[*.{yml,yaml,toml,xml,json}]
15+
indent_size = 2

‎.gitattributes‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* text=auto eol=lf
2+
*.bat text eol=crlf
3+
gradlew text eol=lf
4+
5+
*.png binary
6+
*.ico binary
7+
*.icns binary
8+
*.ttf binary
9+
*.jar binary

‎.github/dependabot.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Keeps Gradle dependencies (including gradle/libs.versions.toml) and GitHub Actions up to date.
2+
# Enabled in projects created from this template. To enable: remove the leading "# " from every line.
3+
#
4+
# version: 2
5+
# updates:
6+
# - package-ecosystem: gradle
7+
# directory: /
8+
# schedule:
9+
# interval: weekly
10+
# - package-ecosystem: github-actions
11+
# directory: /
12+
# schedule:
13+
# interval: weekly

‎.github/workflows/build.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# CI build, enabled in projects created from this template (NOT in the template repository itself).
2+
# To enable: remove the leading "# " from every line of this file.
3+
#
4+
# name: Build
5+
#
6+
# on:
7+
# push:
8+
# branches: [main]
9+
# pull_request:
10+
#
11+
# concurrency:
12+
# group: build-${{ github.ref }}
13+
# cancel-in-progress: true
14+
#
15+
# jobs:
16+
# build:
17+
# name: Build (${{ matrix.os }})
18+
# runs-on: ${{ matrix.os }}
19+
# strategy:
20+
# fail-fast: false
21+
# matrix:
22+
# # Packaging only works for the OS it runs on, so every OS gets its own runner.
23+
# os: [ubuntu-latest, windows-latest, macos-latest]
24+
# steps:
25+
# - uses: actions/checkout@v4
26+
#
27+
# - uses: actions/setup-java@v4
28+
# with:
29+
# distribution: temurin
30+
# java-version: 21
31+
#
32+
# - uses: gradle/actions/setup-gradle@v4
33+
#
34+
# - name: Build and test
35+
# run: ./gradlew build --no-daemon
36+
#
37+
# - name: Upload test reports on failure
38+
# if: failure()
39+
# uses: actions/upload-artifact@v4
40+
# with:
41+
# name: test-reports-${{ matrix.os }}
42+
# path: build/reports/tests

‎.github/workflows/release.yml‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Builds installers on every OS and publishes them as a GitHub Release when a version tag is pushed.
2+
# Enabled in projects created from this template (NOT in the template repository itself).
3+
# To enable: remove the leading "# " from every line of this file.
4+
#
5+
# How the auto-updater finds your installers:
6+
# - it reads the latest GitHub Release of github.owner/github.repo (see gradle.properties)
7+
# - it picks the asset by extension (.msi/.exe, .dmg/.pkg, .deb/.rpm) and by an architecture token in
8+
# the file name (x64 / arm64), which is why the "Collect" step below prefixes every file with a label.
9+
#
10+
# Release flow: git tag v1.2.0 && git push origin v1.2.0
11+
#
12+
# name: Release
13+
#
14+
# on:
15+
# push:
16+
# tags: ["v*"]
17+
#
18+
# permissions:
19+
# contents: write
20+
#
21+
# jobs:
22+
# package:
23+
# name: Package (${{ matrix.label }})
24+
# runs-on: ${{ matrix.os }}
25+
# strategy:
26+
# fail-fast: false
27+
# matrix:
28+
# include:
29+
# - { os: windows-latest, label: windows-x64 }
30+
# - { os: macos-latest, label: macos-arm64 }
31+
# - { os: macos-15-intel, label: macos-x64 }
32+
# - { os: ubuntu-latest, label: linux-x64 }
33+
# steps:
34+
# - uses: actions/checkout@v4
35+
#
36+
# - uses: actions/setup-java@v4
37+
# with:
38+
# distribution: temurin
39+
# java-version: 21
40+
#
41+
# - uses: gradle/actions/setup-gradle@v4
42+
#
43+
# - name: Package release installers
44+
# shell: bash
45+
# # The tag (v1.2.0) becomes the app version, overriding app.version in gradle.properties.
46+
# run: ./gradlew packageReleaseDistributionForCurrentOS -Papp.version="${GITHUB_REF_NAME#v}" --no-daemon
47+
#
48+
# - name: Collect installers
49+
# shell: bash
50+
# run: |
51+
# mkdir -p dist
52+
# for file in build/compose/binaries/main-release/*/*; do
53+
# [ -f "$file" ] && cp "$file" "dist/${{ matrix.label }}-$(basename "$file")"
54+
# done
55+
# ls -la dist
56+
#
57+
# - uses: actions/upload-artifact@v4
58+
# with:
59+
# name: installers-${{ matrix.label }}
60+
# path: dist/*
61+
# if-no-files-found: error
62+
#
63+
# publish:
64+
# name: Publish GitHub Release
65+
# needs: package
66+
# runs-on: ubuntu-latest
67+
# steps:
68+
# - uses: actions/download-artifact@v4
69+
# with:
70+
# pattern: installers-*
71+
# path: dist
72+
# merge-multiple: true
73+
#
74+
# - uses: softprops/action-gh-release@v2
75+
# with:
76+
# files: dist/*
77+
# generate_release_notes: true
78+
# # Tags like v1.2.0-rc.1 are published as pre-releases, the updater ignores them by default.
79+
# prerelease: ${{ contains(github.ref_name, '-') }}

‎.gitignore‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.gradle/
2+
build/
3+
out/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
6+
.idea/
7+
*.iml
8+
.vscode/
9+
.kotlin/
10+
.fleet/
11+
12+
*.log
13+
hs_err_pid*
14+
.DS_Store
15+
Thumbs.db
16+
17+
local.properties
18+
*.keystore
19+
*.p12
20+
*.pfx
21+
.env

‎README.md‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Kotlin Desktop Template
2+
3+
A starting point for desktop apps in Kotlin with their own window frame (no OS title bar), rendered by Skia
4+
through Skiko. No embedded browser: Compose Desktop draws everything on a Skia canvas.
5+
6+
- Kotlin 2.4 on JDK 21, Gradle 9.8 (Kotlin DSL) and a version catalog (`gradle/libs.versions.toml`)
7+
- Compose Multiplatform Desktop 1.12 (Skiko is its renderer, the Skia API is also available directly, see `Gradient.kt`)
8+
- Undecorated window with a `TitleBar` component: drag, double-click to maximize, minimize/maximize/close, edge resize
9+
- Auto-update from GitHub Releases, written on the JDK `HttpClient` and kotlinx.serialization (no extra HTTP library)
10+
- i18n with Compose resources (`en`, `pt`, `de` as examples) and a persisted language choice
11+
- Native installers through jpackage (`.msi`/`.exe`, `.dmg`, `.deb`/`.rpm`) with a bundled, jlinked JRE
12+
- GitHub Actions for build and release, shipped commented out
13+
- Many useful libraries ready to enable in `build.gradle.kts`, each one explained
14+
15+
## Quick start
16+
17+
```bash
18+
./gradlew run # start the app
19+
./gradlew test # unit tests
20+
./gradlew packageDistributionForCurrentOS # installer for the OS you are on (build/compose/binaries/main/)
21+
./gradlew createDistributable # portable folder with launcher executable and bundled JRE
22+
```
23+
24+
jpackage only builds installers for the OS it runs on, so use the CI matrix in `.github/workflows/release.yml`
25+
to produce all of them.
26+
27+
## Creating a project from this template
28+
29+
1. `gradle.properties`: `app.name`, `app.group`, `app.version`, `app.vendor`, `github.owner`, `github.repo`.
30+
2. Rename the package `com.example.app` to your `app.group` (directories under `src/main/kotlin` and `src/test/kotlin`).
31+
`compose.resources.packageOfResClass` and `mainClass` already follow `app.group`.
32+
3. `build.gradle.kts`: generate a new `upgradeUuid` for the Windows MSI and keep it stable from then on.
33+
4. Replace the icons in `packaging/` and `src/main/composeResources/drawable/app_icon.png`.
34+
5. `settings.gradle.kts`: change `rootProject.name`.
35+
6. Enable the workflows: remove the leading `# ` from the lines in `.github/workflows/*.yml` and `.github/dependabot.yml`.
36+
37+
## Auto-update
38+
39+
`GitHubUpdater` calls `GET /repos/{owner}/{repo}/releases/latest`, compares the tag (`v1.2.0`) with the running
40+
version using semantic versioning, picks the installer for the current OS and architecture, downloads it with
41+
progress and verifies the SHA-256 digest GitHub reports for the asset. `UpdateManager` exposes the state as a
42+
`StateFlow` for the UI, and `Installer` hands the file to the OS (`msiexec`, `open`, `xdg-open`) so the user
43+
confirms the install, then the app quits.
44+
45+
- The release workflow prefixes asset names with `windows-x64`, `macos-arm64`, `macos-x64`, `linux-x64`.
46+
The updater matches those tokens, so keep that naming if you change the workflow.
47+
- Linux: `.deb` or `.rpm` is chosen from `/etc/os-release`. On other distributions (Arch and derivatives) no
48+
installer matches, and the UI offers the release page instead.
49+
- Only public repositories work as written. Private repositories need a token, which should not be shipped in an app.
50+
- Unsigned installers trigger SmartScreen and Gatekeeper warnings. Signing is configured in the `windows`/`macOS` blocks.
51+
52+
## Internationalization
53+
54+
Strings live in `src/main/composeResources/values*/strings.xml` and are read with
55+
`stringResource(Res.string.key)`. To add a language, add a `values-xx/strings.xml` and list the locale in
56+
`Languages.supported`. The chosen language is stored with `java.util.prefs`. Switching happens at runtime by
57+
setting the default `Locale` and recomposing the window content under `key(locale)` (see `Main.kt`).
58+
59+
## Custom window frame: what you get and what you give up
60+
61+
Drawing the title bar yourself means the OS no longer provides some behaviours:
62+
63+
- Edge resizing and dragging are implemented by Compose for undecorated windows. Window snapping (Windows Snap
64+
Layouts, macOS tiling, some Linux compositors) may not work.
65+
- A maximized undecorated window can cover the Windows taskbar. `TitleBar` sets `maximizedBounds` to the usable
66+
screen area on Windows to avoid that. Test it on your multi-monitor setups.
67+
- On macOS the controls are drawn on the left as colored circles, elsewhere on the right.
68+
- If you need the native frame behaviour back with a custom look, JetBrains Runtime exposes a custom title bar
69+
API that keeps native controls and snapping, at the cost of depending on JBR internals.
70+
71+
## Packaging notes
72+
73+
- `modules(...)` in `build.gradle.kts` lists the JDK modules jlink keeps. Add what your dependencies need
74+
(for example `java.sql`). If something works with `run` but fails in the installed app, a missing module is the usual cause.
75+
- Installer size is mostly the bundled runtime. Expect tens of megabytes.
76+
- `jpackage` rejects `0.x.y` versions for `.dmg`/`.pkg`, so the template starts at `1.0.0`.
77+
78+
## Lucide icons
79+
80+
All [Lucide](https://lucide.dev) icons as a font, drawn with Skia.
81+
82+
```kotlin
83+
LucideIcon(Lucide.Settings) // 16.dp, theme text color
84+
LucideIcon(Lucide.FolderOpen, size = 24.dp, tint = AppTheme.colors.accent, contentDescription = "Open")
85+
LucideIcon(Lucide.byName("arrow-up-right") ?: Lucide.CircleHelp) // by kebab-case name at runtime
86+
BasicText(Lucide.Heart.text, style = TextStyle(fontFamily = LucideFont.family, fontSize = 18.sp))
87+
```
88+
89+
How it works: `lucide.ttf` has a 1000 unit em square with the baseline at the bottom edge, and every icon sits on
90+
Lucide's 24x24 grid inside it. `LucideIcon` loads the TTF into a Skia `Typeface` once and draws the icon's code
91+
point with `Canvas.drawString`, placing the baseline at the bottom of the icon box. No font metrics are involved,
92+
so the result is identical on every OS. Prefer `LucideIcon` over `Text` with the font family, which adds line
93+
height and can shift the glyph.
94+
95+
Files:
96+
97+
```
98+
scripts/generate-lucide.groovy installs the font and generates the mapping
99+
src/main/resources/fonts/lucide.ttf the icon font
100+
src/main/resources/fonts/lucide-codepoints.json name -> code point (also contains renamed/alias names)
101+
src/main/resources/licenses/lucide.txt ISC + MIT notices, they must ship with the font
102+
src/main/kotlin/.../ui/icons/Lucide.kt generated: one typed constant per icon (Lucide.ArrowDown, ...)
103+
src/main/kotlin/.../ui/icons/Lucide*.kt LucideGlyph, LucideFont, LucideIcon, lookup, gallery
104+
```
105+
106+
- `groovy scripts/generate-lucide.groovy` downloads the newest `lucide-static` from npm (needs `npm` and `tar`),
107+
`--version 1.62.0` pins a release, `--lucide-dir <path>` uses an unpacked copy. Rerun it to update the icons.
108+
The Kotlin package defaults to `<app.group>.ui.icons`, override it with `--package`.
109+
- Constant names are the kebab-case name in PascalCase (`folder-open` -> `FolderOpen`). Aliases of renamed icons
110+
are included, so old names keep working. Icons that Lucide removed from the font (brand logos such as GitHub)
111+
are skipped by the script.
112+
- `LucideGallery.kt` has a `main()` with a searchable grid of every icon: run it from the IDE to browse names.
113+
- To remove it: delete `ui/icons/`, `scripts/generate-lucide.groovy` and the three resource files above.
114+
115+
## Alternatives worth knowing
116+
117+
- [Nucleus](https://github.com/kdroidfilter/Nucleus): Gradle plugin and runtime libraries for Compose Desktop
118+
(packaging, an updater, decorated window helpers, native notifications). It tracks the newest Kotlin and Compose
119+
releases closely, so check its requirements before adopting it.
120+
- `compose-native` (community fork): Kotlin/Native builds of Compose without a JVM for Linux and Windows. Alpha.

0 commit comments

Comments
 (0)