diff --git a/build.gradle.kts b/build.gradle.kts index 6f4081a..c1418e3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -449,6 +449,9 @@ tasks.register("jpackage") { if (os.isLinux) { options.add("-Dsun.java2d.opengl=true") + if (isDeb) { + options.add("-Djpackage.app-layout=deb") + } } val arguments = mutableListOf("${Jvm.current().javaHome}/bin/jpackage") @@ -601,20 +604,26 @@ fun pack() { } /** - * 创建 zip、7z、msi + * 创建 zip、msi */ fun packOnWindows(distributionDir: Directory, finalFilenameWithoutExtension: String, projectName: String) { + val dir = layout.buildDirectory.dir("jpackage/images/win-msi.image/").get().asFile + val cfg = FileUtils.getFile(dir, projectName, "app", "${projectName}.cfg") + val configText = cfg.readText() + // zip + cfg.writeText(StringBuilder(configText).appendLine("java-options=-Djpackage.app-layout=zip").toString()) exec { commandLine( "tar", "-vacf", distributionDir.file("${finalFilenameWithoutExtension}.zip").asFile.absolutePath, projectName ) - workingDir = layout.buildDirectory.dir("jpackage/images/win-msi.image/").get().asFile + workingDir = dir } // exe + cfg.writeText(StringBuilder(configText).appendLine("java-options=-Djpackage.app-layout=exe").toString()) exec { commandLine( "iscc", @@ -718,7 +727,11 @@ fun packOnLinux(distributionDir: Directory, finalFilenameWithoutExtension: Strin return } + val cfg = FileUtils.getFile(distributionDir.asFile, projectName, "lib", "app", "${projectName}.cfg") + val configText = cfg.readText() + // tar.gz + cfg.writeText(StringBuilder(configText).appendLine("java-options=-Djpackage.app-layout=tar.gz").toString()) exec { commandLine( "tar", "-czvf", @@ -773,6 +786,7 @@ Terminal=false appRun.setExecutable(true) // AppImage + cfg.writeText(StringBuilder(configText).appendLine("java-options=-Djpackage.app-layout=AppImage").toString()) exec { commandLine(appimagetool.absolutePath, termoraName, "${finalFilenameWithoutExtension}.AppImage") workingDir = distributionDir.asFile diff --git a/src/main/kotlin/app/termora/AppLayout.kt b/src/main/kotlin/app/termora/AppLayout.kt new file mode 100644 index 0000000..04920e7 --- /dev/null +++ b/src/main/kotlin/app/termora/AppLayout.kt @@ -0,0 +1,21 @@ +package app.termora + +enum class AppLayout { + /** + * Windows + */ + Zip, + Exe, + + /** + * macOS + */ + App, + + /** + * Linux + */ + TarGz, + AppImage, + Deb, +} \ No newline at end of file diff --git a/src/main/kotlin/app/termora/Application.kt b/src/main/kotlin/app/termora/Application.kt index bbe5ee5..3dac1d0 100644 --- a/src/main/kotlin/app/termora/Application.kt +++ b/src/main/kotlin/app/termora/Application.kt @@ -121,6 +121,30 @@ object Application { return version } + fun getLayout(): AppLayout { + if (SystemInfo.isMacOS) return AppLayout.App + + val layout = System.getProperty("jpackage.app-layout") + if (SystemInfo.isLinux) { + if ("deb" == layout) { + return AppLayout.Deb + } else if ("tar.gz" == layout) { + return AppLayout.TarGz + } + } + + if (SystemInfo.isWindows) { + if ("exe" == layout) { + return AppLayout.Exe + } else if ("zip" == layout) { + return AppLayout.Zip + } + } + + return if (SystemInfo.isWindows) AppLayout.Exe else AppLayout.AppImage + + } + /** * 未知版本通常是开发版本 */