Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions framework-crates/objc2-xc-ui-automation/Cargo.modified.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[target.'cfg(target_os = "ios")'.dependencies]
objc2-ui-kit = { workspace = true, optional = true, features = ["UIOrientation"] }

[features]
objc2-ui-kit = ["dep:objc2-ui-kit"]

# Maybe, unsure if desirable:
default = [
"std",
"block2",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-core-location",
"objc2-ui-kit",
]
3 changes: 3 additions & 0 deletions framework-crates/objc2-xc-ui-automation/Cargo.toml

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

42 changes: 42 additions & 0 deletions framework-crates/objc2-xc-ui-automation/src/device_buttons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
use crate::XCUIDevice;
use objc2::{extern_methods, Encode, Encoding, RefEncode};

#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCUIDeviceButton(pub objc2_foundation::NSInteger);
impl XCUIDeviceButton {
#[doc(alias = "XCUIDeviceButtonHome")]
pub const Home: Self = Self(1);
#[doc(alias = "XCUIDeviceButtonVolumeUp")]
pub const VolumeUp: Self = Self(2);
#[doc(alias = "XCUIDeviceButtonVolumeDown")]
pub const VolumeDown: Self = Self(3);
#[cfg(not(any(target_os = "tvos", target_os = "visionos")))]
#[doc(alias = "XCUIDeviceButtonAction")]
pub const Action: Self = Self(4);
#[cfg(not(any(target_os = "tvos", target_os = "visionos", target_os = "watchos")))]
#[doc(alias = "XCUIDeviceButtonCamera")]
pub const Camera: Self = Self(5);
}

unsafe impl Encode for XCUIDeviceButton {
const ENCODING: Encoding = objc2_foundation::NSInteger::ENCODING;
}

unsafe impl RefEncode for XCUIDeviceButton {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl XCUIDevice {
extern_methods!(
#[unsafe(method(hasHardwareButton:))]
#[unsafe(method_family = none)]
pub fn hasHardwareButton(&self, button: XCUIDeviceButton) -> bool;

/// Simulates the user pressing a physical button.
#[unsafe(method(pressButton:))]
#[unsafe(method_family = none)]
pub fn pressButton(&self, button: XCUIDeviceButton);
);
}
19 changes: 19 additions & 0 deletions framework-crates/objc2-xc-ui-automation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ mod generated;
#[allow(unused_imports, unreachable_pub)]
pub use self::generated::*;

// Everything but macOS.
#[cfg(not(any(target_os = "macos", target_env = "macabi")))]
mod device_buttons;

#[cfg(target_os = "ios")]
mod siri;

#[cfg(all(target_os = "ios", feature = "objc2-ui-kit"))]
mod orientation;

#[cfg(not(target_os = "macos"))]
pub use device_buttons::*;

#[cfg(all(target_os = "ios", feature = "objc2-ui-kit"))]
pub use orientation::*;

#[cfg(target_os = "ios")]
pub use siri::*;

// Link to XCTest instead of XCUIAutomation, since the latter is only
// available in newer Xcode versions.
#[link(name = "XCTest", kind = "framework")]
Expand Down
20 changes: 20 additions & 0 deletions framework-crates/objc2-xc-ui-automation/src/orientation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]

use crate::XCUIDevice;
use objc2::extern_methods;
use objc2_ui_kit::UIDeviceOrientation;

impl XCUIDevice {
extern_methods!(
/// The orientation of the device.
#[unsafe(method(orientation))]
#[unsafe(method_family = none)]
pub fn orientation(&self) -> UIDeviceOrientation;

/// Setter for [`orientation`][Self::orientation].
#[unsafe(method(setOrientation:))]
#[unsafe(method_family = none)]
pub fn setOrientation(&self, orientation: UIDeviceOrientation);
);
}
61 changes: 61 additions & 0 deletions framework-crates/objc2-xc-ui-automation/src/siri.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]

use crate::XCUIDevice;
use objc2::{
extern_class, extern_conformance, extern_methods,
rc::{Allocated, Retained},
runtime::{NSObject, NSObjectProtocol},
MainThreadMarker, MainThreadOnly,
};
use objc2_foundation::NSString;

extern_class!(
/// Represents a device's Siri interface and allows issuing textual queries
/// and producing element queries for UI shown by Siri.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xcuiautomation/xcuisiriservice?language=objc)
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct XCUISiriService;
);
extern_conformance!(
unsafe impl NSObjectProtocol for XCUISiriService {}
);

impl XCUISiriService {
extern_methods!(
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new(mtm: MainThreadMarker) -> Retained<Self>;

#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;

/// Provides debugging information about the element representing the root of the Siri UI.
///
/// See also: XCUIElement
#[unsafe(method(debugDescription))]
#[unsafe(method_family = none)]
pub fn debugDescription(&self) -> Retained<NSString>;

/// Presents the Siri UI, if it is not currently active, and accepts a string
/// which is then processed as if it were recognized speech.
///
///
/// Parameter `text`: The string to pass to Siri for processing.
#[unsafe(method(activateWithVoiceRecognitionText:))]
#[unsafe(method_family = none)]
pub fn activateWithVoiceRecognitionText(&self, text: &NSString);
);
}
impl XCUIDevice {
extern_methods!(
/// Provides access to an object representing the Siri interface on the device.
#[unsafe(method(siriService))]
#[unsafe(method_family = none)]
pub fn siriService(&self) -> Retained<XCUISiriService>;
);
}