|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
import SwiftRs
|
|
|
|
|
import Tauri
|
|
|
|
|
import UIKit
|
|
|
|
|
import os.log
|
|
|
|
|
|
|
|
|
|
#if targetEnvironment(simulator)
|
|
|
|
|
var logReady = false
|
|
|
|
@ -12,24 +13,39 @@ import UIKit
|
|
|
|
|
var logReady = true
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
var pendingLogs: [(Int, NSString)] = []
|
|
|
|
|
var elapsedTime: TimeInterval = 0
|
|
|
|
|
var logFlushScheduled = false
|
|
|
|
|
|
|
|
|
|
@_cdecl("tauri_log")
|
|
|
|
|
func log(level: Int, message: NSString) {
|
|
|
|
|
if logReady {
|
|
|
|
|
os_log(level, message)
|
|
|
|
|
} else {
|
|
|
|
|
dispatch_log(level, message)
|
|
|
|
|
pendingLogs.append((level, message))
|
|
|
|
|
scheduleLogFlush()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dispatch_log(_ level: Int, _ message: NSString) {
|
|
|
|
|
// delay logging when the logger isn't immediately available
|
|
|
|
|
// in some cases when using the simulator the app would hang when calling os_log too soon
|
|
|
|
|
// better be safe here and wait a few seconds than actually freeze the app in dev mode
|
|
|
|
|
// in production this isn't a problem
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
|
|
|
|
os_log(level, message)
|
|
|
|
|
// delay logging when the logger isn't immediately available
|
|
|
|
|
// in some cases when using the simulator the app would hang when calling os_log too soon
|
|
|
|
|
// better be safe here and wait a few seconds than actually freeze the app in dev mode
|
|
|
|
|
// in production this isn't a problem
|
|
|
|
|
func scheduleLogFlush() {
|
|
|
|
|
guard !logFlushScheduled else { return }
|
|
|
|
|
logFlushScheduled = true
|
|
|
|
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
|
|
|
|
|
logReady = true
|
|
|
|
|
flushLogs()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func flushLogs() {
|
|
|
|
|
for (level, message) in pendingLogs {
|
|
|
|
|
os_log(level, message)
|
|
|
|
|
}
|
|
|
|
|
pendingLogs.removeAll()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func os_log(_ level: Int, _ message: NSString) {
|
|
|
|
|