From 2233edb9a0d9a012d8e590e53d8b66036df0c5f5 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Wed, 9 Aug 2023 15:57:20 +0200 Subject: [PATCH] iOS: Use NSOperatingSystemVersion from icrate (#3019) --- src/platform_impl/ios/app_state.rs | 23 +++++++++++------------ src/platform_impl/ios/ffi.rs | 19 ------------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/platform_impl/ios/app_state.rs b/src/platform_impl/ios/app_state.rs index 9ae2db4b..493e9068 100644 --- a/src/platform_impl/ios/app_state.rs +++ b/src/platform_impl/ios/app_state.rs @@ -16,7 +16,7 @@ use core_foundation::runloop::{ kCFRunLoopCommonModes, CFRunLoopAddTimer, CFRunLoopGetMain, CFRunLoopRef, CFRunLoopTimerCreate, CFRunLoopTimerInvalidate, CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate, }; -use icrate::Foundation::{CGRect, CGSize, NSInteger, NSProcessInfo}; +use icrate::Foundation::{CGRect, CGSize, NSInteger, NSOperatingSystemVersion, NSProcessInfo}; use objc2::rc::Id; use objc2::runtime::AnyObject; use objc2::{msg_send, sel}; @@ -28,10 +28,7 @@ use crate::{ dpi::LogicalSize, event::{Event, InnerSizeWriter, StartCause, WindowEvent}, event_loop::ControlFlow, - platform_impl::platform::{ - event_loop::{EventHandler, EventProxy, EventWrapper, Never}, - ffi::NSOperatingSystemVersion, - }, + platform_impl::platform::event_loop::{EventHandler, EventProxy, EventWrapper, Never}, window::WindowId as RootWindowId, }; @@ -915,7 +912,7 @@ macro_rules! os_capabilities { impl From for 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, } } } @@ -925,7 +922,7 @@ macro_rules! os_capabilities { pub fn $error_name(&self, extra_msg: &str) { log::warn!( 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 ) } @@ -953,10 +950,12 @@ os_capabilities! { force_touch: 9-0, } -impl NSOperatingSystemVersion { - fn meets_requirements(&self, required_major: NSInteger, required_minor: NSInteger) -> bool { - (self.major, self.minor) >= (required_major, required_minor) - } +fn meets_requirements( + version: NSOperatingSystemVersion, + required_major: NSInteger, + required_minor: NSInteger, +) -> bool { + (version.majorVersion, version.minorVersion) >= (required_major, required_minor) } 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. assert!(atleast_ios_8, "`winit` requires iOS version 8 or greater"); - msg_send![&process_info, operatingSystemVersion] + process_info.operatingSystemVersion() }; version.into() }); diff --git a/src/platform_impl/ios/ffi.rs b/src/platform_impl/ios/ffi.rs index 69db70fc..1f57265a 100644 --- a/src/platform_impl/ios/ffi.rs +++ b/src/platform_impl/ios/ffi.rs @@ -7,25 +7,6 @@ use objc2::encode::{Encode, Encoding}; 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)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct UIUserInterfaceIdiom(NSInteger);