mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-30 17:48:50 +02:00
feat: add init scripts (#361)
This commit is contained in:
Generated
+7
-7
@@ -4960,7 +4960,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri"
|
name = "tauri"
|
||||||
version = "2.0.0-alpha.8"
|
version = "2.0.0-alpha.8"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#59db76af4c88645ee03b9f87c0f787fbc0040905"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#994e4fd6d9e649e0d76124cd6fcd18443ac585b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes 1.4.0",
|
"bytes 1.4.0",
|
||||||
@@ -5010,7 +5010,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-build"
|
name = "tauri-build"
|
||||||
version = "2.0.0-alpha.4"
|
version = "2.0.0-alpha.4"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#59db76af4c88645ee03b9f87c0f787fbc0040905"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#994e4fd6d9e649e0d76124cd6fcd18443ac585b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cargo_toml",
|
"cargo_toml",
|
||||||
@@ -5030,7 +5030,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-codegen"
|
name = "tauri-codegen"
|
||||||
version = "2.0.0-alpha.4"
|
version = "2.0.0-alpha.4"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#59db76af4c88645ee03b9f87c0f787fbc0040905"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#994e4fd6d9e649e0d76124cd6fcd18443ac585b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.0",
|
"base64 0.21.0",
|
||||||
"brotli",
|
"brotli",
|
||||||
@@ -5055,7 +5055,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-macros"
|
name = "tauri-macros"
|
||||||
version = "2.0.0-alpha.4"
|
version = "2.0.0-alpha.4"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#59db76af4c88645ee03b9f87c0f787fbc0040905"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#994e4fd6d9e649e0d76124cd6fcd18443ac585b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.4.1",
|
"heck 0.4.1",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -5449,7 +5449,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime"
|
name = "tauri-runtime"
|
||||||
version = "0.13.0-alpha.4"
|
version = "0.13.0-alpha.4"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#59db76af4c88645ee03b9f87c0f787fbc0040905"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#994e4fd6d9e649e0d76124cd6fcd18443ac585b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gtk",
|
"gtk",
|
||||||
"http",
|
"http",
|
||||||
@@ -5469,7 +5469,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime-wry"
|
name = "tauri-runtime-wry"
|
||||||
version = "0.13.0-alpha.4"
|
version = "0.13.0-alpha.4"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#59db76af4c88645ee03b9f87c0f787fbc0040905"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#994e4fd6d9e649e0d76124cd6fcd18443ac585b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"gtk",
|
"gtk",
|
||||||
@@ -5489,7 +5489,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-utils"
|
name = "tauri-utils"
|
||||||
version = "2.0.0-alpha.4"
|
version = "2.0.0-alpha.4"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#59db76af4c88645ee03b9f87c0f787fbc0040905"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#994e4fd6d9e649e0d76124cd6fcd18443ac585b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-gcm 0.10.1",
|
"aes-gcm 0.10.1",
|
||||||
"brotli",
|
"brotli",
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ tauri-plugin-notification = { path = "../../../plugins/notification", features =
|
|||||||
tauri-plugin-os = { path = "../../../plugins/os" }
|
tauri-plugin-os = { path = "../../../plugins/os" }
|
||||||
tauri-plugin-process = { path = "../../../plugins/process" }
|
tauri-plugin-process = { path = "../../../plugins/process" }
|
||||||
tauri-plugin-shell = { path = "../../../plugins/shell" }
|
tauri-plugin-shell = { path = "../../../plugins/shell" }
|
||||||
tauri-plugin-window = { path = "../../../plugins/window" }
|
tauri-plugin-window = { path = "../../../plugins/window", features = ["devtools", "icon-ico", "icon-png"] }
|
||||||
|
|
||||||
[dependencies.tauri]
|
[dependencies.tauri]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|||||||
@@ -271,8 +271,8 @@ pub(crate) async fn ask<R: Runtime>(
|
|||||||
title,
|
title,
|
||||||
message,
|
message,
|
||||||
type_,
|
type_,
|
||||||
ok_button_label,
|
Some(ok_button_label.unwrap_or_else(|| "Yes".into())),
|
||||||
cancel_button_label,
|
Some(cancel_button_label.unwrap_or_else(|| "No".into())),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ pub(crate) async fn confirm<R: Runtime>(
|
|||||||
title,
|
title,
|
||||||
message,
|
message,
|
||||||
type_,
|
type_,
|
||||||
ok_button_label,
|
Some(ok_button_label.unwrap_or_else(|| "Ok".into())),
|
||||||
cancel_button_label,
|
Some(cancel_button_label.unwrap_or_else(|| "Cancel".into())),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
window.alert = function (message) {
|
||||||
|
window.__TAURI_INVOKE__('plugin:dialog|message', {
|
||||||
|
message: message.toString()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
window.confirm = function (message) {
|
||||||
|
return window.__TAURI_INVOKE__('plugin:dialog|confirm', {
|
||||||
|
message: message.toString()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -69,7 +69,15 @@ impl<R: Runtime> Dialog<R> {
|
|||||||
|
|
||||||
/// Initializes the plugin.
|
/// Initializes the plugin.
|
||||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||||
Builder::new("dialog")
|
let mut builder = Builder::new("dialog");
|
||||||
|
|
||||||
|
// Dialogs are implemented natively on Android
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
{
|
||||||
|
builder = builder.js_init_script(include_str!("init.js").to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
builder
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
commands::open,
|
commands::open,
|
||||||
commands::save,
|
commands::save,
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
;(function () {
|
||||||
|
// open <a href="..."> links with the API
|
||||||
|
function openLinks() {
|
||||||
|
document.querySelector('body').addEventListener(
|
||||||
|
'click',
|
||||||
|
function (e) {
|
||||||
|
var target = e.target
|
||||||
|
while (target != null) {
|
||||||
|
if (target.matches('a')) {
|
||||||
|
if (
|
||||||
|
target.href &&
|
||||||
|
(['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) &&
|
||||||
|
target.target === '_blank'
|
||||||
|
) {
|
||||||
|
window.__TAURI_INVOKE__('plugin:shell|open', {
|
||||||
|
path: target.href
|
||||||
|
})
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
target = target.parentElement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
document.readyState === 'complete' ||
|
||||||
|
document.readyState === 'interactive'
|
||||||
|
) {
|
||||||
|
openLinks()
|
||||||
|
} else {
|
||||||
|
window.addEventListener('DOMContentLoaded', openLinks, true)
|
||||||
|
}
|
||||||
|
})()
|
||||||
@@ -64,6 +64,7 @@ impl<R: Runtime, T: Manager<R>> ShellExt<R> for T {
|
|||||||
|
|
||||||
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
|
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
|
||||||
Builder::<R, Option<Config>>::new("shell")
|
Builder::<R, Option<Config>>::new("shell")
|
||||||
|
.js_init_script(include_str!("init.js").to_string())
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
commands::execute,
|
commands::execute,
|
||||||
commands::stdin_write,
|
commands::stdin_write,
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ thiserror.workspace = true
|
|||||||
[features]
|
[features]
|
||||||
icon-png = ["tauri/icon-png"]
|
icon-png = ["tauri/icon-png"]
|
||||||
icon-ico = ["tauri/icon-ico"]
|
icon-ico = ["tauri/icon-ico"]
|
||||||
|
devtools = []
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ pub fn internal_toggle_maximize<R: Runtime>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(debug_assertions, feature = "devtools"))]
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn internal_toggle_devtools<R: Runtime>(
|
pub fn internal_toggle_devtools<R: Runtime>(
|
||||||
window: Window<R>,
|
window: Window<R>,
|
||||||
|
|||||||
@@ -7,7 +7,18 @@ use tauri::{
|
|||||||
mod desktop_commands;
|
mod desktop_commands;
|
||||||
|
|
||||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||||
|
let mut init_js = String::new();
|
||||||
|
// window.print works on Linux/Windows; need to use the API on macOS
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
{
|
||||||
|
init_js.push_str(include_str!("./scripts/print.js"));
|
||||||
|
}
|
||||||
|
init_js.push_str(include_str!("./scripts/drag.js"));
|
||||||
|
#[cfg(any(debug_assertions, feature = "devtools"))]
|
||||||
|
init_js.push_str(include_str!("./scripts/toggle-devtools.js"));
|
||||||
|
|
||||||
Builder::new("window")
|
Builder::new("window")
|
||||||
|
.js_init_script(init_js)
|
||||||
.invoke_handler(|invoke| {
|
.invoke_handler(|invoke| {
|
||||||
#[cfg(desktop)]
|
#[cfg(desktop)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
document.addEventListener('mousedown', (e) => {
|
||||||
|
if (e.target.hasAttribute('data-tauri-drag-region') && e.buttons === 1) {
|
||||||
|
// prevents text cursor
|
||||||
|
e.preventDefault()
|
||||||
|
// fix #2549: double click on drag region edge causes content to maximize without window sizing change
|
||||||
|
// https://github.com/tauri-apps/tauri/issues/2549#issuecomment-1250036908
|
||||||
|
e.stopImmediatePropagation()
|
||||||
|
|
||||||
|
// start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it
|
||||||
|
const cmd = e.detail === 2 ? 'internal_toggle_maximize' : 'start_dragging'
|
||||||
|
window.__TAURI_INVOKE__('plugin:window|' + cmd)
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
window.print = function () {
|
||||||
|
return window.__TAURI_INVOKE__('plugin:window|print')
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
;(function () {
|
||||||
|
function toggleDevtoolsHotkey() {
|
||||||
|
const isHotkey = navigator.appVersion.includes('Mac')
|
||||||
|
? event => event.metaKey && event.altKey && event.key === 'I'
|
||||||
|
: event => event.ctrlKey && event.shiftKey && event.key === 'I'
|
||||||
|
|
||||||
|
document.addEventListener('keydown', event => {
|
||||||
|
if (isHotkey(event)) {
|
||||||
|
window.__TAURI_INVOKE__('plugin:window|internal_toggle_devtools');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
document.readyState === 'complete' ||
|
||||||
|
document.readyState === 'interactive'
|
||||||
|
) {
|
||||||
|
toggleDevtoolsHotkey()
|
||||||
|
} else {
|
||||||
|
window.addEventListener('DOMContentLoaded', toggleDevtoolsHotkey, true)
|
||||||
|
}
|
||||||
|
})()
|
||||||
Reference in New Issue
Block a user