1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//! [![](https://github.com/p1mo/tauri-wasm/blob/main/.github/banner.png)](https://github.com/p1mo/tauri-wasm)
//! # Tauri v2 wasm bindings
//! **Version:** 2.0.0-beta-1


use wasm_bindgen::JsValue;

/// # API bindings
/// 
/// Example
/// ```js, no_run
/// import { getName } from '@tauri-apps/api';
/// ```
/// 
pub mod api {
    /// # App bindings
    #[cfg(feature = "app")]
    pub mod app;
    /// # Core bindings
    #[cfg(feature = "core")]
    pub mod core;
    /// # Dpi bindings
    #[cfg(feature = "dpi")]
    pub mod dpi;
    /// # Event bindings
    #[cfg(feature = "event")]
    pub mod event;
    /// # Menu bindings
    #[cfg(feature = "menu")]
    pub mod menu;
    /// # Mocks bindings
    #[cfg(feature = "mocks")]
    pub mod mocks;
    /// # Path bindings
    #[cfg(feature = "path")]
    pub mod path;
    /// # Tray bindings
    #[cfg(feature = "tray")]
    pub mod tray;
    /// # Webview bindings
    #[cfg(feature = "webview")]
    pub mod webview;
    /// # Window bindings
    #[cfg(feature = "window")]
    pub mod window;
}

/// # Plugin bindings
pub mod plugin {
    /// # Authenticator bindings
    #[cfg(feature = "authenticator")]
    pub mod authenticator;
    /// # Autostart bindings
    #[cfg(feature = "autostart")]
    pub mod autostart;
    /// # Barcode Scanner bindings
    #[cfg(feature = "barcode-scanner")]
    pub mod barcode_scanner;
    /// # Biometric Scanner bindings
    #[cfg(feature = "biometric")]
    pub mod biometric;
    /// # Cli bindings
    #[cfg(feature = "cli")]
    pub mod cli;
    /// # Clipboard Manager bindings
    #[cfg(feature = "clipboard-manager")]
    pub mod clipboard_manager;
    /// # Deep Link bindings
    #[cfg(feature = "deep-link")]
    pub mod deep_link;
    /// # Dialog bindings
    #[cfg(feature = "dialog")]
    pub mod dialog;
    /// # FS bindings
    #[cfg(feature = "fs")]
    pub mod fs;
    /// # Global Shortcut bindings
    #[cfg(feature = "global-shortcut")]
    pub mod global_shortcut;
    /// # Http bindings
    #[cfg(feature = "http")]
    pub mod http;
    /// # Log bindings
    #[cfg(feature = "log")]
    pub mod log;
    /// # Nfc bindings
    #[cfg(feature = "nfc")]
    pub mod nfc;
    /// # Notification bindings
    #[cfg(feature = "notification")]
    pub mod notification;
    /// # OS bindings
    #[cfg(feature = "os")]
    pub mod os;
    /// # Positioner bindings
    #[cfg(feature = "positioner")]
    pub mod positioner;
    /// # Process bindings
    #[cfg(feature = "process")]
    pub mod process;
    /// # Shell bindings
    #[cfg(feature = "shell")]
    pub mod shell;
    /// # Sql bindings
    #[cfg(feature = "sql")]
    pub mod sql;
    /// # Store bindings
    #[cfg(feature = "store")]
    pub mod store;
    /// # Stronghold bindings
    #[cfg(feature = "stronghold")]
    pub mod stronghold;
    /// # Updater bindings
    #[cfg(feature = "updater")]
    pub mod updater;
    /// # Upload bindings
    #[cfg(feature = "upload")]
    pub mod upload;
    /// # Websocket bindings
    #[cfg(feature = "websocket")]
    pub mod websocket;
    /// # Window State bindings
    #[cfg(feature = "window-state")]
    pub mod window_state;
}

/// # JS bindings like `console.log`, `console.error`
//#[cfg(feature = "js")]
pub mod js;



pub type Result<T> = core::result::Result<T, Error>;

#[derive(Clone, Eq, PartialEq, Debug, thiserror::Error)]
pub enum Error {
    #[error("Command returned Error: {0}")]
    Command(String),
    #[error("Failed to parse JSON: {0}")]
    Serde(String),
    #[cfg(any(feature = "event", feature = "window"))]
    #[error("Oneshot cancelled: {0}")]
    OneshotCanceled(#[from] futures::channel::oneshot::Canceled),
    #[cfg(feature = "fs")]
    #[error("Could not convert path to string")]
    Utf8(std::path::PathBuf),
}

impl From<serde_wasm_bindgen::Error> for Error {
    fn from(e: serde_wasm_bindgen::Error) -> Self {
        Self::Serde(e.to_string())
    }
}

impl From<JsValue> for Error {
    fn from(e: JsValue) -> Self {
        Self::Command(format!("{:?}", e))
    }
}

#[cfg(any(feature = "dialog", feature = "window"))]
pub(crate) mod utils {
    pub struct ArrayIterator {
        pos: u32,
        arr: js_sys::Array,
    }

    impl ArrayIterator {
        pub fn new(arr: js_sys::Array) -> Self {
            Self { pos: 0, arr }
        }
    }

    impl Iterator for ArrayIterator {
        type Item = wasm_bindgen::JsValue;

        fn next(&mut self) -> Option<Self::Item> {
            let raw = self.arr.get(self.pos);

            if raw.is_undefined() {
                None
            } else {
                self.pos += 1;

                Some(raw)
            }
        }
    }
}