mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-08-01 17:58:37 +02:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc53cf11db | ||
|
|
539d41ace7 | ||
|
|
1ec8844b0e | ||
|
|
b5c55d4ba2 | ||
|
|
4341d7f500 | ||
|
|
77149dc432 | ||
|
|
5092683f97 |
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
sql: patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Replace `Mutex` with `RwLock` to enable concurrent SQL execution.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"fs-js": "patch"
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix `writeTextFile` converting UTF-8 characters (for example `äöü`) in the given path into replacement character (`�`)
|
||||||
Generated
+22
@@ -7042,6 +7042,7 @@ dependencies = [
|
|||||||
name = "tauri-plugin-shell"
|
name = "tauri-plugin-shell"
|
||||||
version = "2.0.2"
|
version = "2.0.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"dunce",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"log",
|
"log",
|
||||||
"open",
|
"open",
|
||||||
@@ -7055,6 +7056,7 @@ dependencies = [
|
|||||||
"tauri-plugin",
|
"tauri-plugin",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"windows 0.54.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -8344,6 +8346,16 @@ dependencies = [
|
|||||||
"windows_x86_64_msvc 0.36.1",
|
"windows_x86_64_msvc 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.54.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core 0.54.0",
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows"
|
name = "windows"
|
||||||
version = "0.56.0"
|
version = "0.56.0"
|
||||||
@@ -8373,6 +8385,16 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.54.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65"
|
||||||
|
dependencies = [
|
||||||
|
"windows-result 0.1.2",
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.56.0"
|
version = "0.56.0"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1072,7 +1072,7 @@ async function writeTextFile(
|
|||||||
|
|
||||||
await invoke('plugin:fs|write_text_file', encoder.encode(data), {
|
await invoke('plugin:fs|write_text_file', encoder.encode(data), {
|
||||||
headers: {
|
headers: {
|
||||||
path: path instanceof URL ? path.toString() : path,
|
path: encodeURIComponent(path instanceof URL ? path.toString() : path),
|
||||||
options: JSON.stringify(options)
|
options: JSON.stringify(options)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -37,6 +37,17 @@ regex = "1"
|
|||||||
open = { version = "5", features = ["shellexecute-on-windows"] }
|
open = { version = "5", features = ["shellexecute-on-windows"] }
|
||||||
encoding_rs = "0.8"
|
encoding_rs = "0.8"
|
||||||
os_pipe = "1"
|
os_pipe = "1"
|
||||||
|
dunce = { workspace = true }
|
||||||
|
|
||||||
|
[target."cfg(windows)".dependencies.windows]
|
||||||
|
version = "0.54"
|
||||||
|
features = [
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_UI_Shell_Common",
|
||||||
|
"Win32_UI_WindowsAndMessaging",
|
||||||
|
"Win32_System_Com",
|
||||||
|
"Win32_System_Registry",
|
||||||
|
]
|
||||||
|
|
||||||
[target.'cfg(target_os = "ios")'.dependencies]
|
[target.'cfg(target_os = "ios")'.dependencies]
|
||||||
tauri = { workspace = true, features = ["wry"] }
|
tauri = { workspace = true, features = ["wry"] }
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ pub enum Error {
|
|||||||
/// JSON error.
|
/// JSON error.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Json(#[from] serde_json::Error),
|
Json(#[from] serde_json::Error),
|
||||||
|
/// API not supported on the current platform
|
||||||
|
#[error("API not supported on the current platform")]
|
||||||
|
UnsupportedPlatform,
|
||||||
|
#[error(transparent)]
|
||||||
|
#[cfg(windows)]
|
||||||
|
Win32Error(#[from] windows::core::Error),
|
||||||
|
/// Path doesn't have a parent.
|
||||||
|
#[error("Path doesn't have a parent: {0}")]
|
||||||
|
NoParent(PathBuf),
|
||||||
/// Utf8 error.
|
/// Utf8 error.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Utf8(#[from] std::string::FromUtf8Error),
|
Utf8(#[from] std::string::FromUtf8Error),
|
||||||
|
|||||||
@@ -85,6 +85,10 @@ impl<R: Runtime> Shell<R> {
|
|||||||
.run_mobile_plugin("open", path.into())
|
.run_mobile_plugin("open", path.into())
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_item_in_directory<P: AsRef<Path>>(&self, p: P) -> Result<()> {
|
||||||
|
open::show_item_in_directory(p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ShellExt<R: Runtime> {
|
pub trait ShellExt<R: Runtime> {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub fn show_item_in_directory(file: &Path) -> crate::Result<()> {}
|
||||||
@@ -9,6 +9,22 @@ use serde::{Deserialize, Deserializer};
|
|||||||
use crate::scope::OpenScope;
|
use crate::scope::OpenScope;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[path = "windows.rs"]
|
||||||
|
mod platform;
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
#[path = "macos.rs"]
|
||||||
|
mod platform;
|
||||||
|
#[cfg(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
))]
|
||||||
|
#[path = "linux.rs"]
|
||||||
|
mod platform;
|
||||||
|
|
||||||
/// Program to use on the [`open()`] call.
|
/// Program to use on the [`open()`] call.
|
||||||
pub enum Program {
|
pub enum Program {
|
||||||
/// Use the `open` program.
|
/// Use the `open` program.
|
||||||
@@ -120,3 +136,30 @@ impl Program {
|
|||||||
pub fn open<P: AsRef<str>>(scope: &OpenScope, path: P, with: Option<Program>) -> crate::Result<()> {
|
pub fn open<P: AsRef<str>>(scope: &OpenScope, path: P, with: Option<Program>) -> crate::Result<()> {
|
||||||
scope.open(path.as_ref(), with).map_err(Into::into)
|
scope.open(path.as_ref(), with).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_item_in_directory<P: AsRef<std::path::Path>>(p: P) -> crate::Result<()> {
|
||||||
|
let p = p.as_ref().canonicalize()?;
|
||||||
|
let p = dunce::simplified(&p);
|
||||||
|
|
||||||
|
#[cfg(any(
|
||||||
|
windows,
|
||||||
|
target_os = "macos",
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
))]
|
||||||
|
return platform::show_item_in_directory(p);
|
||||||
|
|
||||||
|
#[cfg(not(any(
|
||||||
|
windows,
|
||||||
|
target_os = "macos",
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
)))]
|
||||||
|
Err(crate::Error::UnsupportedPlatform)
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use windows::{
|
||||||
|
core::{w, HSTRING, PCWSTR},
|
||||||
|
Win32::{
|
||||||
|
Foundation::ERROR_FILE_NOT_FOUND,
|
||||||
|
System::Com::CoInitialize,
|
||||||
|
UI::{
|
||||||
|
Shell::{
|
||||||
|
ILCreateFromPathW, ILFree, SHOpenFolderAndSelectItems, ShellExecuteExW,
|
||||||
|
SHELLEXECUTEINFOW,
|
||||||
|
},
|
||||||
|
WindowsAndMessaging::SW_SHOWNORMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn show_item_in_directory(file: &Path) -> crate::Result<()> {
|
||||||
|
let _ = unsafe { CoInitialize(None) };
|
||||||
|
|
||||||
|
let dir = file
|
||||||
|
.parent()
|
||||||
|
.ok_or_else(|| crate::Error::NoParent(file.to_path_buf()))?;
|
||||||
|
|
||||||
|
let dir = HSTRING::from(dir);
|
||||||
|
let dir_item = unsafe { ILCreateFromPathW(PCWSTR::from_raw(dir.as_ptr())) };
|
||||||
|
|
||||||
|
let file_h = HSTRING::from(file);
|
||||||
|
let file_item = unsafe { ILCreateFromPathW(PCWSTR::from_raw(file_h.as_ptr())) };
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
if let Err(e) = SHOpenFolderAndSelectItems(dir_item, Some(&[file_item]), 0) {
|
||||||
|
if e.code().0 == ERROR_FILE_NOT_FOUND.0 as i32 {
|
||||||
|
let is_dir = std::fs::metadata(file).map(|f| f.is_dir()).unwrap_or(false);
|
||||||
|
let mut info = SHELLEXECUTEINFOW {
|
||||||
|
cbSize: std::mem::size_of::<SHELLEXECUTEINFOW>() as _,
|
||||||
|
nShow: SW_SHOWNORMAL.0,
|
||||||
|
lpVerb: if is_dir {
|
||||||
|
w!("explore")
|
||||||
|
} else {
|
||||||
|
PCWSTR::null()
|
||||||
|
},
|
||||||
|
lpClass: if is_dir { w!("folder") } else { PCWSTR::null() },
|
||||||
|
lpFile: PCWSTR(file_h.as_ptr()),
|
||||||
|
..std::mem::zeroed()
|
||||||
|
};
|
||||||
|
|
||||||
|
ShellExecuteExW(&mut info)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
ILFree(Some(dir_item));
|
||||||
|
ILFree(Some(file_item));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ pub(crate) async fn load<R: Runtime>(
|
|||||||
pool.migrate(&migrator).await?;
|
pool.migrate(&migrator).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
db_instances.0.lock().await.insert(db.clone(), pool);
|
db_instances.0.write().await.insert(db.clone(), pool);
|
||||||
|
|
||||||
Ok(db)
|
Ok(db)
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ pub(crate) async fn close(
|
|||||||
db_instances: State<'_, DbInstances>,
|
db_instances: State<'_, DbInstances>,
|
||||||
db: Option<String>,
|
db: Option<String>,
|
||||||
) -> Result<bool, crate::Error> {
|
) -> Result<bool, crate::Error> {
|
||||||
let mut instances = db_instances.0.lock().await;
|
let instances = db_instances.0.read().await;
|
||||||
|
|
||||||
let pools = if let Some(db) = db {
|
let pools = if let Some(db) = db {
|
||||||
vec![db]
|
vec![db]
|
||||||
@@ -45,9 +45,7 @@ pub(crate) async fn close(
|
|||||||
};
|
};
|
||||||
|
|
||||||
for pool in pools {
|
for pool in pools {
|
||||||
let db = instances
|
let db = instances.get(&pool).ok_or(Error::DatabaseNotLoaded(pool))?;
|
||||||
.get_mut(&pool)
|
|
||||||
.ok_or(Error::DatabaseNotLoaded(pool))?;
|
|
||||||
db.close().await;
|
db.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,9 +60,9 @@ pub(crate) async fn execute(
|
|||||||
query: String,
|
query: String,
|
||||||
values: Vec<JsonValue>,
|
values: Vec<JsonValue>,
|
||||||
) -> Result<(u64, LastInsertId), crate::Error> {
|
) -> Result<(u64, LastInsertId), crate::Error> {
|
||||||
let mut instances = db_instances.0.lock().await;
|
let instances = db_instances.0.read().await;
|
||||||
|
|
||||||
let db = instances.get_mut(&db).ok_or(Error::DatabaseNotLoaded(db))?;
|
let db = instances.get(&db).ok_or(Error::DatabaseNotLoaded(db))?;
|
||||||
db.execute(query, values).await
|
db.execute(query, values).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +73,8 @@ pub(crate) async fn select(
|
|||||||
query: String,
|
query: String,
|
||||||
values: Vec<JsonValue>,
|
values: Vec<JsonValue>,
|
||||||
) -> Result<Vec<IndexMap<String, JsonValue>>, crate::Error> {
|
) -> Result<Vec<IndexMap<String, JsonValue>>, crate::Error> {
|
||||||
let mut instances = db_instances.0.lock().await;
|
let instances = db_instances.0.read().await;
|
||||||
|
|
||||||
let db = instances.get_mut(&db).ok_or(Error::DatabaseNotLoaded(db))?;
|
let db = instances.get(&db).ok_or(Error::DatabaseNotLoaded(db))?;
|
||||||
db.select(query, values).await
|
db.select(query, values).await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ use tauri::{
|
|||||||
plugin::{Builder as PluginBuilder, TauriPlugin},
|
plugin::{Builder as PluginBuilder, TauriPlugin},
|
||||||
Manager, RunEvent, Runtime,
|
Manager, RunEvent, Runtime,
|
||||||
};
|
};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::{Mutex, RwLock};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct DbInstances(pub Mutex<HashMap<String, DbPool>>);
|
pub struct DbInstances(pub RwLock<HashMap<String, DbPool>>);
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
@@ -140,7 +140,7 @@ impl Builder {
|
|||||||
|
|
||||||
tauri::async_runtime::block_on(async move {
|
tauri::async_runtime::block_on(async move {
|
||||||
let instances = DbInstances::default();
|
let instances = DbInstances::default();
|
||||||
let mut lock = instances.0.lock().await;
|
let mut lock = instances.0.write().await;
|
||||||
|
|
||||||
for db in config.preload {
|
for db in config.preload {
|
||||||
let pool = DbPool::connect(&db, app).await?;
|
let pool = DbPool::connect(&db, app).await?;
|
||||||
@@ -168,7 +168,7 @@ impl Builder {
|
|||||||
if let RunEvent::Exit = event {
|
if let RunEvent::Exit = event {
|
||||||
tauri::async_runtime::block_on(async move {
|
tauri::async_runtime::block_on(async move {
|
||||||
let instances = &*app.state::<DbInstances>();
|
let instances = &*app.state::<DbInstances>();
|
||||||
let instances = instances.0.lock().await;
|
let instances = instances.0.read().await;
|
||||||
for value in instances.values() {
|
for value in instances.values() {
|
||||||
value.close().await;
|
value.close().await;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user