mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
[log] Use objc2 (#2344)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"log": patch
|
||||
"log-js": patch
|
||||
---
|
||||
|
||||
Use `objc2` instead of `objc`.
|
||||
Generated
+2
-2
@@ -6645,10 +6645,10 @@ version = "2.2.0"
|
||||
dependencies = [
|
||||
"android_logger",
|
||||
"byte-unit",
|
||||
"cocoa",
|
||||
"fern",
|
||||
"log",
|
||||
"objc",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
|
||||
@@ -39,8 +39,11 @@ android_logger = "0.14"
|
||||
|
||||
[target."cfg(target_os = \"ios\")".dependencies]
|
||||
swift-rs = "1"
|
||||
objc = "0.2"
|
||||
cocoa = "0.26"
|
||||
objc2 = "0.5"
|
||||
objc2-foundation = { version = "0.2", default-features = false, features = [
|
||||
"std",
|
||||
"NSString",
|
||||
] }
|
||||
|
||||
[features]
|
||||
colored = ["fern/colored"]
|
||||
|
||||
+6
-26
@@ -35,31 +35,6 @@ pub const WEBVIEW_TARGET: &str = "webview";
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
mod ios {
|
||||
use cocoa::base::id;
|
||||
use objc::*;
|
||||
|
||||
const UTF8_ENCODING: usize = 4;
|
||||
pub struct NSString(pub id);
|
||||
|
||||
impl NSString {
|
||||
pub fn new(s: &str) -> Self {
|
||||
// Safety: objc runtime calls are unsafe
|
||||
NSString(unsafe {
|
||||
let ns_string: id = msg_send![class!(NSString), alloc];
|
||||
let ns_string: id = msg_send![ns_string,
|
||||
initWithBytes:s.as_ptr()
|
||||
length:s.len()
|
||||
encoding:UTF8_ENCODING];
|
||||
|
||||
// The thing is allocated in rust, the thing must be set to autorelease in rust to relinquish control
|
||||
// or it can not be released correctly in OC runtime
|
||||
let _: () = msg_send![ns_string, autorelease];
|
||||
|
||||
ns_string
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
swift_rs::swift!(pub fn tauri_log(
|
||||
level: u8, message: *const std::ffi::c_void
|
||||
));
|
||||
@@ -429,7 +404,12 @@ impl Builder {
|
||||
log::Level::Info => 2,
|
||||
log::Level::Warn | log::Level::Error => 3,
|
||||
},
|
||||
ios::NSString::new(message.as_str()).0 as _,
|
||||
// The string is allocated in rust, so we must
|
||||
// autorelease it rust to give it to the Swift
|
||||
// runtime.
|
||||
objc2::rc::Retained::autorelease_ptr(
|
||||
objc2_foundation::NSString::from_str(message.as_str()),
|
||||
) as _,
|
||||
);
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user