Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

Add branded drag-to-install DMG packaging

harry036128a8b660f48f7
diff --git a/README.md b/README.md
index fe3040f..85c25db 100644
--- a/README.md
+++ b/README.md
@@ -380,6 +380,23 @@ An Apple silicon Mac can build **both**: the architecture is decided by whicheve
Rosetta runs an x86_64 one. Take Temurin's macOS x64 tarball rather than Homebrew — the `openjdk@17`
formula compiles from source and demands a full Xcode, which this project otherwise does not need:
+`packageDmg` uses dmgbuild 1.6.7 to add the Applications drag target and Finder layout.
+Set up its pinned Python dependency once before either build. The Gradle task checks for
+this dependency before jpackage writes a dmg:
+
+```bash
+python3 -m venv desktop/build/dmg-venv
+desktop/build/dmg-venv/bin/python -m pip install -r desktop/dmg/requirements.txt
+export ANDEE_DMG_PYTHON="$PWD/desktop/build/dmg-venv/bin/python"
+```
+
+The committed `desktop/dmg/background.png` is used as-is during packaging. To
+regenerate it after editing the artwork or caption, install the optional Pillow
+dependency with `desktop/dmg/requirements-background.txt` and run
+`ANDEE_REGENERATE_BACKGROUND=1 bash desktop/dmg/make-dmg.sh ...`.
+`packageReleaseDmg` and `notarizeDmg` are not part of this drag-to-install
+packaging path; verify their image layout separately before distributing one.
+
```bash
curl -L -o /tmp/jdk17-x64.tar.gz \
'https://api.adoptium.net/v3/binary/latest/17/ga/mac/x64/jdk/hotspot/normal/eclipse'
diff --git a/desktop/build.gradle b/desktop/build.gradle
index 90b0076..5883483 100644
--- a/desktop/build.gradle
+++ b/desktop/build.gradle
@@ -159,19 +159,22 @@ dependencies {
testImplementation libs.junit
}
+def macPackageName = 'Andee'
+def macPackageVersion = '1.0.0'
+
compose.desktop {
application {
mainClass = 'net.kuafuai.andee.desktop.MainKt'
nativeDistributions {
targetFormats(TargetFormat.Dmg)
- packageName = 'Andee'
+ packageName = macPackageName
// The packaged runtime is trimmed to what jlink sees used; LWJGL (the
// ball's OpenGL) reaches sun.misc.Unsafe reflectively, so name it, or the
// ball silently fails only in the .app and never under `gradle run`.
modules('jdk.unsupported')
// macOS rejects a 0.x bundle version for a .dmg; 1.0.0 is the bundle's
// version, not the product's.
- packageVersion = '1.0.0'
+ packageVersion = macPackageVersion
macOS {
// The phone's launcher character on a white tile, as an .icns (icon/Andee.icns).
iconFile.set(project.file('icon/Andee.icns'))
@@ -284,6 +287,38 @@ tasks.matching { it.name == 'createDistributable' }.configureEach { finalizedBy(
tasks.named('signApp') { dependsOn('patchInfoPlist') }
tasks.matching { it.name == 'createDistributable' }.configureEach { finalizedBy('signApp') }
+// Rebuild the dmg around the *signed* app with the Applications symlink and a
+// laid-out window (app on the left, Applications on the right, an arrow
+// background) — jpackage's own dmg has no drag target, so people double-click
+// the app and run it straight from the mounted image. make-dmg.sh runs dmgbuild,
+// which writes the .DS_Store that carries the window size, icon positions and
+// background directly — Finder's AppleScript no longer writes .DS_Store on
+// current macOS, so the osascript route was abandoned. It runs after signApp,
+// so the bundled app is the signed one. This deliberately handles the
+// documented packageDmg workflow; release/notarization tasks have distinct
+// outputs and must not be used to publish a drag-to-install image until wired
+// to the same layout step.
+tasks.register('checkDmgTools', Exec) {
+ commandLine 'bash', file('dmg/make-dmg.sh').path, '--check-tools'
+}
+tasks.register('polishDmg', Exec) {
+ dependsOn('createDistributable', 'signApp', 'checkDmgTools')
+ def app = layout.buildDirectory.dir('compose/binaries/main/app/Andee.app')
+ def out = layout.buildDirectory.file("compose/binaries/main/dmg/${macPackageName}-${macPackageVersion}.dmg")
+ commandLine 'bash',
+ file('dmg/make-dmg.sh').path,
+ app.get().asFile.path,
+ out.get().asFile.path
+}
+// packageDmg still builds jpackage's bare dmg; polishDmg overwrites it in place,
+// so the existing `./gradlew :desktop:packageDmg` yields the finished one.
+// Always re-cut the image because signing may change the bundle even when
+// Gradle considers createDistributable up to date.
+tasks.matching { it.name == 'packageDmg' }.configureEach {
+ dependsOn('checkDmgTools')
+ finalizedBy('polishDmg')
+}
+
// The real window body, drawn offscreen against seeded throwaway data:
// ./gradlew :desktop:uishot --args='chat 1020 820 /tmp/ui.png'
tasks.register('uishot', JavaExec) {
diff --git a/desktop/dmg/background-art.png b/desktop/dmg/background-art.png
new file mode 100644
index 0000000..0a8f88e
Binary files /dev/null and b/desktop/dmg/background-art.png differ
diff --git a/desktop/dmg/background.png b/desktop/dmg/background.png
new file mode 100644
index 0000000..a2095a8
Binary files /dev/null and b/desktop/dmg/background.png differ
diff --git a/desktop/dmg/dmgbuild-settings.py b/desktop/dmg/dmgbuild-settings.py
new file mode 100755
index 0000000..0ded5a8
--- /dev/null
+++ b/desktop/dmg/dmgbuild-settings.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+"""Finder window geometry for the Andee drag-to-Applications DMG.
+
+Keep these icon centres aligned with make-background.py. dmgbuild writes the
+Finder .DS_Store directly, so the layout survives mounting on modern macOS.
+"""
+import os
+
+app = os.environ['ANDEE_APP']
+
+files = [app]
+symlinks = {'Applications': '/Applications'}
+
+# dmgbuild exec()s this file, so __file__ is not defined; make-dmg.sh passes
+# the path in, the same way it passes the app.
+background = os.environ['ANDEE_BACKGROUND']
+icon = os.environ['ANDEE_VOLUME_ICON']
+# dmgbuild stores an alias containing the volume name for the background.
+# Update make-dmg.sh's volume name and rebuild the image if it changes.
+
+window_rect = ((200, 120), (820, 500))
+default_view = 'icon-view'
+icon_size = 104
+icon_locations = {
+ 'Andee.app': (225, 246),
+ 'Applications': (595, 246),
+}
+arrange_by = None # "not arranged" — the layout is hand-placed, not sorted
+
+show_status_bar = False
+show_toolbar = False
+show_sidebar = False
+show_pathbar = False
+show_tab_view = False
+
+# UDZO (zlib) mounts faster than dmgbuild's UDBZ default; jpackage's dmg was
+# already UDZO, so the finished image behaves the same as before.
+format = 'UDZO'
diff --git a/desktop/dmg/make-background.py b/desktop/dmg/make-background.py
new file mode 100644
index 0000000..45562c1
--- /dev/null
+++ b/desktop/dmg/make-background.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+"""Compose the Andee DMG background from icon-inspired art and clear guidance.
+
+Finder draws the actual app and Applications icons. This image only supplies
+decoration and instructions; coordinates match dmgbuild-settings.py.
+"""
+from pathlib import Path
+
+from PIL import Image, ImageDraw, ImageFont
+
+HERE = Path(__file__).parent
+WIDTH, HEIGHT = 820, 500
+SCALE = 2
+
+
+def xy(values):
+ return tuple(round(value * SCALE) for value in values)
+
+
+def font(size):
+ for name in (
+ "/System/Library/Fonts/STHeiti Medium.ttc",
+ "/System/Library/Fonts/Hiragino Sans GB.ttc",
+ "/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
+ ):
+ try:
+ return ImageFont.truetype(name, size * SCALE)
+ except OSError:
+ pass
+ return ImageFont.load_default()
+
+
+art = Image.open(HERE / "background-art.png").convert("RGB")
+image = art.resize((WIDTH * SCALE, HEIGHT * SCALE), Image.Resampling.LANCZOS)
+decor = Image.new("RGBA", image.size)
+d = ImageDraw.Draw(decor)
+
+# Translucent area behind the real Finder items, keeping the art visible.
+d.rounded_rectangle(
+ xy((122, 178, 698, 438)),
+ radius=72 * SCALE,
+ fill=(255, 255, 255, 42),
+ outline=(255, 255, 255, 100),
+ width=2 * SCALE,
+)
+
+# The arrow sits between icon centres (225, 246) and (595, 246).
+d.rounded_rectangle(
+ xy((331, 240, 487, 252)),
+ radius=6 * SCALE,
+ fill=(255, 255, 255, 225),
+)
+d.polygon(
+ [xy((476, 219)), xy((514, 246)), xy((476, 273))],
+ fill=(255, 255, 255, 225),
+)
+d.rounded_rectangle(
+ xy((334, 243, 486, 249)),
+ radius=3 * SCALE,
+ fill=(92, 123, 213, 240),
+)
+d.polygon(
+ [xy((478, 228)), xy((503, 246)), xy((478, 264))],
+ fill=(92, 123, 213, 240),
+)
+
+d.text(
+ xy((410, 370)), "拖拽完成安装",
+ font=font(23), fill=(40, 58, 111, 245), anchor="mm",
+)
+d.text(
+ xy((410, 402)), "Drag Andee to Applications",
+ font=font(13), fill=(70, 85, 135, 230), anchor="mm",
+)
+
+image = Image.alpha_composite(image.convert("RGBA"), decor)
+image = image.convert("RGB").resize((WIDTH, HEIGHT), Image.Resampling.LANCZOS)
+output = HERE / "background.png"
+image.save(output, optimize=True)
+print(f"wrote {output} ({WIDTH}x{HEIGHT})")
diff --git a/desktop/dmg/make-dmg.sh b/desktop/dmg/make-dmg.sh
new file mode 100755
index 0000000..5c18074
--- /dev/null
+++ b/desktop/dmg/make-dmg.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+# Builds the release dmg around the *signed* Andee.app with the Applications
+# symlink and the drag layout (app on the left, Applications on the right, an
+# arrow background, a fixed window).
+#
+# jpackage's dmg (what Compose Desktop's packageDmg produces) has no
+# Applications symlink and no window layout, so people double-click the app and
+# run it straight from the mounted image. dmgbuild writes the .DS_Store that
+# carries the layout directly — Finder's AppleScript no longer writes .DS_Store
+# on current macOS (measured on Sequoia), so the osascript route was abandoned.
+#
+# Usage: make-dmg.sh [--check-tools | <Andee.app> <out.dmg>]
+set -euo pipefail
+
+HERE="$(cd "$(dirname "$0")" && pwd)"
+PYTHON="${ANDEE_DMG_PYTHON:-python3}"
+
+check_tools() {
+ if ! command -v "$PYTHON" >/dev/null 2>&1 || \
+ ! "$PYTHON" -c "from importlib.metadata import version; import sys; sys.exit(version('dmgbuild') != '1.6.7')" 2>/dev/null; then
+ echo "DMG packaging requires Python with dmgbuild==1.6.7." >&2
+ echo "Install it using desktop/dmg/requirements.txt; see README.md (Mac packaging)." >&2
+ echo "Set ANDEE_DMG_PYTHON to that environment's Python executable." >&2
+ exit 2
+ fi
+}
+
+check_tools
+if [[ "${1:-}" == "--check-tools" ]]; then
+ exit 0
+fi
+if [[ $# -ne 2 ]]; then
+ echo "Usage: $0 <Andee.app> <out.dmg>" >&2
+ exit 2
+fi
+
+APP="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
+OUT="$2"
+
+mkdir -p "$(dirname "$OUT")"
+export ANDEE_APP="$APP"
+export ANDEE_BACKGROUND="$HERE/background.png"
+export ANDEE_VOLUME_ICON="$HERE/../icon/Andee.icns"
+
+if [[ ! -f "$ANDEE_BACKGROUND" || -n "${ANDEE_REGENERATE_BACKGROUND:-}" ]]; then
+ "$PYTHON" "$HERE/make-background.py"
+fi
+
+"$PYTHON" -m dmgbuild "Andee" "$OUT" -s "$HERE/dmgbuild-settings.py"
diff --git a/desktop/dmg/requirements-background.txt b/desktop/dmg/requirements-background.txt
new file mode 100644
index 0000000..9673b41
--- /dev/null
+++ b/desktop/dmg/requirements-background.txt
@@ -0,0 +1 @@
+Pillow==11.3.0
diff --git a/desktop/dmg/requirements.txt b/desktop/dmg/requirements.txt
new file mode 100644
index 0000000..f515e71
--- /dev/null
+++ b/desktop/dmg/requirements.txt
@@ -0,0 +1 @@
+dmgbuild==1.6.7