Skip to content

Commit e0840a7

Browse files
committed
feat(uikit): media
1 parent a6f8c77 commit e0840a7

3 files changed

Lines changed: 285 additions & 45 deletions

File tree

winio-ui-ui-kit/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ objc2-ui-kit = { workspace = true, features = [
3535
"objc2-uniform-type-identifiers",
3636
] }
3737
objc2-uniform-type-identifiers = { workspace = true }
38+
objc2-av-foundation = { workspace = true, features = [
39+
"objc2-core-media",
40+
], optional = true }
41+
objc2-core-media = { workspace = true, optional = true }
3842
objc2-web-kit = { workspace = true, optional = true }
3943

4044
[features]
41-
media = []
45+
media = ["dep:objc2-av-foundation", "dep:objc2-core-media"]
4246
webview = ["dep:objc2-web-kit"]
4347

4448
compio-compat = ["compio/compat-futures"]

winio-ui-ui-kit/src/ui/filebox.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use objc2::{
77
};
88
use objc2_foundation::{NSArray, NSObject, NSObjectProtocol, NSString, NSURL};
99
use objc2_ui_kit::{UIDocumentPickerDelegate, UIDocumentPickerViewController};
10-
use objc2_uniform_type_identifiers::UTType;
10+
use objc2_uniform_type_identifiers::{UTType, UTTypeData};
1111
use winio_callback::Callback;
1212
use winio_handle::AsWindow;
1313

@@ -87,21 +87,23 @@ async fn filebox(
8787
) -> Result<Vec<PathBuf>> {
8888
let mtm = MainThreadMarker::new().ok_or(Error::NotMainThread)?;
8989
let delegate = catch(|| {
90-
let ns_filters = NSArray::from_retained_slice(
91-
&filters
92-
.into_iter()
93-
.filter_map(|f| {
94-
let pattern = f.pattern;
95-
if pattern == "*.*" || pattern == "*" {
96-
None
97-
} else {
98-
UTType::typeWithFilenameExtension(&NSString::from_str(
99-
pattern.strip_prefix("*.").unwrap_or(&pattern),
100-
))
101-
}
102-
})
103-
.collect::<Vec<_>>(),
104-
);
90+
let mut ns_filters = filters
91+
.into_iter()
92+
.filter_map(|f| {
93+
let pattern = f.pattern;
94+
if pattern == "*.*" || pattern == "*" {
95+
Some(unsafe { UTTypeData.retain() })
96+
} else {
97+
UTType::typeWithFilenameExtension(&NSString::from_str(
98+
pattern.strip_prefix("*.").unwrap_or(&pattern),
99+
))
100+
}
101+
})
102+
.collect::<Vec<_>>();
103+
if ns_filters.is_empty() {
104+
ns_filters.push(unsafe { UTTypeData.retain() });
105+
}
106+
let ns_filters = NSArray::from_retained_slice(&ns_filters);
105107
let browser =
106108
UIDocumentPickerViewController::initForOpeningContentTypes(mtm.alloc(), &ns_filters);
107109
browser.setAllowsMultipleSelection(multiple);

0 commit comments

Comments
 (0)