Mountain/IPC/WindServiceHandlers/NativeDialog/ParseDialogFilters.rs
1//! Parse `options.filters` from a VS Code `showOpenDialog` call into the
2//! `DialogFilter` shape the Tauri dialog plugin accepts. Silently skips
3//! malformed or empty entries - the user still gets the picker, just
4//! without the filter hint.
5
6use serde_json::Value;
7
8use crate::IPC::WindServiceHandlers::NativeDialog::DialogFilter::DialogFilter;
9
10pub fn Fn(Options:&Value) -> Vec<DialogFilter> {
11 Options
12 .get("filters")
13 .and_then(Value::as_array)
14 .map(|Array| {
15 Array
16 .iter()
17 .filter_map(|Entry| {
18 let Name = Entry.get("name").and_then(Value::as_str).unwrap_or("Files").to_string();
19 let Extensions:Vec<String> = Entry
20 .get("extensions")
21 .and_then(Value::as_array)
22 .map(|List| List.iter().filter_map(|V| V.as_str().map(str::to_string)).collect())
23 .unwrap_or_default();
24 if Extensions.is_empty() {
25 None
26 } else {
27 Some(DialogFilter { Name, Extensions })
28 }
29 })
30 .collect()
31 })
32 .unwrap_or_default()
33}