Skip to content

Commit

Permalink
WIP: create mac app launcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
xian committed Sep 4, 2024
1 parent 11eb6ca commit 85845bd
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
87 changes: 86 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ repositories {
group = "org.baaahs"
version = "0.0.1"

val JVM_VERSION = 11

fun kotlinw(target: String): String =
"org.jetbrains.kotlin-wrappers:kotlin-$target"

kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(19)
languageVersion = JavaLanguageVersion.of(JVM_VERSION)
vendor = JvmVendorSpec.ADOPTIUM
}

Expand Down Expand Up @@ -351,6 +353,89 @@ tasks.withType<DependencyUpdatesTask> {
}
}

tasks.register("createMacApp") {
group = "application"
description = "Creates a macOS .app bundle for Sparkle Motion."

val shadowJarTask = tasks.named("shadowJar")
dependsOn(shadowJarTask)

val appName = "Sparkle Motion"
val appDir = buildDir("$appName.app")
val contentsDir = "$appDir/Contents"
val macosDir = "$contentsDir/MacOS"
val resourcesDir = "$contentsDir/Resources"
val javaDir = "$contentsDir/Java"

doLast {
copy {
from(shadowJarTask) {
include("*.jar")
eachFile {
println(this.file)
}
rename { "sparklemotion.jar" }
}
into(javaDir)
}

copy {
from("src/macApp/resources/SparkleMotion.icns")
into(resourcesDir)
}

// into(appDir)

// Create MacOS directory and add executable script
mkdir(macosDir)
val dollarDir = "\$DIR"
file("$macosDir/SparkleMotion").writeText("""
#!/bin/bash
DIR="$(cd "$(dirname "$0")" && pwd)/../.."
java -Xms512m -Xmx2048m -Dapple.laf.useScreenMenuBar=true -Xdock:name='Sparkle Motion' -Xdock:icon="$dollarDir/Contents/Resources/SparkleMotion.icns" -XstartOnFirstThread -Djava.awt.headless=true -jar "$dollarDir/Contents/Java/sparklemotion.jar"
""".trimIndent())
file("$macosDir/SparkleMotion").setExecutable(true)

// Create Info.plist
file("$contentsDir/Info.plist").writeText("""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>$appName</string>
<key>CFBundleDisplayName</key>
<string>$appName</string>
<key>CFBundleIdentifier</key>
<string>com.example.sparklemotion</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleExecutable</key>
<string>SparkleMotion</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleIconFile</key>
<string>SparkleMotion.icns</string>
<key>LSMinimumSystemVersion</key>
<string>10.9.0</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
</dict>
</plist>
""".trimIndent())
}
}

tasks.build {
dependsOn(tasks.named("createMacApp"))
}

// Janky. See https://github.com/google/ksp/issues/963#issuecomment-1780330007.
gradle.projectsEvaluated {
tasks {
Expand Down
68 changes: 68 additions & 0 deletions src/macApp/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Basic App Information -->
<key>CFBundleName</key>
<string>Sparkle Motion</string>
<key>CFBundleDisplayName</key>
<string>Sparkle Motion</string>
<key>CFBundleIdentifier</key>
<string>org.baaahs.sparklemotion</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>

<!-- Executable Information -->
<key>CFBundleExecutable</key>
<string>JavaApplicationStub</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleIconFile</key>
<string>application.icns</string>

<!-- Java Specific -->
<key>Java</key>
<dict>
<!-- Path to the main Java class -->
<key>MainClass</key>
<string>baaahs.sm.server.PinkyMainKt</string>

<!-- JVM settings -->
<key>JVMVersion</key>
<string>1.8+</string>
<key>JVMOptions</key>
<array>
<string>-Dapple.laf.useScreenMenuBar=true</string>
<string>-Xdock:name=Sparkle Motion</string>
<string>-Xdock:icon=SparkleMotion.icns</string>
</array>

<!-- Memory settings -->
<key>JVMArguments</key>
<array>
<string>-Xms512m</string>
<string>-Xmx2048m</string>
</array>

<!-- Path to the JAR file -->
<key>ClassPath</key>
<array>
<string>$JAVAROOT/sparklemotion.jar</string>
</array>
</dict>

<!-- Required keys for macOS compatibility -->
<key>LSMinimumSystemVersion</key>
<string>10.9.0</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>

<!-- Application type -->
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
</dict>
</plist>
Binary file added src/macApp/resources/SparkleMotion.icns
Binary file not shown.

0 comments on commit 85845bd

Please sign in to comment.