mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-26 21:41:48 +02:00
chore: fmt
This commit is contained in:
@@ -13,7 +13,6 @@ use tauri::{
|
||||
plugin::{Builder, PluginHandle, TauriPlugin},
|
||||
};
|
||||
|
||||
|
||||
mod error;
|
||||
mod models;
|
||||
|
||||
|
||||
@@ -139,12 +139,12 @@ fn get_matches_internal(config: &Config, matches: &ArgMatches) -> Matches {
|
||||
.subcommands
|
||||
.as_ref()
|
||||
.and_then(|s| s.get(subcommand_name))
|
||||
{
|
||||
cli_matches.set_subcommand(
|
||||
subcommand_name.to_string(),
|
||||
get_matches_internal(subcommand_config, subcommand_matches),
|
||||
);
|
||||
}
|
||||
{
|
||||
cli_matches.set_subcommand(
|
||||
subcommand_name.to_string(),
|
||||
get_matches_internal(subcommand_config, subcommand_matches),
|
||||
);
|
||||
}
|
||||
|
||||
cli_matches
|
||||
}
|
||||
|
||||
@@ -71,11 +71,12 @@ where
|
||||
{
|
||||
let opt = Option::<String>::deserialize(deserializer)?;
|
||||
if let Some(ref host) = opt
|
||||
&& let Some((scheme, _)) = host.split_once("://") {
|
||||
return Err(serde::de::Error::custom(format!(
|
||||
"host `{host}` cannot start with a scheme, please remove the `{scheme}://` prefix"
|
||||
)));
|
||||
}
|
||||
&& let Some((scheme, _)) = host.split_once("://")
|
||||
{
|
||||
return Err(serde::de::Error::custom(format!(
|
||||
"host `{host}` cannot start with a scheme, please remove the `{scheme}://` prefix"
|
||||
)));
|
||||
}
|
||||
Ok(opt)
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,10 @@ fn init_deep_link<R: Runtime>(
|
||||
},
|
||||
)?;
|
||||
|
||||
return Ok(DeepLink {
|
||||
Ok(DeepLink {
|
||||
app: app.clone(),
|
||||
plugin_handle: handle,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
@@ -417,9 +417,10 @@ mod imp {
|
||||
if mimeapps_path.exists() {
|
||||
let mut mimeapps = ini::Ini::load_from_file(&mimeapps_path)?;
|
||||
if let Some(section) = mimeapps.section_mut(Some("Default Applications"))
|
||||
&& section.get(&mime_type).unwrap_or_default() == file_name {
|
||||
section.remove(&mime_type);
|
||||
}
|
||||
&& section.get(&mime_type).unwrap_or_default() == file_name
|
||||
{
|
||||
section.remove(&mime_type);
|
||||
}
|
||||
mimeapps.write_to_file(&mimeapps_path)?;
|
||||
}
|
||||
|
||||
@@ -559,8 +560,6 @@ impl<R: Runtime> DeepLink<R> {
|
||||
///
|
||||
/// Use `get_current` on app load to check whether your app was started via a deep link.
|
||||
pub fn on_open_url<F: Fn(OpenUrlEvent) + Send + Sync + 'static>(&self, f: F) -> EventId {
|
||||
|
||||
|
||||
self.app.listen("deep-link://new-url", move |event| {
|
||||
if let Ok(urls) = serde_json::from_str(event.payload()) {
|
||||
f(OpenUrlEvent {
|
||||
|
||||
@@ -172,12 +172,13 @@ pub(crate) async fn open<R: Runtime>(
|
||||
} else {
|
||||
let folder = dialog_builder.blocking_pick_folder();
|
||||
if let Some(folder) = &folder
|
||||
&& let Ok(path) = folder.clone().into_path() {
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_directory(&path, options.recursive)?;
|
||||
}
|
||||
tauri_scope.allow_directory(&path, options.directory)?;
|
||||
&& let Ok(path) = folder.clone().into_path()
|
||||
{
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_directory(&path, options.recursive)?;
|
||||
}
|
||||
tauri_scope.allow_directory(&path, options.directory)?;
|
||||
}
|
||||
OpenResponse::Folder(folder.map(|p| p.simplified()))
|
||||
}
|
||||
}
|
||||
@@ -204,12 +205,13 @@ pub(crate) async fn open<R: Runtime>(
|
||||
let file = dialog_builder.blocking_pick_file();
|
||||
|
||||
if let Some(file) = &file
|
||||
&& let Ok(path) = file.clone().into_path() {
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_file(&path)?;
|
||||
}
|
||||
tauri_scope.allow_file(&path)?;
|
||||
&& let Ok(path) = file.clone().into_path()
|
||||
{
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_file(&path)?;
|
||||
}
|
||||
tauri_scope.allow_file(&path)?;
|
||||
}
|
||||
OpenResponse::File(file.map(|f| f.simplified()))
|
||||
};
|
||||
Ok(res)
|
||||
@@ -245,12 +247,13 @@ pub(crate) async fn save<R: Runtime>(
|
||||
|
||||
let path = dialog_builder.blocking_save_file();
|
||||
if let Some(p) = &path
|
||||
&& let Ok(path) = p.clone().into_path() {
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_file(&path)?;
|
||||
}
|
||||
tauri_scope.allow_file(&path)?;
|
||||
&& let Ok(path) = p.clone().into_path()
|
||||
{
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_file(&path)?;
|
||||
}
|
||||
tauri_scope.allow_file(&path)?;
|
||||
}
|
||||
|
||||
Ok(path.map(|p| p.simplified()))
|
||||
}
|
||||
|
||||
@@ -42,9 +42,7 @@ impl<R: Runtime> Fs<R> {
|
||||
match path.into() {
|
||||
FilePath::Url(u) => self
|
||||
.resolve_content_uri(u.to_string(), opts.android_mode())
|
||||
.map_err(|e| {
|
||||
std::io::Error::other(format!("failed to open file: {e}"))
|
||||
}),
|
||||
.map_err(|e| std::io::Error::other(format!("failed to open file: {e}"))),
|
||||
FilePath::Path(p) => {
|
||||
// tauri::utils::platform::resources_dir() returns a PathBuf with the Android asset URI prefix
|
||||
// we must resolve that file with the Android API
|
||||
@@ -52,9 +50,7 @@ impl<R: Runtime> Fs<R> {
|
||||
.is_ok()
|
||||
{
|
||||
self.resolve_content_uri(p.to_string_lossy(), opts.android_mode())
|
||||
.map_err(|e| {
|
||||
std::io::Error::other(format!("failed to open file: {e}"))
|
||||
})
|
||||
.map_err(|e| std::io::Error::other(format!("failed to open file: {e}")))
|
||||
} else {
|
||||
std::fs::OpenOptions::from(opts).open(p)
|
||||
}
|
||||
|
||||
@@ -191,9 +191,10 @@ impl FromStr for FilePath {
|
||||
type Err = Infallible;
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
if let Ok(url) = url::Url::from_str(s)
|
||||
&& url.scheme().len() != 1 {
|
||||
return Ok(Self::Url(url));
|
||||
}
|
||||
&& url.scheme().len() != 1
|
||||
{
|
||||
return Ok(Self::Url(url));
|
||||
}
|
||||
Ok(Self::Path(PathBuf::from(s)))
|
||||
}
|
||||
}
|
||||
@@ -202,9 +203,10 @@ impl FromStr for SafeFilePath {
|
||||
type Err = Error;
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
if let Ok(url) = url::Url::from_str(s)
|
||||
&& url.scheme().len() != 1 {
|
||||
return Ok(Self::Url(url));
|
||||
}
|
||||
&& url.scheme().len() != 1
|
||||
{
|
||||
return Ok(Self::Url(url));
|
||||
}
|
||||
|
||||
SafePathBuf::new(s.into())
|
||||
.map(SafeFilePath::Path)
|
||||
|
||||
@@ -349,15 +349,16 @@ pub async fn fetch<R: Runtime>(
|
||||
|
||||
// ensure we have an Origin header set
|
||||
if (cfg!(not(feature = "unsafe-headers")) || !headers.contains_key(header::ORIGIN))
|
||||
&& let Ok(url) = webview.url() {
|
||||
// The url crate returns OpaqueOrigin for tauri://localhost which serializes to "null"
|
||||
let origin = if url.scheme() == "tauri" {
|
||||
"tauri://localhost".to_string()
|
||||
} else {
|
||||
url.origin().ascii_serialization()
|
||||
};
|
||||
headers.append(header::ORIGIN, HeaderValue::from_str(&origin)?);
|
||||
}
|
||||
&& let Ok(url) = webview.url()
|
||||
{
|
||||
// The url crate returns OpaqueOrigin for tauri://localhost which serializes to "null"
|
||||
let origin = if url.scheme() == "tauri" {
|
||||
"tauri://localhost".to_string()
|
||||
} else {
|
||||
url.origin().ascii_serialization()
|
||||
};
|
||||
headers.append(header::ORIGIN, HeaderValue::from_str(&origin)?);
|
||||
}
|
||||
|
||||
// In case empty origin is passed, remove it. Some services do not like Origin header
|
||||
// so this way we can remove it in explicit way. The default behaviour is still to set it
|
||||
|
||||
@@ -105,7 +105,7 @@ pub fn destroy<R: Runtime, M: Manager<R>>(manager: &M) {
|
||||
&& let Some(dbus_name) = manager
|
||||
.try_state::<DBusName>()
|
||||
.and_then(|name| WellKnownName::try_from(name.0.clone()).ok())
|
||||
{
|
||||
let _ = connection.0.release_name(dbus_name);
|
||||
}
|
||||
{
|
||||
let _ = connection.0.release_name(dbus_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,9 +471,10 @@ impl Builder {
|
||||
let stores = collection.stores.read().unwrap();
|
||||
for (path, rid) in stores.iter() {
|
||||
if let Ok(store) = app_handle.resources_table().get::<Store<R>>(*rid)
|
||||
&& let Err(err) = store.save() {
|
||||
tracing::error!("failed to save store {path:?} with error {err:?}");
|
||||
}
|
||||
&& let Err(err) = store.save()
|
||||
{
|
||||
tracing::error!("failed to save store {path:?} with error {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -271,10 +271,11 @@ async fn destroy(
|
||||
) -> Result<()> {
|
||||
let mut collection = collection.0.lock().unwrap();
|
||||
if let Some(stronghold) = collection.remove(&snapshot_path)
|
||||
&& let Err(e) = stronghold.save() {
|
||||
collection.insert(snapshot_path, stronghold);
|
||||
return Err(e);
|
||||
}
|
||||
&& let Err(e) = stronghold.save()
|
||||
{
|
||||
collection.insert(snapshot_path, stronghold);
|
||||
return Err(e);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
|
||||
use base64::Engine;
|
||||
use futures_util::StreamExt;
|
||||
use http::{HeaderName, header::ACCEPT};
|
||||
@@ -1187,15 +1186,16 @@ impl Update {
|
||||
let mut archive = tar::Archive::new(decoder);
|
||||
for mut entry in archive.entries()?.flatten() {
|
||||
if let Ok(path) = entry.path()
|
||||
&& path.extension() == Some(OsStr::new("AppImage")) {
|
||||
// if something went wrong during the extraction, we should restore previous app
|
||||
if let Err(err) = entry.unpack(&self.extract_path) {
|
||||
std::fs::rename(tmp_app_image, &self.extract_path)?;
|
||||
return Err(err.into());
|
||||
}
|
||||
// early finish we have everything we need here
|
||||
return Ok(());
|
||||
&& path.extension() == Some(OsStr::new("AppImage"))
|
||||
{
|
||||
// if something went wrong during the extraction, we should restore previous app
|
||||
if let Err(err) = entry.unpack(&self.extract_path) {
|
||||
std::fs::rename(tmp_app_image, &self.extract_path)?;
|
||||
return Err(err.into());
|
||||
}
|
||||
// early finish we have everything we need here
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
// if we have not returned early we should restore the backup
|
||||
std::fs::rename(tmp_app_image, &self.extract_path)?;
|
||||
@@ -1289,17 +1289,19 @@ impl Update {
|
||||
.arg(install_arg)
|
||||
.arg(pkg_path)
|
||||
.status()
|
||||
&& status.success() {
|
||||
log::debug!("installed {pkg_path:?} with pkexec");
|
||||
return Ok(());
|
||||
}
|
||||
&& status.success()
|
||||
{
|
||||
log::debug!("installed {pkg_path:?} with pkexec");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// 2. Try zenity or kdialog for a graphical sudo experience
|
||||
if let Ok(password) = self.get_password_graphically()
|
||||
&& self.install_with_sudo(pkg_path, &password, install_cmd, install_arg)? {
|
||||
log::debug!("installed {pkg_path:?} with GUI sudo");
|
||||
return Ok(());
|
||||
}
|
||||
&& self.install_with_sudo(pkg_path, &password, install_cmd, install_arg)?
|
||||
{
|
||||
log::debug!("installed {pkg_path:?} with GUI sudo");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// 3. Final fallback: terminal sudo
|
||||
let status = std::process::Command::new("sudo")
|
||||
@@ -1327,9 +1329,10 @@ impl Update {
|
||||
.output();
|
||||
|
||||
if let Ok(output) = zenity_result
|
||||
&& output.status.success() {
|
||||
return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string());
|
||||
}
|
||||
&& output.status.success()
|
||||
{
|
||||
return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string());
|
||||
}
|
||||
|
||||
// Fall back to kdialog if zenity fails or isn't available
|
||||
let kdialog_result = std::process::Command::new("kdialog")
|
||||
@@ -1337,9 +1340,10 @@ impl Update {
|
||||
.output();
|
||||
|
||||
if let Ok(output) = kdialog_result
|
||||
&& output.status.success() {
|
||||
return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string());
|
||||
}
|
||||
&& output.status.success()
|
||||
{
|
||||
return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string());
|
||||
}
|
||||
|
||||
Err(Error::AuthenticationFailed)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user