Skip to content

Commit 26d1a15

Browse files
authored
fix: migrate some of the codebase to objc2 (#339)
* fix: migrate some of the codebase to objc2 * use workspace dep * fix block2 * fix fig_input_method
1 parent 6d13844 commit 26d1a15

29 files changed

+713
-936
lines changed

Cargo.lock

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ appkit-nsworkspace-bindings = { path = "crates/macos-utils/appkit-nsworkspace-bi
3535
async-trait = "0.1.74"
3636
aws-types = "1.2.0"
3737
base64 = "0.22.1"
38+
block2 = "0.5.1"
3839
bytes = "1.5.0"
3940
bitflags = { version = "2.6.0", features = ["serde"] }
4041
bstr = "1.1.0"
@@ -86,6 +87,10 @@ nix = { version = "0.29.0", features = [
8687
"user",
8788
] }
8889
objc = "0.2.7"
90+
objc2 = "0.5.2"
91+
objc2-app-kit = "0.2.2"
92+
objc2-foundation = "0.2.2"
93+
objc2-input-method-kit = "0.2.2"
8994
once_cell = { version = "1.18.0", features = ["parking_lot"] }
9095
percent-encoding = "2.2.0"
9196
portable-pty = "0.8.1"

crates/fig_desktop/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ core-graphics.workspace = true
136136
libc.workspace = true
137137
macos-utils = { path = "../macos-utils" }
138138
objc.workspace = true
139+
objc2.workspace = true
140+
objc2-app-kit = { workspace = true, features = ["NSApplication"] }
141+
objc2-foundation.workspace = true
139142
system-configuration = "0.6.0"
140-
objc-foundation = "0.1.1"
141-
objc_id = "0.1.1"
142143

143144
[build-dependencies]
144145
image = "0.25.1"

crates/fig_desktop/src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ use webview::{
7171
// #[global_allocator]
7272
// static GLOBAL: Jemalloc = Jemalloc;
7373

74-
#[cfg(target_os = "macos")]
75-
#[macro_use]
76-
extern crate objc;
77-
7874
#[derive(Debug, Default)]
7975
pub struct InterceptState {
8076
pub intercept_bound_keystrokes: RwLock<bool>,

crates/fig_desktop/src/platform/macos.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use macos_utils::window_server::{
4343
UIElement,
4444
};
4545
use macos_utils::{
46-
NSString,
4746
NotificationCenter,
4847
WindowServer,
4948
WindowServerEvent,
@@ -65,6 +64,11 @@ use objc::{
6564
sel,
6665
sel_impl,
6766
};
67+
use objc2_foundation::{
68+
NSDictionary,
69+
NSOperationQueue,
70+
ns_string,
71+
};
6872
use once_cell::sync::Lazy;
6973
use parking_lot::{
7074
Mutex,
@@ -132,8 +136,8 @@ static UNMANAGED: Lazy<Unmanaged> = Lazy::new(|| Unmanaged {
132136
static ACCESSIBILITY_ENABLED: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(accessibility_is_enabled()));
133137

134138
static MACOS_VERSION: Lazy<semver::Version> = Lazy::new(|| {
135-
let version = macos_utils::os::NSOperatingSystemVersion::get();
136-
semver::Version::new(version.major as u64, version.minor as u64, version.patch as u64)
139+
let version = macos_utils::os::OperatingSystemVersion::get();
140+
semver::Version::new(version.major() as u64, version.minor() as u64, version.patch() as u64)
137141
});
138142

139143
pub static ACTIVATION_POLICY: Mutex<ActivationPolicy> = Mutex::new(ActivationPolicy::Regular);
@@ -323,12 +327,9 @@ impl PlatformStateImpl {
323327

324328
let accessibility_proxy = self.proxy.clone();
325329
let mut distributed = NotificationCenter::distributed_center();
326-
let ax_notification_name: NSString = "com.apple.accessibility.api".into();
327-
let queue: id = unsafe {
328-
let queue: id = msg_send![class!(NSOperationQueue), alloc];
329-
msg_send![queue, init]
330-
};
331-
distributed.subscribe(ax_notification_name, Some(queue), move |_| {
330+
let ax_notification_name = ns_string!("com.apple.accessibility.api");
331+
let queue = unsafe { NSOperationQueue::new() };
332+
distributed.subscribe(ax_notification_name, Some(&queue), move |_| {
332333
accessibility_proxy
333334
.clone()
334335
.send_event(Event::PlatformBoundEvent(
@@ -687,8 +688,8 @@ impl PlatformStateImpl {
687688
if !is_xterm && supports_ime {
688689
tracing::debug!("Sending notif com.amazon.codewhisperer.edit_buffer_updated");
689690
NotificationCenter::distributed_center().post_notification(
690-
"com.amazon.codewhisperer.edit_buffer_updated",
691-
std::iter::empty::<(&str, &str)>(),
691+
ns_string!("com.amazon.codewhisperer.edit_buffer_updated"),
692+
&NSDictionary::new(),
692693
);
693694
} else {
694695
let caret = if is_xterm {

crates/fig_desktop_api/src/init_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Constants {
115115
api_proto_url: "api://localhost".to_string(),
116116
midway: midway_cookie_path().map_or(false, |p| p.is_file()),
117117
#[cfg(target_os = "macos")]
118-
macos_version: macos_utils::os::NSOperatingSystemVersion::get().to_string(),
118+
macos_version: macos_utils::os::OperatingSystemVersion::get().to_string(),
119119
#[cfg(target_os = "linux")]
120120
linux: LinuxConstants {
121121
display_server: get_display_server(&fig_os_shim::Context::new()).ok(),

crates/fig_input_method/Cargo.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ toml.workspace = true
2424
apple-bundle = "0.1.4"
2525

2626
[target.'cfg(target_os = "macos")'.dependencies]
27-
objc.workspace = true
28-
cocoa.workspace = true
29-
libc.workspace = true
30-
rand.workspace = true
3127
fig_ipc.workspace = true
3228
fig_log.workspace = true
3329
fig_proto.workspace = true
3430
fig_util.workspace = true
3531
macos-utils = { path = "../macos-utils" }
32+
objc2.workspace = true
33+
objc2-app-kit = { workspace = true, features = [
34+
"NSApplication",
35+
"NSResponder",
36+
] }
37+
objc2-foundation = { workspace = true, features = ["NSThread"] }
38+
objc2-input-method-kit = { workspace = true, features = [
39+
"IMKServer",
40+
"IMKInputController",
41+
] }
3642
tokio.workspace = true
3743
tracing.workspace = true

crates/fig_input_method/Makefile

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)