iOS: Use NSOperatingSystemVersion from icrate (#3019)

This commit is contained in:
Fredrik Fornwall 2023-08-09 15:57:20 +02:00 committed by GitHub
parent bd2f1e8312
commit 2233edb9a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 31 deletions

View file

@ -16,7 +16,7 @@ use core_foundation::runloop::{
kCFRunLoopCommonModes, CFRunLoopAddTimer, CFRunLoopGetMain, CFRunLoopRef, CFRunLoopTimerCreate, kCFRunLoopCommonModes, CFRunLoopAddTimer, CFRunLoopGetMain, CFRunLoopRef, CFRunLoopTimerCreate,
CFRunLoopTimerInvalidate, CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate, CFRunLoopTimerInvalidate, CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate,
}; };
use icrate::Foundation::{CGRect, CGSize, NSInteger, NSProcessInfo}; use icrate::Foundation::{CGRect, CGSize, NSInteger, NSOperatingSystemVersion, NSProcessInfo};
use objc2::rc::Id; use objc2::rc::Id;
use objc2::runtime::AnyObject; use objc2::runtime::AnyObject;
use objc2::{msg_send, sel}; use objc2::{msg_send, sel};
@ -28,10 +28,7 @@ use crate::{
dpi::LogicalSize, dpi::LogicalSize,
event::{Event, InnerSizeWriter, StartCause, WindowEvent}, event::{Event, InnerSizeWriter, StartCause, WindowEvent},
event_loop::ControlFlow, event_loop::ControlFlow,
platform_impl::platform::{ platform_impl::platform::event_loop::{EventHandler, EventProxy, EventWrapper, Never},
event_loop::{EventHandler, EventProxy, EventWrapper, Never},
ffi::NSOperatingSystemVersion,
},
window::WindowId as RootWindowId, window::WindowId as RootWindowId,
}; };
@ -915,7 +912,7 @@ macro_rules! os_capabilities {
impl From<NSOperatingSystemVersion> for OSCapabilities { impl From<NSOperatingSystemVersion> for OSCapabilities {
fn from(os_version: NSOperatingSystemVersion) -> OSCapabilities { fn from(os_version: NSOperatingSystemVersion) -> OSCapabilities {
$(let $name = os_version.meets_requirements($major, $minor);)* $(let $name = meets_requirements(os_version, $major, $minor);)*
OSCapabilities { $($name,)* os_version, } OSCapabilities { $($name,)* os_version, }
} }
} }
@ -925,7 +922,7 @@ macro_rules! os_capabilities {
pub fn $error_name(&self, extra_msg: &str) { pub fn $error_name(&self, extra_msg: &str) {
log::warn!( log::warn!(
concat!("`", $objc_call, "` requires iOS {}.{}+. This device is running iOS {}.{}.{}. {}"), concat!("`", $objc_call, "` requires iOS {}.{}+. This device is running iOS {}.{}.{}. {}"),
$major, $minor, self.os_version.major, self.os_version.minor, self.os_version.patch, $major, $minor, self.os_version.majorVersion, self.os_version.minorVersion, self.os_version.patchVersion,
extra_msg extra_msg
) )
} }
@ -953,10 +950,12 @@ os_capabilities! {
force_touch: 9-0, force_touch: 9-0,
} }
impl NSOperatingSystemVersion { fn meets_requirements(
fn meets_requirements(&self, required_major: NSInteger, required_minor: NSInteger) -> bool { version: NSOperatingSystemVersion,
(self.major, self.minor) >= (required_major, required_minor) required_major: NSInteger,
} required_minor: NSInteger,
) -> bool {
(version.majorVersion, version.minorVersion) >= (required_major, required_minor)
} }
pub fn os_capabilities() -> OSCapabilities { pub fn os_capabilities() -> OSCapabilities {
@ -975,7 +974,7 @@ pub fn os_capabilities() -> OSCapabilities {
// //
// The minimum required iOS version is likely to grow in the future. // The minimum required iOS version is likely to grow in the future.
assert!(atleast_ios_8, "`winit` requires iOS version 8 or greater"); assert!(atleast_ios_8, "`winit` requires iOS version 8 or greater");
msg_send![&process_info, operatingSystemVersion] process_info.operatingSystemVersion()
}; };
version.into() version.into()
}); });

View file

@ -7,25 +7,6 @@ use objc2::encode::{Encode, Encoding};
use crate::platform::ios::{Idiom, ScreenEdge}; use crate::platform::ios::{Idiom, ScreenEdge};
#[repr(C)]
#[derive(Clone, Debug)]
pub struct NSOperatingSystemVersion {
pub major: NSInteger,
pub minor: NSInteger,
pub patch: NSInteger,
}
unsafe impl Encode for NSOperatingSystemVersion {
const ENCODING: Encoding = Encoding::Struct(
"NSOperatingSystemVersion",
&[
NSInteger::ENCODING,
NSInteger::ENCODING,
NSInteger::ENCODING,
],
);
}
#[repr(transparent)] #[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UIUserInterfaceIdiom(NSInteger); pub struct UIUserInterfaceIdiom(NSInteger);