mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-15 18:02:58 +08:00
chore: macOS dispatch_async
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user