Skip to content

Commit

Permalink
Merge pull request #2 from eirtools/objc2
Browse files Browse the repository at this point in the history
Use objc2 and objc2-foundation
  • Loading branch information
eirnym authored Oct 21, 2024
2 parents c8d1890 + 77748b7 commit 5f1fea8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ regex = "1"
winapi = { version = "0.3", features = ["winnls"] }

[target.'cfg(target_os = "macos")'.dependencies]
objc = "^0.2"
objc-foundation = "^0.1"
objc2 = "0.5.1"
objc2-foundation = { version = "0.2", features = ["NSLocale", "NSString"] }
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#[macro_use]
extern crate lazy_static;

extern crate regex;
#[cfg(target_os = "macos")]
extern crate objc2;

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

extern crate regex;

use regex::Regex;
use std::borrow::{Borrow,Cow};
Expand Down
17 changes: 6 additions & 11 deletions src/macos.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
//! Inspect macOS system for locale configuration
extern crate objc_foundation;

use super::{LanguageRange, Locale};

use objc::runtime::Object;
use self::objc_foundation::{INSString, NSString};
use objc2_foundation::NSLocale;

pub fn system_locale() -> Option<Locale> {
let locale_identifier = unsafe {
let nslocale = class!(NSLocale);
let current_locale: *mut Object = msg_send![nslocale, currentLocale];
let locale_identifier: *const NSString = msg_send![current_locale, localeIdentifier];
locale_identifier.as_ref().unwrap()
};
Some(Locale::from(LanguageRange::from_unix(locale_identifier.as_str()).unwrap()))
let current_locale = unsafe { NSLocale::currentLocale() };
let locale_identifier = unsafe { current_locale.localeIdentifier() };
Some(Locale::from(
LanguageRange::from_unix(&locale_identifier.to_string()).unwrap(),
))
}

0 comments on commit 5f1fea8

Please sign in to comment.