fix: AppImage not working

This commit is contained in:
hstyi
2025-02-14 14:37:19 +08:00
committed by hstyi
parent 9875200912
commit ff865f13a2

View File

@@ -395,26 +395,30 @@ tasks.register("dist") {
// AppImage // AppImage
if (os.isLinux) { if (os.isLinux) {
// Download AppImageKit
val appimagetool = FileUtils.getFile(projectDir, ".gradle", "appimagetool")
if (!appimagetool.exists()) {
exec { exec {
commandLine( commandLine(
"wget", "wget",
"-O", "appimagetool", "-O", appimagetool.absolutePath,
"https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-${if (arch.isArm) "aarch64" else "x86_64"}.AppImage" "https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-${if (arch.isArm) "aarch64" else "x86_64"}.AppImage"
) )
workingDir = distributionDir.asFile workingDir = distributionDir.asFile
} }
exec { // AppImageKit chmod
commandLine("chmod", "+x", distributionDir.file("appimagetool")) exec { commandLine("chmod", "+x", appimagetool.absolutePath) }
} }
// Desktop file
val termoraName = project.name.uppercaseFirstChar() val termoraName = project.name.uppercaseFirstChar()
val desktopFile = distributionDir.file(termoraName + File.separator + termoraName + ".desktop").asFile val desktopFile = distributionDir.file(termoraName + File.separator + termoraName + ".desktop").asFile
desktopFile.writeText( desktopFile.writeText(
"""[Desktop Entry] """[Desktop Entry]
Type=Application Type=Application
Name=${termoraName} Name=${termoraName}
Exec=bin/${termoraName}
Comment=Terminal emulator and SSH client Comment=Terminal emulator and SSH client
Icon=/lib/${termoraName} Icon=/lib/${termoraName}
Categories=Development; Categories=Development;
@@ -422,8 +426,18 @@ Terminal=false
""".trimIndent() """.trimIndent()
) )
// AppRun file
val appRun = File(desktopFile.parentFile, "AppRun")
val sb = StringBuilder()
sb.append("#!/bin/sh").appendLine()
sb.append("SELF=$(readlink -f \"$0\")").appendLine()
sb.append("HERE=\${SELF%/*}").appendLine()
sb.append("exec \"\${HERE}/bin/${termoraName}\" \"$@\"")
appRun.writeText(sb.toString())
appRun.setExecutable(true)
exec { exec {
commandLine("./appimagetool", termoraName, "${finalFilenameWithoutExtension}.AppImage") commandLine(appimagetool.absolutePath, termoraName, "${finalFilenameWithoutExtension}.AppImage")
workingDir = distributionDir.asFile workingDir = distributionDir.asFile
} }
} }