-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
234 lines (215 loc) · 8.42 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
234 lines (215 loc) · 8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag
import java.nio.file.Paths
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.compose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.buildconfig)
alias(libs.plugins.compose.hot.reload)
}
group = "moe.styx"
version = "0.2.2-beta3"
// Necessary to have working Windows installers for rc/beta/etc versions.
// Count up by one for every release until a new MINOR version bump.
val subVersionClassifier = 6
repositories {
google()
mavenCentral()
mavenLocal()
maven("https://jitpack.io")
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
maven("https://repo.styx.moe/releases")
maven("https://repo.styx.moe/snapshots")
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(libs.coroutines.core.swing)
// Compose Stuff
implementation(compose.desktop.currentOs)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.components.resources)
// Misc
implementation(libs.slf4j.simple)
implementation(libs.zip4j)
implementation(libs.kdiscord.ipc)
implementation(libs.junixsocket)
// Styx
implementation(libs.styx.common.compose)
}
val jlinkModules = arrayOf(
"java.base",
"java.desktop",
"java.instrument",
"java.logging",
"java.management",
"java.net.http",
"java.prefs",
"java.rmi",
"jdk.unsupported",
"jdk.crypto.ec"
)
compose.desktop {
application {
mainClass = "moe.styx.MainKt"
jvmArgs += listOf("-Xmx1250M", "-Xms300M")
buildTypes.release.proguard {
configurationFiles.from(project.file("proguard.rules"))
}
nativeDistributions {
modules(*jlinkModules)
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb, TargetFormat.Rpm)
packageName = "Styx 2"
copyright = "© 2024 Vodes & Styx contributors. All rights reserved."
vendor = "Vodes & Styx contributors"
licenseFile.set(project.file("LICENSE"))
windows {
packageVersion = project.version.toString().split("-")[0] + subVersionClassifier.toString().padStart(4, '0')
menuGroup = "Styx"
upgradeUuid = System.getenv("STYX_APP_GUID")
iconFile.set(project.file("src/main/resources/icons/icon.ico"))
}
linux {
packageVersion = project.version.toString().replace("-", ".")
iconFile.set(project.file("src/main/resources/icons/icon.png"))
menuGroup = "AudioVideo;Video"
shortcut = true
}
macOS {
packageVersion = project.version.toString().let {
if (it.startsWith("0.")) it.replaceFirst("0.", "1.") else it
}.split("-")[0]
appStore = false
dockName = project.name
setDockNameSameAsPackageName = false
signing {
sign = false
}
iconFile.set(project.file("src/main/resources/icons/icon.icns"))
}
}
}
}
composeCompiler {
featureFlags.add(ComposeFeatureFlag.OptimizeNonSkippingGroups)
}
buildConfig {
val siteURL = System.getenv("STYX_SITEURL")
buildConfigField("APP_NAME", project.name)
buildConfigField("APP_VERSION", provider { "${project.version}" })
buildConfigField("APP_SECRET", System.getenv("STYX_SECRET"))
buildConfigField("BASE_URL", System.getenv("STYX_BASEURL")) // Example: https://api.company.com
buildConfigField("SITE_URL", siteURL) // Example: https://company.com
buildConfigField("IMAGE_URL", System.getenv("STYX_IMAGEURL")) // Example: https://images.company.com
buildConfigField("SITE", siteURL.split("https://").getOrElse(1) { siteURL })
buildConfigField("BUILD_TIME", (System.currentTimeMillis() / 1000))
buildConfigField("VERSION_CHECK_URL", "https://api.github.com/repos/Vodes/Styx-2/tags")
buildConfigField("DISCORD_CLIENT_ID", "686174250259709983")
}
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(21))
vendor.set(JvmVendorSpec.JETBRAINS)
}
}
val optName by lazy { project.name.replace(" ", "-").lowercase() }
val desktopFile by lazy { File(projectDir, "${project.name.replace(" ", "-")}.desktop") }
val cleanupScriptFile by lazy { File(projectDir, "cleanup.sh") }
val buildDir by lazy { File(projectDir, "build") }
val installerOutDir by lazy { Paths.get(buildDir.absolutePath, "compose", "binaries", "installers").toFile().also { it.mkdirs() } }
tasks.register("packageLinuxInstallers") {
dependsOn("packageReleaseUberJarForCurrentOS")
doLast {
val uberJar = Paths.get(buildDir.absolutePath, "compose", "jars").toFile().walkTopDown().find {
it.isFile && it.name.endsWith("-release.jar", true) && it.name.startsWith(project.name, true)
} ?: throw Exception("Could not find UberJar!")
val icon = Paths.get(projectDir.absolutePath, "src").toFile().walkTopDown().find { it.isFile && it.name.equals("icon.png") }
?: throw Exception("Could not find app icon!")
val portableDir = Paths.get(buildDir.absolutePath, "compose", "binaries", "portable").toFile().also { it.mkdirs() }
uberJar.copyTo(File(portableDir, "$optName-all.jar"), overwrite = true)
icon.copyTo(File(portableDir, "icon.png"), overwrite = true)
val jlinkExe =
getExecutableFromPath("jlink") ?: throw Exception("Please install jlink! It should be in some jdk development package on your distro.")
exec {
executable = jlinkExe.absolutePath
args = listOf(
"--add-modules",
jlinkModules.joinToString(","),
"-G",
"--no-header-files",
"--no-man-pages",
"--compress",
"1",
"--output",
File(portableDir, "jvm").absolutePath
)
}
val fpmExe = getExecutableFromPath("fpm") ?: throw Exception("Please install fpm! https://fpm.readthedocs.io/en/v1.14.0/index.html")
createNecessaryInstallerFiles()
val types = listOf("rpm", "deb", "pacman")
types.forEach {
exec {
executable = fpmExe.absolutePath
args(*getFpmArgs(it, "x86_64", portableDir))
}
}
}
}
fun getFpmArgs(type: String, architecture: String, appImageDir: File): Array<String> {
return arrayOf(
"-f",
"-s",
"dir",
"-t",
type,
"-v",
project.version.toString().replace("-", "."),
"-a",
architecture,
"-p",
installerOutDir.absolutePath,
"--after-remove",
cleanupScriptFile.absolutePath,
"--before-upgrade",
cleanupScriptFile.absolutePath,
"--name",
"styx-2",
"--license",
"mpl-2.0",
"-m",
"Vodes & Styx contributors",
"--vendor",
"Vodes & Styx contributors",
"--url",
System.getenv("STYX_SITEURL"),
"${appImageDir.absolutePath}/.=/opt/$optName",
"${desktopFile.absolutePath}=/usr/share/applications/"
)
}
fun createNecessaryInstallerFiles() {
desktopFile.writeText(
"""
[Desktop Entry]
Name=${project.name}
Comment=Your friendly neighborhood anime streaming service
Exec=bash -c "/opt/$optName/jvm/bin/java -Xmx1250M -Xms300M -jar /opt/$optName/$optName-all.jar"
Icon=/opt/$optName/icon.png
Terminal=false
Type=Application
Categories=AudioVideo;Video
MimeType=
""".trimIndent()
)
cleanupScriptFile.writeText("rm -rf /opt/${optName} ; rm -f /usr/share/applications/${desktopFile.name}")
}
fun getExecutableFromPath(name: String): File? {
var name = name
val isWindows = System.getProperty("os.name").contains("win", true)
if (isWindows && !name.contains(".exe"))
name = "$name.exe"
val pathDirs = System.getenv("PATH").split(File.pathSeparator)
.map { File(it) }.filter { it.exists() && it.isDirectory }
return pathDirs.flatMap { it.listFiles()?.asList() ?: listOf() }.find { (if (isWindows) it.name else it.nameWithoutExtension).equals(name, true) }
}