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

Use objc2-core-foundation #147

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Added support for tvOS, watchOS and visionOS.

## [0.1.61] - 2024-09-16

### Changed
Expand Down
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ fallback = []
[target.'cfg(target_os = "android")'.dependencies]
android_system_properties = "0.1.5"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation-sys = "0.8.3"
[target.'cfg(target_vendor = "apple")'.dependencies]
objc2-core-foundation = { version = "0.3.0", default-features = false, features = [
"std",
"CFBase",
"CFDate",
"CFString",
"CFTimeZone",
] }

[target.'cfg(target_os = "windows")'.dependencies]
windows-core = { version = ">=0.50, <=0.52" }
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod ffi_utils;

#[cfg_attr(any(target_os = "linux", target_os = "hurd"), path = "tz_linux.rs")]
#[cfg_attr(target_os = "windows", path = "tz_windows.rs")]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), path = "tz_macos.rs")]
#[cfg_attr(target_vendor = "apple", path = "tz_darwin.rs")]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
path = "tz_wasm32_unknown.rs"
Expand All @@ -55,7 +55,7 @@ mod ffi_utils;
#[cfg_attr(target_os = "aix", path = "tz_aix.rs")]
#[cfg_attr(target_os = "android", path = "tz_android.rs")]
#[cfg_attr(target_os = "haiku", path = "tz_haiku.rs")]
mod platform;
mod tz_darwin;

/// Error types
#[derive(Debug)]
Expand Down Expand Up @@ -100,7 +100,7 @@ impl From<std::io::Error> for GetTimezoneError {
/// about this function.
#[inline]
pub fn get_timezone() -> Result<String, GetTimezoneError> {
platform::get_timezone_inner()
tz_darwin::get_timezone_inner()
}

#[cfg(test)]
Expand Down
18 changes: 18 additions & 0 deletions src/tz_darwin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use objc2_core_foundation::{CFTimeZoneCopySystem, CFTimeZoneGetName};

pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
get_timezone().ok_or(crate::GetTimezoneError::OsError)
}

/// Get system time zone, and extract its name.
#[inline]
fn get_timezone() -> Option<String> {
// SAFETY: No invariants to uphold.
// `CFRetained` will take care of memory management.
let tz = unsafe { CFTimeZoneCopySystem() }?;

// SAFETY: No invariants to uphold (the `CFTimeZone` is valid).
let name = unsafe { CFTimeZoneGetName(&tz) }?;

Some(name.to_string())
}
144 changes: 0 additions & 144 deletions src/tz_macos.rs

This file was deleted.