Skip to content

Commit

Permalink
Don't run jextract on non-Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Aug 30, 2023
1 parent 2cb1dc6 commit a5f8fa4
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 74 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ jobs:
run: |
Invoke-WebRequest https://download.java.net/java/early_access/jextract/1/openjdk-20-jextract+1-2_windows-x64_bin.tar.gz -OutFile jextract.tar.gz
tar xzvf jextract.tar.gz
- name: Setup jextract
if: matrix.os != 'windows-latest'
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
curl -L https://download.java.net/java/early_access/jextract/1/openjdk-20-jextract+1-2_macos-x64_bin.tar.gz -o jextract.tar.gz
else
curl -L https://download.java.net/java/early_access/jextract/1/openjdk-20-jextract+1-2_linux-x64_bin.tar.gz -o jextract.tar.gz
fi
tar xzvf jextract.tar.gz
- name: Setup MacOS signing
if: matrix.os == 'macos-latest'
Expand Down
39 changes: 31 additions & 8 deletions app/desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,43 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.org.jline.utils.OSUtils

plugins {
kotlin("jvm")
kotlin("multiplatform")
kotlin("plugin.serialization")
id("org.jetbrains.compose")
}

dependencies {
implementation(projects.app.shared)
implementation(projects.app.desktop.uwpHelper)
implementation(compose.desktop.currentOs)
implementation(libs.logback)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.cors)
kotlin {
jvm()

sourceSets {
val windowsMain by creating {
dependsOn(commonMain.get())
dependencies {
implementation(projects.app.desktop.uwpHelper)
}
}
val nonWindowsMain by creating {
dependsOn(commonMain.get())
}

named("jvmMain") {
if (OSUtils.IS_WINDOWS) {
dependsOn(windowsMain)
} else {
dependsOn(nonWindowsMain)
}
dependencies {
implementation(projects.app.shared)
implementation(project.dependencies.compose.desktop.currentOs)
implementation(libs.logback)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.cors)
}
}
}
}


compose.desktop {
application {
mainClass = "dev.schlaubi.tonbrett.app.desktop.MainKt"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun main(reAuthorize: Boolean, uwp: Boolean = false, onAuth: () -> Unit) {
} else {
Route.Auth.Type.APP
}
browseUrl(href(Route.Auth(protocol), URLBuilder(getUrl())).build().toURI())
launchUri(href(Route.Auth(protocol), URLBuilder(getUrl())).build().toURI())
if (!uwp) {
startAuthorizationServer(reAuthorize, onAuth)
} else {
Expand Down Expand Up @@ -96,7 +96,7 @@ fun startApplication(uwp: Boolean) = application {
) {
Text(strings.needsUpdate, color = ColorScheme.textColor)
Button({
browseUrl(URI("https://github.com/DRSchlaubi/tonbrett/releases/latest"))
launchUri(URI("https://github.com/DRSchlaubi/tonbrett/releases/latest"))
exitApplication()
}) {
Icon(Icons.Default.Refresh, null)
Expand Down
17 changes: 17 additions & 0 deletions app/desktop/src/commonMain/kotlin/NativeUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.schlaubi.tonbrett.app.desktop

import java.net.URI

/**
* Tries to launch the URI using the UWP `Launcher`.
*
* @param uri the [URI] to launch
*/
expect fun launchUri(uri: URI)

/**
* Tries to retrieve the current UWP app data folder.
*
* @return the absolute path to the folder
*/
expect fun getAppDataRoaming(): String
File renamed without changes.
File renamed without changes
37 changes: 0 additions & 37 deletions app/desktop/src/main/kotlin/NativeUtil.kt

This file was deleted.

17 changes: 0 additions & 17 deletions app/desktop/src/main/kotlin/URIUtil.kt

This file was deleted.

16 changes: 16 additions & 0 deletions app/desktop/src/nonWindowsMain/kotlin/NativeUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.schlaubi.tonbrett.app.desktop

import java.awt.Desktop
import java.net.URI

actual fun launchUri(uri: URI) {
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri)
} else {
Runtime.getRuntime().exec(arrayOf("xdg-open", uri.toString()))
}
}

actual fun getAppDataRoaming(): String =
throw UnsupportedOperationException("This function is only supported on Windows")
27 changes: 27 additions & 0 deletions app/desktop/src/windowsMain/kotlin/NativeUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.schlaubi.tonbrett.app.desktop

import dev.schlaubi.tonbrett.app.desktop.uwp_helper.AppDataRoamingResult
import dev.schlaubi.tonbrett.app.desktop.uwp_helper.UwpHelper.*
import java.lang.foreign.Arena
import java.net.URI

actual fun launchUri(uri: URI): Unit = Arena.openConfined().use { arena ->
val url = arena.allocateUtf8String(uri.toString())
launch_uri(url)
}

actual fun getAppDataRoaming(): String =
Arena.openConfined().use { arena ->
val result = get_app_data_roaming(arena)
val isError = AppDataRoamingResult.`is_error$get`(result)
val length = AppDataRoamingResult.`length$get`(result).coerceAtLeast(0)
val buffer = arena.allocateArray(uint16_t, length)
copy_string_from_get_app_data_roaming_result_into_buffer(result, buffer)
val shortArray = buffer.toArray(uint16_t)
val charArray = CharArray(shortArray.size)
for ((index, short) in shortArray.withIndex()) {
charArray[index] = short.toInt().toChar()
}
val string = String(charArray)
if (isError) throw Exception(string) else string
}

0 comments on commit a5f8fa4

Please sign in to comment.