electron_sys/module/
app.rs

1use crate::{
2    class::{CommandLine, Dock, Menu},
3    interface::{
4        GetFileIconOptions,
5        GetLoginItemSettings,
6        GetLoginItemSettingsOptions,
7        GpuFeatureStatus,
8        ImportCertificateOptions,
9        JumpListSettings,
10        MoveToApplicationsFolderOptions,
11        RelaunchOptions,
12        SetAboutPanelOptions,
13        SetLoginItemSettings,
14    },
15};
16use js_sys::{Function, JsString, Promise};
17use node_sys::events::EventEmitter;
18use wasm_bindgen::prelude::*;
19
20#[wasm_bindgen(module = "electron")]
21extern {
22    #[wasm_bindgen(extends = EventEmitter)]
23    pub type App;
24
25    pub static app: App;
26
27    //******************//
28    // Instance Methods //
29    //******************//
30
31    #[wasm_bindgen(method)]
32    pub fn quit(this: &App);
33
34    #[wasm_bindgen(method)]
35    pub fn exit(this: &App, exit_code: Option<i32>);
36
37    #[wasm_bindgen(method)]
38    pub fn relaunch(this: &App, options: Option<RelaunchOptions>);
39
40    #[wasm_bindgen(method, js_name = "isReady")]
41    pub fn is_ready(this: &App) -> bool;
42
43    #[must_use]
44    #[wasm_bindgen(method, js_name = "whenReady")]
45    pub fn when_ready(this: &App) -> Promise;
46
47    #[wasm_bindgen(method)]
48    pub fn focus(this: &App);
49
50    #[wasm_bindgen(method)]
51    pub fn hide(this: &App);
52
53    #[wasm_bindgen(method)]
54    pub fn show(this: &App);
55
56    #[wasm_bindgen(method, js_name = "setAppLogsPath")]
57    pub fn set_app_logs_path(this: &App, path: Option<&str>);
58
59    #[wasm_bindgen(method, js_name = "getAppPath")]
60    pub fn get_app_path(this: &App) -> JsString;
61
62    #[wasm_bindgen(method, catch, js_name = "getPath")]
63    pub fn get_path(this: &App) -> Result<JsString, JsValue>;
64
65    #[must_use]
66    #[wasm_bindgen(method, js_name = "getFileIcon")]
67    pub fn get_file_icon(this: &App, path: &str, options: Option<GetFileIconOptions>) -> Promise;
68
69    #[wasm_bindgen(method, catch, js_name = "setPath")]
70    pub fn set_path(this: &App, name: &str, path: &str) -> Result<(), JsValue>;
71
72    #[wasm_bindgen(method, js_name = "getVersion")]
73    pub fn get_version(this: &App) -> JsString;
74
75    #[wasm_bindgen(method, js_name = "getLocale")]
76    pub fn get_locale(this: &App);
77
78    #[wasm_bindgen(method, js_name = "getLocaleCountryCode")]
79    pub fn get_locale_country_code(this: &App);
80
81    #[wasm_bindgen(method, js_name = "addRecentDocument")]
82    pub fn add_recent_document(this: &App, path: &str);
83
84    #[wasm_bindgen(method, js_name = "clearRecentDocuments")]
85    pub fn clear_recent_documents(this: &App);
86
87    #[wasm_bindgen(method, js_name = "setAsDefaultProtocolClient")]
88    pub fn set_as_default_protocol_client(this: &App, protocol: &str, path: Option<&str>, args: &str) -> bool;
89
90    #[wasm_bindgen(method, js_name = "removeAsDefaultProtocolClient")]
91    pub fn remove_as_default_protocol_client(this: &App, protocol: &str, path: Option<&str>, args: &str) -> bool;
92
93    #[wasm_bindgen(method, js_name = "isDefaultProtocolClient")]
94    pub fn is_default_protocol_client(this: &App, protocol: &str, path: Option<&str>, args: &str) -> bool;
95
96    #[wasm_bindgen(method, js_name = "setUserTasks")]
97    pub fn set_user_tasks(this: &App, task: Box<[JsValue]>) -> bool;
98
99    #[wasm_bindgen(method, js_name = "getJumpListSettings")]
100    pub fn get_jump_list_settings(this: &App) -> JumpListSettings;
101
102    #[wasm_bindgen(method, js_name = "setJumpList")]
103    pub fn set_jump_list(this: &App, categories: Option<Box<[JsValue]>>) -> JsString;
104
105    #[wasm_bindgen(method, js_name = "requestSingleInstanceLock")]
106    pub fn request_single_instance_lock(this: &App) -> bool;
107
108    #[wasm_bindgen(method, js_name = "hasSingleInstanceLock")]
109    pub fn has_single_instance_lock(this: &App) -> bool;
110
111    #[wasm_bindgen(method, js_name = "releaseSingleInstanceLock")]
112    pub fn release_single_instance_lock(this: &App);
113
114    #[wasm_bindgen(method, js_name = "setUserActivity")]
115    pub fn set_user_activity(this: &App, user_info: &JsValue, webpage_url: Option<&str>);
116
117    #[wasm_bindgen(method, js_name = "getCurrentActivityType")]
118    pub fn get_current_activity_type(this: &App) -> JsString;
119
120    #[wasm_bindgen(method, js_name = "invalidateCurrentActivity")]
121    pub fn invalidate_current_activity(this: &App);
122
123    #[wasm_bindgen(method, js_name = "resignCurrentActivity")]
124    pub fn resign_current_activity(this: &App);
125
126    #[wasm_bindgen(method, js_name = "updateCurrentActivity")]
127    pub fn update_current_activity(this: &App, kind: &str, user_info: &JsValue);
128
129    #[wasm_bindgen(method, js_name = "setAppUserModelId")]
130    pub fn set_app_user_model_id(this: &App, id: &str);
131
132    #[wasm_bindgen(method, js_name = "importCertificate")]
133    pub fn import_certificate(this: &App, options: ImportCertificateOptions, callback: &Function);
134
135    #[wasm_bindgen(method, js_name = "disableHardwareAcceleration")]
136    pub fn disable_hardware_acceleration(this: &App);
137
138    #[wasm_bindgen(method, js_name = "disableDomainBlockingFor3DAPIs")]
139    pub fn disable_domain_blocking_for_3d_apis(this: &App);
140
141    #[wasm_bindgen(method, js_name = "getAppMetrics")]
142    pub fn get_app_metrics(this: &App) -> Box<[JsValue]>;
143
144    #[wasm_bindgen(method, js_name = "getGPUFeatureStatus")]
145    pub fn get_gpu_feature_status(this: &App) -> GpuFeatureStatus;
146
147    #[must_use]
148    #[wasm_bindgen(method, js_name = "getGPUInfo")]
149    pub fn get_gpu_info(this: &App, info_type: &str) -> Promise;
150
151    #[wasm_bindgen(method, js_name = "isUnityRunning")]
152    pub fn is_unity_running(this: &App) -> bool;
153
154    #[wasm_bindgen(method, js_name = "getLoginItemSettings")]
155    pub fn get_login_item_settings(this: &App, options: Option<GetLoginItemSettingsOptions>) -> GetLoginItemSettings;
156
157    #[wasm_bindgen(method, js_name = "setLoginItemSettings")]
158    pub fn set_login_item_settings(this: &App, settings: Option<SetLoginItemSettings>);
159
160    #[wasm_bindgen(method, js_name = "setAboutPanelOptions")]
161    pub fn set_about_panel_options(this: &App, options: SetAboutPanelOptions);
162
163    #[wasm_bindgen(method, js_name = "isEmojiPanelSupported")]
164    pub fn is_emoji_panel_supported(this: &App);
165
166    #[wasm_bindgen(method, js_name = "showEmojiPanel")]
167    pub fn show_emoji_panel(this: &App);
168
169    #[wasm_bindgen(method, js_name = "startAccessingSecurityScopedResource")]
170    pub fn start_accessing_security_scoped_resource(this: &App, bookmark_data: &str) -> Function;
171
172    #[wasm_bindgen(method, js_name = "enableSandbox")]
173    pub fn enable_sandbox(this: &App);
174
175    #[wasm_bindgen(method, js_name = "isInApplicationsFolder")]
176    pub fn is_in_applications_folder(this: &App) -> bool;
177
178    #[wasm_bindgen(method, js_name = "moveToApplicationsFolder")]
179    pub fn move_to_applications_folder(this: &App, options: Option<MoveToApplicationsFolderOptions>);
180
181    //*********************//
182    // Instance Properties //
183    //*********************//
184
185    #[wasm_bindgen(method, getter, js_name = "accessibilitySupportEnabled")]
186    pub fn accessibility_support_enabled(this: &App) -> bool;
187
188    #[wasm_bindgen(method, setter, js_name = "accessibilitySupportEnabled")]
189    pub fn set_accessibility_support_enabled(this: &App, value: bool);
190
191    #[wasm_bindgen(method, js_name = "showAboutPanel")]
192    pub fn show_about_panel(this: &App);
193
194    #[wasm_bindgen(method, getter, js_name = "applicationMenu")]
195    pub fn application_menu(this: &App) -> Option<Menu>;
196
197    #[wasm_bindgen(method, setter, js_name = "applicationMenu")]
198    pub fn set_application_menu(this: &App, value: Option<Menu>);
199
200    #[wasm_bindgen(method, getter, js_name = "badgeCount")]
201    pub fn badge_count(this: &App);
202
203    #[wasm_bindgen(method, setter, js_name = "badgeCount")]
204    pub fn set_badge_count(this: &App, value: usize);
205
206    #[wasm_bindgen(method, getter, js_name = "commandLine")] // readonly
207    pub fn command_line(this: &App) -> CommandLine;
208
209    #[wasm_bindgen(method, getter)] // readonly
210    pub fn dock(this: &App) -> Dock;
211
212    #[wasm_bindgen(method, getter, js_name = "isPackaged")] // readonly
213    pub fn is_packaged(this: &App) -> bool;
214
215    #[wasm_bindgen(method, getter)]
216    pub fn name(this: &App) -> JsString;
217
218    #[wasm_bindgen(method, setter, js_name = "setName")]
219    pub fn set_name(this: &App, value: JsString);
220
221    #[wasm_bindgen(method, getter, js_name = "userAgentFallback")]
222    pub fn user_agent_fallback(this: &App) -> JsString;
223
224    #[wasm_bindgen(method, setter, js_name = "setUserAgentFallback")]
225    pub fn set_user_agent_fallback(this: &App, value: JsString);
226
227    #[wasm_bindgen(method, getter, js_name = "allowRendererProcessReuse")]
228    pub fn allow_renderer_process_reuse(this: &App) -> bool;
229
230    #[wasm_bindgen(method, setter, js_name = "setAllowRendererProcessReuse")]
231    pub fn set_allow_renderer_process_reuse(this: &App, value: bool);
232}