chore: macOS dispatch_async

This commit is contained in:
hstyi
2025-03-14 21:14:20 +08:00
committed by hstyi
parent 1ffaed3f36
commit 9884ed19fa
3 changed files with 3 additions and 40 deletions

View File

@@ -127,7 +127,6 @@ application {
)
if (os.isMacOsX) {
args.add("--add-opens java.desktop/sun.lwawt.macosx.concurrent=ALL-UNNAMED")
args.add("-Dsun.java2d.metal=true")
args.add("-Dapple.awt.application.appearance=system")
}

View File

@@ -1,7 +1,7 @@
package app.termora.native
import app.termora.native.osx.DispatchNative
import com.formdev.flatlaf.util.SystemInfo
import de.jangassen.jfa.ThreadUtils
import de.jangassen.jfa.foundation.Foundation
import jnafilechooser.api.JnaFileChooser
import org.apache.commons.lang3.StringUtils
@@ -94,7 +94,7 @@ class FileChooser {
private fun showMacOSOpenDialog(future: CompletableFuture<List<File>>) {
DispatchNative.getInstance().dispatch_async(object : Runnable {
ThreadUtils.dispatch_async(object : Runnable {
override fun run() {
val pool = Foundation.NSAutoreleasePool()
try {
@@ -170,7 +170,7 @@ class FileChooser {
}
private fun showMacOSSaveDialog(filename: String, future: CompletableFuture<File?>) {
DispatchNative.getInstance().dispatch_async(object : Runnable {
ThreadUtils.dispatch_async(object : Runnable {
override fun run() {
val pool = Foundation.NSAutoreleasePool()
try {

View File

@@ -1,36 +0,0 @@
package app.termora.native.osx
import app.termora.ApplicationScope
import java.lang.reflect.Method
class DispatchNative private constructor() {
companion object {
fun getInstance(): DispatchNative {
return ApplicationScope.forApplicationScope().getOrCreate(DispatchNative::class) { DispatchNative() }
}
}
val dispatch_main_queue: Long
private val nativeExecuteAsync: Method
init {
val clazz = Class.forName("sun.lwawt.macosx.concurrent.LibDispatchNative")
val nativeGetMainQueue = clazz.getDeclaredMethod("nativeGetMainQueue")
nativeGetMainQueue.isAccessible = true
dispatch_main_queue = nativeGetMainQueue.invoke(null) as Long
nativeExecuteAsync = clazz.getDeclaredMethod(
"nativeExecuteAsync",
*arrayOf(Long::class.java, Runnable::class.java)
)
nativeExecuteAsync.isAccessible = true
}
fun dispatch_async(runnable: Runnable) {
nativeExecuteAsync.invoke(null, dispatch_main_queue, runnable)
}
}