-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cb1dc6
commit a5f8fa4
Showing
13 changed files
with
93 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |