diff --git a/examples/api/src/views/Opener.svelte b/examples/api/src/views/Opener.svelte index 6ffaca88..83e88073 100644 --- a/examples/api/src/views/Opener.svelte +++ b/examples/api/src/views/Opener.svelte @@ -3,20 +3,6 @@ export let onMessage - const programs = [ - 'firefox', - 'google chrome', - 'chromium', - 'safari', - 'open', - 'start', - 'xdg-open', - 'gio', - 'gnome-open', - 'kde-open', - 'wslview' - ] - let url = '' let path = '' let revealPath = '' @@ -25,14 +11,12 @@ let pathProgram = 'Default' function openUrl() { - opener - .openUrl(url, urlProgram === 'Default' ? undefined : urlProgram) - .catch(onMessage) + opener.openUrl(url, urlProgram ? urlProgram : undefined).catch(onMessage) } function openPath() { opener - .openPath(path, pathProgram === 'Default' ? undefined : pathProgram) + .openPath(path, pathProgram ? pathProgram : undefined) .catch(onMessage) } @@ -47,20 +31,13 @@ on:submit|preventDefault={openUrl} > - - with - +
- - with - +
- { +export async function openUrl(url: string, openWith?: string): Promise { await invoke('plugin:opener|open_url', { url, with: openWith @@ -69,21 +54,16 @@ export async function openUrl(url: string, openWith?: Program): Promise { * * // opens a file using the default program: * await openPath('/path/to/file'); - * // opens a file using `start` command on Windows. - * await openPath('C:/path/to/file', 'start'); + * // opens a file using `vlc` command on Windows. + * await openPath('C:/path/to/file', 'vlc'); * ``` * * @param path The path to open. - * @param openWith The app to open the path with. - * Must be one of `firefox`, `google chrome`, `chromium` `safari`, `open`, `start`, `xdg-open`, `gio`, `gnome-open`, `kde-open` or `wslview`. - * If not specified, defaults to the system default application for the specified path type. + * @param openWith The app to open the path with. If not specified, defaults to the system default application for the specified path type. * * @since 2.0.0 */ -export async function openPath( - path: string, - openWith?: Program -): Promise { +export async function openPath(path: string, openWith?: string): Promise { await invoke('plugin:opener|open_path', { path, with: openWith diff --git a/plugins/opener/src/lib.rs b/plugins/opener/src/lib.rs index 8342f1f9..064d50f5 100644 --- a/plugins/opener/src/lib.rs +++ b/plugins/opener/src/lib.rs @@ -6,7 +6,7 @@ use std::path::Path; use tauri::{ plugin::{Builder, TauriPlugin}, - AppHandle, Manager, Runtime, + Manager, Runtime, }; #[cfg(mobile)] @@ -30,8 +30,10 @@ pub use open::{open_path, open_url}; pub use reveal_item_in_dir::reveal_item_in_dir; pub struct Opener { - #[allow(dead_code)] - app: AppHandle, + // we use `fn() -> R` to slicence the unused generic error + // while keeping this struct `Send + Sync` without requiring `R` to be + #[cfg(not(mobile))] + _marker: std::marker::PhantomData R>, #[cfg(mobile)] mobile_plugin_handle: PluginHandle, } @@ -116,7 +118,8 @@ pub fn init() -> TauriPlugin { let handle = _api.register_ios_plugin(init_plugin_opener)?; app.manage(Opener { - app: app.clone(), + #[cfg(not(mobile))] + _marker: std::marker::PhantomData:: R>, #[cfg(mobile)] mobile_plugin_handle: handle, });