feat: add init scripts (#361)

This commit is contained in:
Lucas Fernandes Nogueira
2023-05-17 18:25:56 -03:00
committed by GitHub
parent d87b569643
commit 7ae7167fbe
13 changed files with 140 additions and 13 deletions
+4 -4
View File
@@ -271,8 +271,8 @@ pub(crate) async fn ask<R: Runtime>(
title,
message,
type_,
ok_button_label,
cancel_button_label,
Some(ok_button_label.unwrap_or_else(|| "Yes".into())),
Some(cancel_button_label.unwrap_or_else(|| "No".into())),
))
}
@@ -292,7 +292,7 @@ pub(crate) async fn confirm<R: Runtime>(
title,
message,
type_,
ok_button_label,
cancel_button_label,
Some(ok_button_label.unwrap_or_else(|| "Ok".into())),
Some(cancel_button_label.unwrap_or_else(|| "Cancel".into())),
))
}
+15
View File
@@ -0,0 +1,15 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
window.alert = function (message) {
window.__TAURI_INVOKE__('plugin:dialog|message', {
message: message.toString()
})
}
window.confirm = function (message) {
return window.__TAURI_INVOKE__('plugin:dialog|confirm', {
message: message.toString()
})
}
+9 -1
View File
@@ -69,7 +69,15 @@ impl<R: Runtime> Dialog<R> {
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("dialog")
let mut builder = Builder::new("dialog");
// Dialogs are implemented natively on Android
#[cfg(not(target_os = "android"))]
{
builder = builder.js_init_script(include_str!("init.js").to_string());
}
builder
.invoke_handler(tauri::generate_handler![
commands::open,
commands::save,