Simple tauri app
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
SPDXVersion: SPDX-2.1
|
||||
DataLicense: CC0-1.0
|
||||
PackageName: tauri
|
||||
DataFormat: SPDXRef-1
|
||||
PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy
|
||||
PackageHomePage: https://tauri.app
|
||||
PackageLicenseDeclared: Apache-2.0
|
||||
PackageLicenseDeclared: MIT
|
||||
PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy
|
||||
PackageSummary: <text>Tauri is a rust project that enables developers to make secure
|
||||
and small desktop applications using a web frontend.
|
||||
</text>
|
||||
PackageComment: <text>The package includes the following libraries; see
|
||||
Relationship information.
|
||||
</text>
|
||||
Created: 2019-05-20T09:00:00Z
|
||||
PackageDownloadLocation: git://github.com/tauri-apps/tauri
|
||||
PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git
|
||||
PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git
|
||||
Creator: Person: Daniel Thompson-Yvetot
|
||||
+143
@@ -0,0 +1,143 @@
|
||||

|
||||
|
||||
<!-- description -->
|
||||
|
||||
| Platform | Supported |
|
||||
| -------- | --------- |
|
||||
| Linux | ✓ |
|
||||
| Windows | ✓ |
|
||||
| macOS | ✓ |
|
||||
| Android | ? |
|
||||
| iOS | ? |
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.77.2**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
|
||||
2. Pull sources directly from Github using git tags / revision hashes (most secure)
|
||||
3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
|
||||
|
||||
Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
|
||||
`src-tauri/Cargo.toml`
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-opener = "2.0.0"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-opener = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
||||
|
||||
<!-- Add the branch for installations using git! -->
|
||||
|
||||
```sh
|
||||
pnpm add @tauri-apps/plugin-opener
|
||||
# or
|
||||
npm add @tauri-apps/plugin-opener
|
||||
# or
|
||||
yarn add @tauri-apps/plugin-opener
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
First you need to register the core plugin with Tauri:
|
||||
|
||||
`src-tauri/src/lib.rs`
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { openUrl, openPath, revealItemInDir } from '@tauri-apps/plugin-opener'
|
||||
|
||||
// Opens the URL in the default browser
|
||||
await openUrl('https://example.com')
|
||||
// Or with a specific browser/app
|
||||
await openUrl('https://example.com', 'firefox')
|
||||
|
||||
// Opens the path with the system's default app
|
||||
await openPath('/path/to/file')
|
||||
// Or with a specific app
|
||||
await openPath('/path/to/file', 'firefox')
|
||||
|
||||
// Reveal a path with the system's default explorer
|
||||
await revealItemInDir('/path/to/file')
|
||||
|
||||
// Reveal multiple paths with the system's default explorer
|
||||
// Note: will be renamed to `revealItemsInDir` in the next major version
|
||||
await revealItemInDir(['/path/to/file', '/path/to/another/file'])
|
||||
```
|
||||
|
||||
### Usage from Rust
|
||||
|
||||
You can also use those APIs from Rust:
|
||||
|
||||
```rust
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
let opener = app.opener();
|
||||
|
||||
// Opens the URL in the default browser
|
||||
opener.open_url("https://example.com", None::<&str>)?;
|
||||
// Or with a specific browser/app
|
||||
opener.open_url("https://example.com", Some("firefox"))?;
|
||||
|
||||
// Opens the path with the system's default app
|
||||
opener.open_path("/path/to/file", None::<&str>)?;
|
||||
// Or with a specific app
|
||||
opener.open_path("/path/to/file", Some("firefox"))?;
|
||||
|
||||
// Reveal a path with the system's default explorer
|
||||
opener.reveal_item_in_dir("/path/to/file")?;
|
||||
|
||||
// Reveal multiple paths with the system's default explorer
|
||||
opener.reveal_items_in_dir(["/path/to/file"])?;
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
||||
|
||||
## Partners
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://crabnebula.dev" target="_blank">
|
||||
<img src="https://github.com/tauri-apps/plugins-workspace/raw/v2/.github/sponsors/crabnebula.svg" alt="CrabNebula" width="283">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri).
|
||||
|
||||
## License
|
||||
|
||||
Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
|
||||
|
||||
MIT or MIT/Apache 2.0 where applicable.
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
'use strict';
|
||||
|
||||
var core = require('@tauri-apps/api/core');
|
||||
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
/**
|
||||
* Open files and URLs using their default application.
|
||||
*
|
||||
* ## Security
|
||||
*
|
||||
* This API has a scope configuration that forces you to restrict the files and urls to be opened.
|
||||
*
|
||||
* ### Restricting access to the {@link open | `open`} API
|
||||
*
|
||||
* On the configuration object, `open: true` means that the {@link open} API can be used with any URL,
|
||||
* as the argument is validated with the `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+` regex.
|
||||
* You can change that regex by changing the boolean value to a string, e.g. `open: ^https://github.com/`.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
/**
|
||||
* Opens a url with the system's default app, or the one specified with {@linkcode openWith}.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { openUrl } from '@tauri-apps/plugin-opener';
|
||||
*
|
||||
* // opens the given URL on the default browser:
|
||||
* await openUrl('https://github.com/tauri-apps/tauri');
|
||||
* // opens the given URL using `firefox`:
|
||||
* await openUrl('https://github.com/tauri-apps/tauri', 'firefox');
|
||||
* ```
|
||||
*
|
||||
* @param url The URL to open.
|
||||
* @param openWith The app to open the URL with. If not specified, defaults to the system default application for the specified url type.
|
||||
* On mobile, `openWith` can be provided as `inAppBrowser` to open the URL in an in-app browser. Otherwise, it will open the URL in the system default browser.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function openUrl(url,
|
||||
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
||||
openWith) {
|
||||
await core.invoke('plugin:opener|open_url', {
|
||||
url,
|
||||
with: openWith
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Opens a path with the system's default app, or the one specified with {@linkcode openWith}.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { openPath } from '@tauri-apps/plugin-opener';
|
||||
*
|
||||
* // opens a file using the default program:
|
||||
* await openPath('/path/to/file');
|
||||
* // 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. If not specified, defaults to the system default application for the specified path type.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function openPath(path, openWith) {
|
||||
await core.invoke('plugin:opener|open_path', {
|
||||
path,
|
||||
with: openWith
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Reveal a path with the system's default explorer.
|
||||
*
|
||||
* #### Platform-specific:
|
||||
*
|
||||
* - **Android / iOS:** Unsupported.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { revealItemInDir } from '@tauri-apps/plugin-opener';
|
||||
* await revealItemInDir('/path/to/file');
|
||||
* await revealItemInDir([ '/path/to/file', '/path/to/another/file' ]);
|
||||
* ```
|
||||
*
|
||||
* @param path The path to reveal.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function revealItemInDir(path) {
|
||||
const paths = typeof path === 'string' ? [path] : path;
|
||||
return core.invoke('plugin:opener|reveal_item_in_dir', { paths });
|
||||
}
|
||||
|
||||
exports.openPath = openPath;
|
||||
exports.openUrl = openUrl;
|
||||
exports.revealItemInDir = revealItemInDir;
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Opens a url with the system's default app, or the one specified with {@linkcode openWith}.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { openUrl } from '@tauri-apps/plugin-opener';
|
||||
*
|
||||
* // opens the given URL on the default browser:
|
||||
* await openUrl('https://github.com/tauri-apps/tauri');
|
||||
* // opens the given URL using `firefox`:
|
||||
* await openUrl('https://github.com/tauri-apps/tauri', 'firefox');
|
||||
* ```
|
||||
*
|
||||
* @param url The URL to open.
|
||||
* @param openWith The app to open the URL with. If not specified, defaults to the system default application for the specified url type.
|
||||
* On mobile, `openWith` can be provided as `inAppBrowser` to open the URL in an in-app browser. Otherwise, it will open the URL in the system default browser.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare function openUrl(url: string | URL, openWith?: 'inAppBrowser' | string): Promise<void>;
|
||||
/**
|
||||
* Opens a path with the system's default app, or the one specified with {@linkcode openWith}.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { openPath } from '@tauri-apps/plugin-opener';
|
||||
*
|
||||
* // opens a file using the default program:
|
||||
* await openPath('/path/to/file');
|
||||
* // 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. If not specified, defaults to the system default application for the specified path type.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare function openPath(path: string, openWith?: string): Promise<void>;
|
||||
/**
|
||||
* Reveal a path with the system's default explorer.
|
||||
*
|
||||
* #### Platform-specific:
|
||||
*
|
||||
* - **Android / iOS:** Unsupported.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { revealItemInDir } from '@tauri-apps/plugin-opener';
|
||||
* await revealItemInDir('/path/to/file');
|
||||
* await revealItemInDir([ '/path/to/file', '/path/to/another/file' ]);
|
||||
* ```
|
||||
*
|
||||
* @param path The path to reveal.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare function revealItemInDir(path: string | string[]): Promise<void>;
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
/**
|
||||
* Open files and URLs using their default application.
|
||||
*
|
||||
* ## Security
|
||||
*
|
||||
* This API has a scope configuration that forces you to restrict the files and urls to be opened.
|
||||
*
|
||||
* ### Restricting access to the {@link open | `open`} API
|
||||
*
|
||||
* On the configuration object, `open: true` means that the {@link open} API can be used with any URL,
|
||||
* as the argument is validated with the `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+` regex.
|
||||
* You can change that regex by changing the boolean value to a string, e.g. `open: ^https://github.com/`.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
/**
|
||||
* Opens a url with the system's default app, or the one specified with {@linkcode openWith}.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { openUrl } from '@tauri-apps/plugin-opener';
|
||||
*
|
||||
* // opens the given URL on the default browser:
|
||||
* await openUrl('https://github.com/tauri-apps/tauri');
|
||||
* // opens the given URL using `firefox`:
|
||||
* await openUrl('https://github.com/tauri-apps/tauri', 'firefox');
|
||||
* ```
|
||||
*
|
||||
* @param url The URL to open.
|
||||
* @param openWith The app to open the URL with. If not specified, defaults to the system default application for the specified url type.
|
||||
* On mobile, `openWith` can be provided as `inAppBrowser` to open the URL in an in-app browser. Otherwise, it will open the URL in the system default browser.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function openUrl(url,
|
||||
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
||||
openWith) {
|
||||
await invoke('plugin:opener|open_url', {
|
||||
url,
|
||||
with: openWith
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Opens a path with the system's default app, or the one specified with {@linkcode openWith}.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { openPath } from '@tauri-apps/plugin-opener';
|
||||
*
|
||||
* // opens a file using the default program:
|
||||
* await openPath('/path/to/file');
|
||||
* // 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. If not specified, defaults to the system default application for the specified path type.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function openPath(path, openWith) {
|
||||
await invoke('plugin:opener|open_path', {
|
||||
path,
|
||||
with: openWith
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Reveal a path with the system's default explorer.
|
||||
*
|
||||
* #### Platform-specific:
|
||||
*
|
||||
* - **Android / iOS:** Unsupported.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { revealItemInDir } from '@tauri-apps/plugin-opener';
|
||||
* await revealItemInDir('/path/to/file');
|
||||
* await revealItemInDir([ '/path/to/file', '/path/to/another/file' ]);
|
||||
* ```
|
||||
*
|
||||
* @param path The path to reveal.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function revealItemInDir(path) {
|
||||
const paths = typeof path === 'string' ? [path] : path;
|
||||
return invoke('plugin:opener|reveal_item_in_dir', { paths });
|
||||
}
|
||||
|
||||
export { openPath, openUrl, revealItemInDir };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "@tauri-apps/plugin-opener",
|
||||
"version": "2.5.0",
|
||||
"description": "Open files and URLs using their default application.",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"authors": [
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
],
|
||||
"repository": "https://github.com/tauri-apps/plugins-workspace",
|
||||
"type": "module",
|
||||
"types": "./dist-js/index.d.ts",
|
||||
"main": "./dist-js/index.cjs",
|
||||
"module": "./dist-js/index.js",
|
||||
"exports": {
|
||||
"types": "./dist-js/index.d.ts",
|
||||
"import": "./dist-js/index.js",
|
||||
"require": "./dist-js/index.cjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c"
|
||||
},
|
||||
"files": [
|
||||
"dist-js",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.8.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user