remove AppHandle, Program from ts

pull/2019/head
amrbashir 8 months ago
parent 3b80f1eae2
commit 8ed396f821
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

@ -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}
>
<button class="btn" type="submit">Open URL</button>
<input
class="input grow"
placeholder="Type the URL to open..."
bind:value={url}
/>
<span> with </span>
<select class="input" bind:value={urlProgram}>
<option value="Default">Default</option>
{#each programs as p}
<option value={p}>{p}</option>
{/each}
</select>
<input class="input" bind:value={urlProgram} />
</form>
<form
@ -68,20 +45,13 @@
on:submit|preventDefault={openPath}
>
<button class="btn" type="submit">Open Path</button>
<input
class="input grow"
placeholder="Type the path to open..."
bind:value={path}
/>
<span> with </span>
<select class="input" bind:value={pathProgram}>
<option value="Default">Default</option>
{#each programs as p}
<option value={p}>{p}</option>
{/each}
</select>
<input class="input" bind:value={pathProgram} />
</form>
<form
@ -89,7 +59,6 @@
on:submit|preventDefault={revealItemInDir}
>
<button class="btn" type="submit">Reveal</button>
<input
class="input grow"
placeholder="Type the path to reveal..."

@ -20,19 +20,6 @@
import { invoke } from '@tauri-apps/api/core'
export type Program =
| 'firefox'
| 'google chrome'
| 'chromium'
| 'safari'
| 'open'
| 'start'
| 'xdg-open'
| 'gio'
| 'gnome-open'
| 'kde-open'
| 'wslview'
/**
* Opens a url with the system's default app, or the one specified with {@linkcode openWith}.
*
@ -47,13 +34,11 @@ export type Program =
* ```
*
* @param url The URL to open.
* @param openWith The app to open the URL 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 url type.
* @param openWith The app to open the URL with. If not specified, defaults to the system default application for the specified url type.
*
* @since 2.0.0
*/
export async function openUrl(url: string, openWith?: Program): Promise<void> {
export async function openUrl(url: string, openWith?: string): Promise<void> {
await invoke('plugin:opener|open_url', {
url,
with: openWith
@ -69,21 +54,16 @@ export async function openUrl(url: string, openWith?: Program): Promise<void> {
*
* // 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<void> {
export async function openPath(path: string, openWith?: string): Promise<void> {
await invoke('plugin:opener|open_path', {
path,
with: openWith

@ -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<R: Runtime> {
#[allow(dead_code)]
app: AppHandle<R>,
// 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<fn() -> R>,
#[cfg(mobile)]
mobile_plugin_handle: PluginHandle<R>,
}
@ -116,7 +118,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
let handle = _api.register_ios_plugin(init_plugin_opener)?;
app.manage(Opener {
app: app.clone(),
#[cfg(not(mobile))]
_marker: std::marker::PhantomData::<fn() -> R>,
#[cfg(mobile)]
mobile_plugin_handle: handle,
});

Loading…
Cancel
Save