fix: use non-deprecated way
This commit is contained in:
parent
008af1f7e3
commit
b21b0384e1
1 changed files with 4 additions and 4 deletions
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue