|
|
|
@ -4,10 +4,7 @@
|
|
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
use tauri::{
|
|
|
|
|
plugin::{Builder, TauriPlugin},
|
|
|
|
|
Manager, Runtime,
|
|
|
|
|
};
|
|
|
|
|
use tauri::{plugin::TauriPlugin, Manager, Runtime};
|
|
|
|
|
|
|
|
|
|
#[cfg(mobile)]
|
|
|
|
|
use tauri::plugin::PluginHandle;
|
|
|
|
@ -107,10 +104,37 @@ impl<R: Runtime, T: Manager<R>> crate::OpenerExt<R> for T {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Initializes the plugin.
|
|
|
|
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
|
|
|
Builder::new("opener")
|
|
|
|
|
.js_init_script(include_str!("init-iife.js").to_string())
|
|
|
|
|
/// The opener plugin Builder.
|
|
|
|
|
pub struct Builder {
|
|
|
|
|
open_js_links_on_click: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Builder {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
open_js_links_on_click: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Builder {
|
|
|
|
|
/// Create a new opener plugin Builder.
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self::default()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Whether the plugin should inject a JS script to open URLs in default browser
|
|
|
|
|
/// when clicking on `<a>` elements that has `_blank` target, or when pressing `Ctrl` or `Shift` while clicking it.
|
|
|
|
|
///
|
|
|
|
|
/// Enabled by default for `http:`, `https:`, `mailto:`, `tel:` links.
|
|
|
|
|
pub fn open_js_links_on_click(mut self, open: bool) -> Self {
|
|
|
|
|
self.open_js_links_on_click = open;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Build and Initializes the plugin.
|
|
|
|
|
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
|
|
|
|
|
let mut builder = tauri::plugin::Builder::new("opener")
|
|
|
|
|
.setup(|app, _api| {
|
|
|
|
|
#[cfg(target_os = "android")]
|
|
|
|
|
let handle = _api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?;
|
|
|
|
@ -129,6 +153,17 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
|
|
|
commands::open_url,
|
|
|
|
|
commands::open_path,
|
|
|
|
|
commands::reveal_item_in_dir
|
|
|
|
|
])
|
|
|
|
|
.build()
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if self.open_js_links_on_click {
|
|
|
|
|
builder = builder.js_init_script(include_str!("init-iife.js").to_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Initializes the plugin.
|
|
|
|
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
|
|
|
Builder::default().build()
|
|
|
|
|
}
|
|
|
|
|