Skip to content

Commit 85806c0

Browse files
committed
PoC of package created using jpackage
1 parent d443d16 commit 85806c0

File tree

1 file changed

+63
-15
lines changed

1 file changed

+63
-15
lines changed

tiny-cli/src/main/kotlin/com/github/minigdx/tiny/cli/command/ExportDesktopCommand.kt

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import kotlinx.serialization.json.Json
1414
import kotlinx.serialization.json.decodeFromStream
1515
import java.io.File
1616
import java.io.FileInputStream
17-
import java.net.URLClassLoader
1817
import java.nio.file.Files
1918
import java.nio.file.StandardCopyOption
2019

@@ -113,16 +112,65 @@ class ExportDesktopCommand : CliktCommand(name = "export-desktop") {
113112
"--main-class", "com.github.minigdx.tiny.cli.MainKt",
114113
)
115114

116-
if (platform == "mac") {
117-
jpackageCommand.addAll(listOf("--mac-package-name", appName))
118-
}
119-
120-
if (platform == "windows") {
121-
jpackageCommand.addAll(listOf("--win-dir-chooser", "--win-menu", "--win-shortcut"))
122-
}
123-
124-
if (platform == "linux") {
125-
jpackageCommand.addAll(listOf("--linux-shortcut"))
115+
// Add platform-specific arguments for game location
116+
when (platform) {
117+
"mac" -> {
118+
// For macOS, the application is installed in /Applications/[AppName].app/
119+
// The executable is in Contents/MacOS/ and we want to access the game directory in Contents/Resources/game
120+
jpackageCommand.addAll(
121+
listOf(
122+
"--arguments",
123+
"run",
124+
"--arguments",
125+
"../app/game",
126+
),
127+
)
128+
129+
// Add macOS-specific options
130+
jpackageCommand.addAll(listOf("--mac-package-name", appName))
131+
132+
// Add macOS-specific JVM options
133+
jpackageCommand.addAll(listOf("--java-options", "-XstartOnFirstThread"))
134+
}
135+
"windows" -> {
136+
// For Windows, use a relative path from the executable location
137+
jpackageCommand.addAll(
138+
listOf(
139+
"--arguments",
140+
"run",
141+
"--arguments",
142+
"game",
143+
),
144+
)
145+
146+
// Add Windows-specific options
147+
jpackageCommand.addAll(listOf("--win-dir-chooser", "--win-menu", "--win-shortcut"))
148+
}
149+
"linux" -> {
150+
// For Linux, use a relative path from the executable location
151+
jpackageCommand.addAll(
152+
listOf(
153+
"--arguments",
154+
"run",
155+
"--arguments",
156+
"game",
157+
),
158+
)
159+
160+
// Add Linux-specific options
161+
jpackageCommand.addAll(listOf("--linux-shortcut"))
162+
}
163+
else -> {
164+
// Default case
165+
jpackageCommand.addAll(
166+
listOf(
167+
"--arguments",
168+
"run",
169+
"--arguments",
170+
"game",
171+
),
172+
)
173+
}
126174
}
127175

128176
echo("\uD83D\uDCBB Running jpackage for $platform...")
@@ -186,7 +234,7 @@ class ExportDesktopCommand : CliktCommand(name = "export-desktop") {
186234
if (
187235
!dependencyFilePath.startsWith(excludedDirPath) &&
188236
dependencyFile.exists() && dependencyFile.isFile && dependencyFile.name.endsWith(".jar")
189-
) {
237+
) {
190238
val targetFile = File(outputJar.parent, dependencyFile.name)
191239
echo(" - Copying ${dependencyFile.name}")
192240
Files.copy(dependencyFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
@@ -205,7 +253,7 @@ class ExportDesktopCommand : CliktCommand(name = "export-desktop") {
205253
private fun copyRecursivelyExcluding(
206254
source: File,
207255
target: File,
208-
excludedDir: File
256+
excludedDir: File,
209257
) {
210258
// Get the canonical path of the excluded directory for reliable comparison
211259
val excludedDirPath = excludedDir.canonicalPath
@@ -303,10 +351,10 @@ class ExportDesktopCommand : CliktCommand(name = "export-desktop") {
303351
CLASSPATH="${'$'}CLASSPATH:${'$'}jar"
304352
fi
305353
done
306-
354+
307355
# Initialize the variable as empty
308356
MACOS_SPECIFIC_ARGS=""
309-
357+
310358
# Condition 1: OS must be macOS
311359
if [ `uname -s` = "Darwin" ]; then
312360
MACOS_SPECIFIC_ARGS="-XstartOnFirstThread"

0 commit comments

Comments
 (0)