Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrate some of the codebase to objc2 #339

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ appkit-nsworkspace-bindings = { path = "crates/macos-utils/appkit-nsworkspace-bi
async-trait = "0.1.74"
aws-types = "1.2.0"
base64 = "0.22.1"
block2 = "0.5.1"
bytes = "1.5.0"
bitflags = { version = "2.6.0", features = ["serde"] }
bstr = "1.1.0"
Expand Down Expand Up @@ -86,6 +87,10 @@ nix = { version = "0.29.0", features = [
"user",
] }
objc = "0.2.7"
objc2 = "0.5.2"
objc2-app-kit = "0.2.2"
objc2-foundation = "0.2.2"
objc2-input-method-kit = "0.2.2"
once_cell = { version = "1.18.0", features = ["parking_lot"] }
percent-encoding = "2.2.0"
portable-pty = "0.8.1"
Expand Down
5 changes: 3 additions & 2 deletions crates/fig_desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ core-graphics.workspace = true
libc.workspace = true
macos-utils = { path = "../macos-utils" }
objc.workspace = true
objc2.workspace = true
objc2-app-kit = { workspace = true, features = ["NSApplication"] }
objc2-foundation.workspace = true
system-configuration = "0.6.0"
objc-foundation = "0.1.1"
objc_id = "0.1.1"

[build-dependencies]
image = "0.25.1"
4 changes: 0 additions & 4 deletions crates/fig_desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ use webview::{
// #[global_allocator]
// static GLOBAL: Jemalloc = Jemalloc;

#[cfg(target_os = "macos")]
#[macro_use]
extern crate objc;

#[derive(Debug, Default)]
pub struct InterceptState {
pub intercept_bound_keystrokes: RwLock<bool>,
Expand Down
23 changes: 12 additions & 11 deletions crates/fig_desktop/src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use macos_utils::window_server::{
UIElement,
};
use macos_utils::{
NSString,
NotificationCenter,
WindowServer,
WindowServerEvent,
Expand All @@ -65,6 +64,11 @@ use objc::{
sel,
sel_impl,
};
use objc2_foundation::{
NSDictionary,
NSOperationQueue,
ns_string,
};
use once_cell::sync::Lazy;
use parking_lot::{
Mutex,
Expand Down Expand Up @@ -132,8 +136,8 @@ static UNMANAGED: Lazy<Unmanaged> = Lazy::new(|| Unmanaged {
static ACCESSIBILITY_ENABLED: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(accessibility_is_enabled()));

static MACOS_VERSION: Lazy<semver::Version> = Lazy::new(|| {
let version = macos_utils::os::NSOperatingSystemVersion::get();
semver::Version::new(version.major as u64, version.minor as u64, version.patch as u64)
let version = macos_utils::os::OperatingSystemVersion::get();
semver::Version::new(version.major() as u64, version.minor() as u64, version.patch() as u64)
});

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

let accessibility_proxy = self.proxy.clone();
let mut distributed = NotificationCenter::distributed_center();
let ax_notification_name: NSString = "com.apple.accessibility.api".into();
let queue: id = unsafe {
let queue: id = msg_send![class!(NSOperationQueue), alloc];
msg_send![queue, init]
};
distributed.subscribe(ax_notification_name, Some(queue), move |_| {
let ax_notification_name = ns_string!("com.apple.accessibility.api");
let queue = unsafe { NSOperationQueue::new() };
distributed.subscribe(ax_notification_name, Some(&queue), move |_| {
accessibility_proxy
.clone()
.send_event(Event::PlatformBoundEvent(
Expand Down Expand Up @@ -687,8 +688,8 @@ impl PlatformStateImpl {
if !is_xterm && supports_ime {
tracing::debug!("Sending notif com.amazon.codewhisperer.edit_buffer_updated");
NotificationCenter::distributed_center().post_notification(
"com.amazon.codewhisperer.edit_buffer_updated",
std::iter::empty::<(&str, &str)>(),
ns_string!("com.amazon.codewhisperer.edit_buffer_updated"),
&NSDictionary::new(),
);
} else {
let caret = if is_xterm {
Expand Down
2 changes: 1 addition & 1 deletion crates/fig_desktop_api/src/init_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Constants {
api_proto_url: "api://localhost".to_string(),
midway: midway_cookie_path().map_or(false, |p| p.is_file()),
#[cfg(target_os = "macos")]
macos_version: macos_utils::os::NSOperatingSystemVersion::get().to_string(),
macos_version: macos_utils::os::OperatingSystemVersion::get().to_string(),
#[cfg(target_os = "linux")]
linux: LinuxConstants {
display_server: get_display_server(&fig_os_shim::Context::new()).ok(),
Expand Down
14 changes: 10 additions & 4 deletions crates/fig_input_method/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ toml.workspace = true
apple-bundle = "0.1.4"

[target.'cfg(target_os = "macos")'.dependencies]
objc.workspace = true
cocoa.workspace = true
libc.workspace = true
rand.workspace = true
fig_ipc.workspace = true
fig_log.workspace = true
fig_proto.workspace = true
fig_util.workspace = true
macos-utils = { path = "../macos-utils" }
objc2.workspace = true
objc2-app-kit = { workspace = true, features = [
"NSApplication",
"NSResponder",
] }
objc2-foundation = { workspace = true, features = ["NSThread"] }
objc2-input-method-kit = { workspace = true, features = [
"IMKServer",
"IMKInputController",
] }
tokio.workspace = true
tracing.workspace = true
22 changes: 0 additions & 22 deletions crates/fig_input_method/Makefile

This file was deleted.

Loading
Loading