mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
686a839c96
let's delay logs on simulator to prevent deadlocks - looks like the logging system isn't available when the Rust process starts, and it's freezing the app (simulator only) closes https://github.com/tauri-apps/tauri/issues/12172
43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import SwiftRs
|
|
import Tauri
|
|
import UIKit
|
|
|
|
#if targetEnvironment(simulator)
|
|
var logReady = false
|
|
#else
|
|
var logReady = true
|
|
#endif
|
|
|
|
@_cdecl("tauri_log")
|
|
func log(level: Int, message: NSString) {
|
|
if logReady {
|
|
os_log(level, message)
|
|
} else {
|
|
dispatch_log(level, message)
|
|
}
|
|
}
|
|
|
|
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)
|
|
logReady = true
|
|
}
|
|
}
|
|
|
|
func os_log(_ level: Int, _ message: NSString) {
|
|
switch level {
|
|
case 1: Logger.debug(message as String)
|
|
case 2: Logger.info(message as String)
|
|
case 3: Logger.error(message as String)
|
|
default: break
|
|
}
|
|
}
|