Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tauri-plugin-opener #2019

Merged
merged 36 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
38369c8
[WIP] create tauri-plugin-opener
amrbashir Nov 7, 2024
42ab44c
migrate to using scope
amrbashir Nov 7, 2024
b9ced54
clippy
amrbashir Nov 7, 2024
6766bfd
add show_item_in_dir (windows impl)
amrbashir Nov 7, 2024
67c8f42
reveal_item_in_dir (linux impl)
amrbashir Nov 7, 2024
73959f5
macos impl
amrbashir Nov 7, 2024
fe2fdee
1.0.0 & major in change file
amrbashir Nov 7, 2024
8555563
lock file and licenese headers
amrbashir Nov 7, 2024
5399e54
implement revealItemInDir in JS
amrbashir Nov 7, 2024
f7244d5
Merge branch 'v2' into feat/plugin-opener
amrbashir Nov 12, 2024
5158101
remove regex and urlpattern deps
amrbashir Nov 12, 2024
a24915e
error msg
amrbashir Nov 12, 2024
7f7f3e4
lock file
amrbashir Nov 12, 2024
eb88ad5
try to fix CI
amrbashir Nov 12, 2024
f3a5f88
fmt
amrbashir Nov 12, 2024
f5da785
update window crate
amrbashir Nov 12, 2024
adf4d52
strong type openWith paramter
amrbashir Nov 12, 2024
bcc6c09
split into openUrl and openPath
amrbashir Nov 12, 2024
e0264cc
refactor init script
amrbashir Nov 12, 2024
9594639
fmt
amrbashir Nov 12, 2024
47a5c85
Merge branch 'v2' into feat/plugin-opener
amrbashir Nov 12, 2024
6d62ec7
update example
amrbashir Nov 13, 2024
ec35bf3
fix evt.ctrlKey and evt.shiftKey
amrbashir Nov 13, 2024
7cd8b23
simplify and fix leak
amrbashir Nov 13, 2024
5df1e4b
remove lefover
amrbashir Nov 14, 2024
b696024
fix example, fix linux, document
amrbashir Nov 14, 2024
768e3ec
remove `Program` enum
amrbashir Nov 14, 2024
3f66dbd
Merge branch 'v2' into feat/plugin-opener
amrbashir Nov 14, 2024
3b80f1e
remove middle click comment
amrbashir Nov 14, 2024
8ed396f
remove AppHandle, Program from ts
amrbashir Nov 14, 2024
30dcce8
fix permissions error
amrbashir Nov 14, 2024
ff17c5d
Update plugins/opener/src/scope_entry.rs
amrbashir Nov 14, 2024
ac467fe
Merge branch 'v2' into feat/plugin-opener
amrbashir Nov 14, 2024
3a54f2f
fix fallback
amrbashir Nov 18, 2024
955697a
Merge branch 'v2' into feat/plugin-opener
amrbashir Nov 18, 2024
23143e9
add option to configure global script behavior
amrbashir Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"dialog",
"fs",
"global-shortcut",
"opener",
"http",
"nfc",
"notification",
Expand All @@ -87,6 +88,7 @@
"dialog-js",
"fs-js",
"global-shortcut-js",
"opener-js",
"http-js",
"nfc-js",
"notification-js",
Expand Down Expand Up @@ -186,6 +188,14 @@
"path": "./plugins/global-shortcut",
"manager": "javascript"
},
"opener": {
"path": "./plugins/opener",
"manager": "rust"
},
"opener-js": {
"path": "./plugins/opener",
"manager": "javascript"
},
"haptics": {
"path": "./plugins/haptics",
"manager": "rust"
Expand Down
6 changes: 6 additions & 0 deletions .changes/opener-initial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"opener": "major"
"opener-js": "major"
---

Initial Release
4 changes: 4 additions & 0 deletions .github/workflows/check-generated-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ jobs:
- .github/workflows/check-generated-files.yml
- plugins/global-shortcut/guest-js/**
- plugins/global-shortcut/src/api-iife.js
opener:
- .github/workflows/check-generated-files.yml
- plugins/opener/guest-js/**
- plugins/opener/src/api-iife.js
haptics:
- .github/workflows/check-generated-files.yml
- plugins/haptics/guest-js/**
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ jobs:
tauri-plugin-global-shortcut:
- .github/workflows/lint-rust.yml
- plugins/global-shortcut/**
tauri-plugin-opener:
- .github/workflows/lint-rust.yml
- plugins/opener/**
tauri-plugin-haptics:
- .github/workflows/lint-rust.yml
- plugins/haptics/**
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ jobs:
- .github/workflows/test-rust.yml
- Cargo.toml
- plugins/global-shortcut/**
tauri-plugin-opener:
- .github/workflows/test-rust.yml
- Cargo.toml
- plugins/opener/**
tauri-plugin-haptics:
- .github/workflows/test-rust.yml
- Cargo.toml
Expand Down
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ url = "2"
schemars = "0.8"
dunce = "1"
specta = "=2.0.0-rc.20"
glob = "0.3"
zbus = "4"
#tauri-specta = "=2.0.0-rc.11"

[workspace.package]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This repo and all plugins require a Rust version of at least **1.77.2**
| [log](plugins/log) | Configurable logging. | ✅ | ✅ | ✅ | ✅ | ✅ |
| [nfc](plugins/nfc) | Read and write NFC tags on Android and iOS. | ? | ? | ? | ✅ | ✅ |
| [notification](plugins/notification) | Send message notifications (brief auto-expiring OS window element) to your user. Can also be used with the Notification Web API. | ✅ | ✅ | ✅ | ✅ | ✅ |
| [opener](plugins/opener) | Open files and URLs using their default application. | ✅ | ✅ | ✅ | ? | ? |
| [os](plugins/os) | Read information about the operating system. | ✅ | ✅ | ✅ | ✅ | ✅ |
| [persisted-scope](plugins/persisted-scope) | Persist runtime scope changes on the filesystem. | ✅ | ✅ | ✅ | ? | ? |
| [positioner](plugins/positioner) | Move windows to common locations. | ✅ | ✅ | ✅ | ❌ | ❌ |
Expand Down
1 change: 1 addition & 0 deletions examples/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@tauri-apps/plugin-fs": "2.0.2",
"@tauri-apps/plugin-geolocation": "2.0.0",
"@tauri-apps/plugin-global-shortcut": "2.0.0",
"@tauri-apps/plugin-opener": "1.0.0",
"@tauri-apps/plugin-haptics": "2.0.0",
"@tauri-apps/plugin-http": "2.0.1",
"@tauri-apps/plugin-nfc": "2.0.0",
Expand Down
1 change: 1 addition & 0 deletions examples/api/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tauri-plugin-notification = { path = "../../../plugins/notification", version =
] }
tauri-plugin-os = { path = "../../../plugins/os", version = "2.0.1" }
tauri-plugin-process = { path = "../../../plugins/process", version = "2.0.1" }
tauri-plugin-opener = { path = "../../../plugins/opener", version = "1.0.0" }
tauri-plugin-shell = { path = "../../../plugins/shell", version = "2.0.2" }
tauri-plugin-store = { path = "../../../plugins/store", version = "2.1.0" }

Expand Down
3 changes: 2 additions & 1 deletion examples/api/src-tauri/capabilities/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
],
"deny": ["$APPDATA/db/*.stronghold"]
},
"store:default"
"store:default",
"opener:default"
]
}
1 change: 1 addition & 0 deletions examples/api/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn run() {
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_store::Builder::default().build())
.setup(move |app| {
Expand Down
7 changes: 6 additions & 1 deletion examples/api/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import { writable } from 'svelte/store'
import { open } from '@tauri-apps/plugin-shell'
import { getCurrentWindow } from '@tauri-apps/api/window'
import { getCurrentWebview } from '@tauri-apps/api/webview'
import * as os from '@tauri-apps/plugin-os'
Expand All @@ -14,6 +13,7 @@
import Notifications from './views/Notifications.svelte'
import Shortcuts from './views/Shortcuts.svelte'
import Shell from './views/Shell.svelte'
import Opener from './views/Opener.svelte'
import Store from './views/Store.svelte'
import Updater from './views/Updater.svelte'
import Clipboard from './views/Clipboard.svelte'
Expand Down Expand Up @@ -92,6 +92,11 @@
component: Shell,
icon: 'i-codicon-terminal-bash'
},
{
label: 'Opener',
component: Opener,
icon: 'i-codicon-link-external'
},
{
label: 'Store',
component: Store,
Expand Down
50 changes: 50 additions & 0 deletions examples/api/src/views/Opener.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<script>
import { open } from '@tauri-apps/plugin-opener'
amrbashir marked this conversation as resolved.
Show resolved Hide resolved

export let onMessage

const programs = [
'firefox',
'google chrome',
'chromium',
'safari',
'open',
'start',
'xdg-open',
'gio',
'gnome-open',
'kde-open',
'wslview'
]

let path = ''

let program = 'Default'

function openPath() {
open(path, program === 'Default' ? undefined : program).catch(onMessage)
}
</script>

<div class="flex flex-col">
<form
class="flex flex-row gap-2 items-center"
on:submit|preventDefault={openPath}
>
<input
class="input grow"
placeholder="Type the path to watch..."
bind:value={path}
/>

<span> with </span>
<select class="input" bind:value={program}>
<option value="Default">Default</option>
{#each programs as p}
<option value={p}>{p}</option>
{/each}
</select>

<button class="btn" type="submit">Open</button>
</form>
</div>
2 changes: 1 addition & 1 deletion plugins/fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ thiserror = { workspace = true }
url = { workspace = true }
anyhow = "1"
uuid = { version = "1", features = ["v4"] }
glob = "0.3"
glob = { workspace = true }
# TODO: Remove `serialization-compat-6` in v3
notify = { version = "7", optional = true, features = [
"serde",
Expand Down
17 changes: 15 additions & 2 deletions plugins/fs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ mod scope;
#[serde(untagged)]
#[allow(unused)]
enum FsScopeEntry {
/// FS scope path.
/// A path that can be accessed by the webview when using the fs APIs.
/// FS scope path pattern.
///
/// The pattern can start with a variable that resolves to a system base directory.
/// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
/// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
/// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`,
/// `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
Value(PathBuf),
Object {
/// FS scope path.
/// A path that can be accessed by the webview when using the fs APIs.
///
/// The pattern can start with a variable that resolves to a system base directory.
/// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
/// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
/// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`,
/// `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
path: PathBuf,
},
}
Expand Down
65 changes: 65 additions & 0 deletions plugins/opener/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[package]
name = "tauri-plugin-opener"
version = "1.0.0"
description = "Open files and URLs using their default application."
edition = { workspace = true }
authors = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
links = "tauri-plugin-opener"

[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]

# Platforms supported by the plugin
# Support levels are "full", "partial", "none", "unknown"
# Details of the support level are left to plugin maintainer
[package.metadata.platforms]
windows = { level = "full", notes = "" }
linux = { level = "full", notes = "" }
macos = { level = "full", notes = "" }
android = { level = "partial", notes = "Only allows to open URLs via `open`" }
ios = { level = "partial", notes = "Only allows to open URLs via `open`" }


[build-dependencies]
tauri-plugin = { workspace = true, features = ["build"] }
schemars = { workspace = true }
serde = { workspace = true }

[dependencies]
serde = { workspace = true }
serde_json = { workspace = true }
tauri = { workspace = true }
thiserror = { workspace = true }
open = { version = "5", features = ["shellexecute-on-windows"] }
url = { workspace = true }
glob = { workspace = true }

[target."cfg(windows)".dependencies]
dunce = { workspace = true }

[target."cfg(windows)".dependencies.windows]
version = "0.54"
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
features = [
"Win32_Foundation",
"Win32_UI_Shell_Common",
"Win32_UI_WindowsAndMessaging",
"Win32_System_Com",
"Win32_System_Registry",
]

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\"))".dependencies]
zbus = { workspace = true }

[target."cfg(target_os = \"macos\")".dependencies.objc2-app-kit]
version = "0.2"
features = ["NSWorkspace"]

[target."cfg(target_os = \"macos\")".dependencies.objc2-foundation]
version = "0.2"
features = ["NSURL", "NSArray", "NSString"]

[target.'cfg(target_os = "ios")'.dependencies]
tauri = { workspace = true, features = ["wry"] }
20 changes: 20 additions & 0 deletions plugins/opener/LICENSE.spdx
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading