fix: use non-deprecated way

This commit is contained in:
Kagura 2024-11-01 10:08:28 +08:00
parent 008af1f7e3
commit b21b0384e1

View file

@ -8,19 +8,19 @@ import java.io.IOException
import java.net.URI
import java.util.*
fun openBrowser(uri: URI) {
private fun openBrowser(uri: URI) {
val osName by lazy(LazyThreadSafetyMode.NONE) { System.getProperty("os.name").lowercase(Locale.getDefault()) }
val desktop = Desktop.getDesktop()
when {
Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE) -> desktop.browse(uri)
"mac" in osName -> Runtime.getRuntime().exec("open $uri")
"mac" in osName -> Runtime.getRuntime().exec(arrayOf<String>("open",uri.toString()))
"nix" in osName || "nux" in osName -> {
try {
Runtime.getRuntime().exec("xdg-open $uri")
Runtime.getRuntime().exec(arrayOf<String>("xdg-open",uri.toString()))
} catch (_: IOException) {
// xdg-open 不存在
if (File("/run/current-system/sw/bin/xdg-open").exists()) { // nixos
Runtime.getRuntime().exec("/run/current-system/sw/bin/kde-open $uri")
Runtime.getRuntime().exec(arrayOf<String>("/run/current-system/sw/bin/kde-open",uri.toString()))
} else {
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
val content = StringSelection(uri.toString())