mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-26 21:41:48 +02:00
fix: mobile clippy warnings
This commit is contained in:
@@ -13,7 +13,6 @@ use tauri::{
|
||||
plugin::{Builder, PluginHandle, TauriPlugin},
|
||||
};
|
||||
|
||||
pub use models::*;
|
||||
|
||||
mod error;
|
||||
mod models;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
)]
|
||||
|
||||
use tauri::{
|
||||
Manager, RunEvent, Runtime,
|
||||
Manager, Runtime,
|
||||
plugin::{Builder, TauriPlugin},
|
||||
};
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
})
|
||||
.on_event(|_app, _event| {
|
||||
#[cfg(desktop)]
|
||||
if let RunEvent::Exit = _event {
|
||||
if let tauri::RunEvent::Exit = _event {
|
||||
_app.clipboard().cleanup();
|
||||
}
|
||||
})
|
||||
|
||||
@@ -43,10 +43,7 @@ impl<R: Runtime> Fs<R> {
|
||||
FilePath::Url(u) => self
|
||||
.resolve_content_uri(u.to_string(), opts.android_mode())
|
||||
.map_err(|e| {
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("failed to open file: {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
|
||||
@@ -56,10 +53,7 @@ impl<R: Runtime> Fs<R> {
|
||||
{
|
||||
self.resolve_content_uri(p.to_string_lossy(), opts.android_mode())
|
||||
.map_err(|e| {
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("failed to open file: {e}"),
|
||||
)
|
||||
std::io::Error::other(format!("failed to open file: {e}"))
|
||||
})
|
||||
} else {
|
||||
std::fs::OpenOptions::from(opts).open(p)
|
||||
|
||||
+125
-128
@@ -159,26 +159,26 @@ impl<R: Runtime> Drop for FileHandle<R> {
|
||||
// Only clean up if we're tracking this resource
|
||||
// If start_accessing_security_scoped_resource was used, it won't be in our tracking
|
||||
// and we shouldn't interfere
|
||||
if let FilePath::Url(url) = file_path {
|
||||
if url.scheme() == "file" {
|
||||
let security_scoped_resources =
|
||||
self.app_handle.state::<crate::SecurityScopedResources>();
|
||||
if let FilePath::Url(url) = file_path
|
||||
&& url.scheme() == "file"
|
||||
{
|
||||
let security_scoped_resources =
|
||||
self.app_handle.state::<crate::SecurityScopedResources>();
|
||||
|
||||
// Only clean up if it's not tracked manually
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
log::debug!(
|
||||
"Stopping accessing security-scoped resource for URL: {url} on drop"
|
||||
);
|
||||
let _ = self
|
||||
.app_handle
|
||||
.fs()
|
||||
.stop_accessing_security_scoped_resource(FilePath::Url(url.clone()));
|
||||
security_scoped_resources.remove(url.as_str());
|
||||
} else {
|
||||
log::debug!(
|
||||
"Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)"
|
||||
);
|
||||
}
|
||||
// Only clean up if it's not tracked manually
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
log::debug!(
|
||||
"Stopping accessing security-scoped resource for URL: {url} on drop"
|
||||
);
|
||||
let _ = self
|
||||
.app_handle
|
||||
.fs()
|
||||
.stop_accessing_security_scoped_resource(FilePath::Url(url.clone()));
|
||||
security_scoped_resources.remove(url.as_str());
|
||||
} else {
|
||||
log::debug!(
|
||||
"Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,26 +237,24 @@ impl<R: Runtime> Drop for PathHandle<R> {
|
||||
// Only clean up if we're tracking this resource (i.e., resolve_path started it)
|
||||
// If start_accessing_security_scoped_resource was used, it won't be in our tracking
|
||||
// and we shouldn't interfere
|
||||
if let FilePath::Url(url) = file_path {
|
||||
if url.scheme() == "file" {
|
||||
let security_scoped_resources =
|
||||
self.app_handle.state::<crate::SecurityScopedResources>();
|
||||
if let FilePath::Url(url) = file_path
|
||||
&& url.scheme() == "file"
|
||||
{
|
||||
let security_scoped_resources =
|
||||
self.app_handle.state::<crate::SecurityScopedResources>();
|
||||
|
||||
// Only clean up if it's not tracked manually
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
log::debug!(
|
||||
"Stopping accessing security-scoped resource for URL: {url} on drop"
|
||||
);
|
||||
let _ = self
|
||||
.app_handle
|
||||
.fs()
|
||||
.stop_accessing_security_scoped_resource(FilePath::Url(url.clone()));
|
||||
security_scoped_resources.remove(url.as_str());
|
||||
} else {
|
||||
log::debug!(
|
||||
"Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)"
|
||||
);
|
||||
}
|
||||
// Only clean up if it's not tracked manually
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
log::debug!("Stopping accessing security-scoped resource for URL: {url} on drop");
|
||||
let _ = self
|
||||
.app_handle
|
||||
.fs()
|
||||
.stop_accessing_security_scoped_resource(FilePath::Url(url.clone()));
|
||||
security_scoped_resources.remove(url.as_str());
|
||||
} else {
|
||||
log::debug!(
|
||||
"Not cleaning up security-scoped resource for URL: {url} on drop (manually tracked via start_accessing_security_scoped_resource)"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1280,50 +1278,49 @@ pub fn start_accessing_security_scoped_resource<R: Runtime>(
|
||||
};
|
||||
|
||||
// Only handle file URLs
|
||||
if let FilePath::Url(url) = &file_path {
|
||||
if url.scheme() == "file" {
|
||||
use objc2_foundation::{NSString, NSURL};
|
||||
if let FilePath::Url(url) = &file_path
|
||||
&& url.scheme() == "file"
|
||||
{
|
||||
use objc2_foundation::{NSString, NSURL};
|
||||
|
||||
let url_nsstring = NSString::from_str(url.as_str());
|
||||
let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) };
|
||||
if let Some(ns_url) = ns_url {
|
||||
// Check if already active
|
||||
let security_scoped_resources =
|
||||
webview.state::<crate::SecurityScopedResources>();
|
||||
if security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
let url_nsstring = NSString::from_str(url.as_str());
|
||||
let ns_url = NSURL::URLWithString(&url_nsstring);
|
||||
if let Some(ns_url) = ns_url {
|
||||
// Check if already active
|
||||
let security_scoped_resources = webview.state::<crate::SecurityScopedResources>();
|
||||
if security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
log::debug!(
|
||||
"Security-scoped resource already active for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Start accessing the security-scoped resource
|
||||
unsafe {
|
||||
let success = ns_url.startAccessingSecurityScopedResource();
|
||||
if success {
|
||||
log::debug!(
|
||||
"Security-scoped resource already active for URL: {}",
|
||||
"Started accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
return Ok(());
|
||||
security_scoped_resources.track_manually(url.as_str().to_string());
|
||||
} else {
|
||||
log::warn!(
|
||||
"Failed to start accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
return Err(CommandError::from(format!(
|
||||
"Failed to start accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
)));
|
||||
}
|
||||
|
||||
// Start accessing the security-scoped resource
|
||||
unsafe {
|
||||
let success = ns_url.startAccessingSecurityScopedResource();
|
||||
if success {
|
||||
log::debug!(
|
||||
"Started accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
security_scoped_resources.track_manually(url.as_str().to_string());
|
||||
} else {
|
||||
log::warn!(
|
||||
"Failed to start accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
return Err(CommandError::from(format!(
|
||||
"Failed to start accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(CommandError::from(format!(
|
||||
"Failed to create NSURL from URL: {}",
|
||||
url.as_str()
|
||||
)));
|
||||
}
|
||||
} else {
|
||||
return Err(CommandError::from(format!(
|
||||
"Failed to create NSURL from URL: {}",
|
||||
url.as_str()
|
||||
)));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -1352,31 +1349,31 @@ pub fn stop_accessing_security_scoped_resource<R: Runtime>(
|
||||
};
|
||||
|
||||
// Only handle file URLs
|
||||
if let FilePath::Url(url) = file_path {
|
||||
if url.scheme() == "file" {
|
||||
let security_scoped_resources = webview.state::<crate::SecurityScopedResources>();
|
||||
if let FilePath::Url(url) = file_path
|
||||
&& url.scheme() == "file"
|
||||
{
|
||||
let security_scoped_resources = webview.state::<crate::SecurityScopedResources>();
|
||||
|
||||
// Check if it's tracked
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
log::debug!(
|
||||
"Security-scoped resource not tracked as active for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Stop accessing the security-scoped resource
|
||||
webview
|
||||
.fs()
|
||||
.stop_accessing_security_scoped_resource(FilePath::Url(url.clone()))?;
|
||||
|
||||
// Remove from tracking
|
||||
security_scoped_resources.remove(url.as_str());
|
||||
// Check if it's tracked
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
log::debug!(
|
||||
"Stopped accessing security-scoped resource for URL: {}",
|
||||
"Security-scoped resource not tracked as active for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Stop accessing the security-scoped resource
|
||||
webview
|
||||
.fs()
|
||||
.stop_accessing_security_scoped_resource(FilePath::Url(url.clone()))?;
|
||||
|
||||
// Remove from tracking
|
||||
security_scoped_resources.remove(url.as_str());
|
||||
log::debug!(
|
||||
"Stopped accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1518,47 +1515,47 @@ pub fn resolve_path<R: Runtime>(
|
||||
// On iOS, start accessing security-scoped resource if the path is a file URL
|
||||
// Only if it hasn't been started already via start_accessing_security_scoped_resource
|
||||
#[cfg(target_os = "ios")]
|
||||
if let SafeFilePath::Url(url) = &path {
|
||||
if url.scheme() == "file" {
|
||||
use objc2_foundation::{NSString, NSURL};
|
||||
if let SafeFilePath::Url(url) = &path
|
||||
&& url.scheme() == "file"
|
||||
{
|
||||
use objc2_foundation::{NSString, NSURL};
|
||||
|
||||
let security_scoped_resources = webview.state::<crate::SecurityScopedResources>();
|
||||
let security_scoped_resources = webview.state::<crate::SecurityScopedResources>();
|
||||
|
||||
// Check if already active (started via start_accessing_security_scoped_resource)
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
let url_nsstring = NSString::from_str(url.as_str());
|
||||
let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) };
|
||||
if let Some(ns_url) = ns_url {
|
||||
// Start accessing the security-scoped resource
|
||||
// This is required for files outside the app's sandbox (e.g., from file picker)
|
||||
unsafe {
|
||||
let success = ns_url.startAccessingSecurityScopedResource();
|
||||
if success {
|
||||
log::debug!(
|
||||
"Started accessing security-scoped resource for URL: {} (via resolve_path)",
|
||||
url.as_str()
|
||||
);
|
||||
// Track it so we know to clean it up
|
||||
security_scoped_resources.track_manually(url.as_str().to_string());
|
||||
} else {
|
||||
log::warn!(
|
||||
"Failed to start accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
}
|
||||
// Check if already active (started via start_accessing_security_scoped_resource)
|
||||
if !security_scoped_resources.is_tracked_manually(url.as_str()) {
|
||||
let url_nsstring = NSString::from_str(url.as_str());
|
||||
let ns_url = NSURL::URLWithString(&url_nsstring);
|
||||
if let Some(ns_url) = ns_url {
|
||||
// Start accessing the security-scoped resource
|
||||
// This is required for files outside the app's sandbox (e.g., from file picker)
|
||||
unsafe {
|
||||
let success = ns_url.startAccessingSecurityScopedResource();
|
||||
if success {
|
||||
log::debug!(
|
||||
"Started accessing security-scoped resource for URL: {} (via resolve_path)",
|
||||
url.as_str()
|
||||
);
|
||||
// Track it so we know to clean it up
|
||||
security_scoped_resources.track_manually(url.as_str().to_string());
|
||||
} else {
|
||||
log::warn!(
|
||||
"Failed to start accessing security-scoped resource for URL: {}",
|
||||
url.as_str()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log::debug!(
|
||||
"Failed to create NSURL from URL: {}, ignoring security-scoped resource access request",
|
||||
url.as_str()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log::debug!(
|
||||
"Security-scoped resource already active for URL: {} (started via start_accessing_security_scoped_resource), skipping",
|
||||
"Failed to create NSURL from URL: {}, ignoring security-scoped resource access request",
|
||||
url.as_str()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log::debug!(
|
||||
"Security-scoped resource already active for URL: {} (started via start_accessing_security_scoped_resource), skipping",
|
||||
url.as_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ impl<R: Runtime> Fs<R> {
|
||||
|
||||
// Create NSURL from the URL string
|
||||
// URLWithString may return None for invalid URLs, but file:// URLs should be valid
|
||||
let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) };
|
||||
let ns_url = NSURL::URLWithString(&url_nsstring);
|
||||
if let Some(ns_url) = ns_url {
|
||||
// Start accessing the security-scoped resource
|
||||
// This is required for files outside the app's sandbox (e.g., from file picker)
|
||||
@@ -127,7 +127,7 @@ impl<R: Runtime> Fs<R> {
|
||||
};
|
||||
|
||||
let url_nsstring = NSString::from_str(&url_string);
|
||||
let ns_url = unsafe { NSURL::URLWithString(&url_nsstring) };
|
||||
let ns_url = NSURL::URLWithString(&url_nsstring);
|
||||
if let Some(ns_url) = ns_url {
|
||||
// Stop accessing the security-scoped resource
|
||||
unsafe {
|
||||
|
||||
@@ -725,7 +725,7 @@ mod android {
|
||||
///
|
||||
/// It maps to the `NotificationManager.IMPORTANCE_*` constants and is serialized as its
|
||||
/// integer value. Only available on Android.
|
||||
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize_repr, Deserialize_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum Importance {
|
||||
/// The notifications are not shown.
|
||||
@@ -737,17 +737,12 @@ mod android {
|
||||
/// The notifications are shown and make a sound.
|
||||
///
|
||||
/// This is the value used when the channel does not define an importance.
|
||||
#[default]
|
||||
Default = 3,
|
||||
/// The notifications are shown, make a sound and pop up as a heads-up notification.
|
||||
High = 4,
|
||||
}
|
||||
|
||||
impl Default for Importance {
|
||||
fn default() -> Self {
|
||||
Self::Default
|
||||
}
|
||||
}
|
||||
|
||||
/// How much of a notification is shown on the lock screen.
|
||||
///
|
||||
/// It maps to the `Notification.VISIBILITY_*` constants and is serialized as its
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
|
||||
///
|
||||
/// - **Android / iOS:** Unsupported.
|
||||
pub fn reveal_item_in_dir<P: AsRef<Path>>(path: P) -> crate::Result<()> {
|
||||
let path = canonicalize(path.as_ref())?;
|
||||
let _path = canonicalize(path.as_ref())?;
|
||||
|
||||
#[cfg(any(
|
||||
windows,
|
||||
@@ -21,7 +21,7 @@ pub fn reveal_item_in_dir<P: AsRef<Path>>(path: P) -> crate::Result<()> {
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
return imp::reveal_items_in_dir(&[path]);
|
||||
return imp::reveal_items_in_dir(&[_path]);
|
||||
|
||||
#[cfg(not(any(
|
||||
windows,
|
||||
|
||||
@@ -87,6 +87,7 @@ impl<R: Runtime> Shell<R> {
|
||||
/// See [`crate::open::open`] for how it handles security-related measures.
|
||||
#[cfg(mobile)]
|
||||
#[deprecated(since = "2.1.0", note = "Use tauri-plugin-opener instead.")]
|
||||
#[allow(deprecated)]
|
||||
pub fn open(&self, path: impl Into<String>, _with: Option<open::Program>) -> Result<()> {
|
||||
self.mobile_plugin_handle
|
||||
.run_mobile_plugin("open", path.into())
|
||||
|
||||
@@ -8,15 +8,20 @@
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(
|
||||
tauri_plugin_single_instance::Builder::new()
|
||||
.callback(move |app, argv, cwd| {
|
||||
println!("{}, {argv:?}, {cwd}", app.package_info().name);
|
||||
})
|
||||
.dbus_id("org.Tauri.SIExampleApp".to_owned())
|
||||
.build(),
|
||||
)
|
||||
let builder = tauri::Builder::default();
|
||||
|
||||
// single-instance is only available on desktop
|
||||
#[cfg(desktop)]
|
||||
let builder = builder.plugin(
|
||||
tauri_plugin_single_instance::Builder::new()
|
||||
.callback(move |app, argv, cwd| {
|
||||
println!("{}, {argv:?}, {cwd}", app.package_info().name);
|
||||
})
|
||||
.dbus_id("org.Tauri.SIExampleApp".to_owned())
|
||||
.build(),
|
||||
);
|
||||
|
||||
builder
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
@@ -5,15 +5,12 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ffi::OsString,
|
||||
io::Cursor,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
use std::ffi::OsStr;
|
||||
|
||||
use base64::Engine;
|
||||
use futures_util::StreamExt;
|
||||
@@ -26,6 +23,10 @@ use reqwest::{
|
||||
};
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Deserializer, Serialize, de::Error as DeError};
|
||||
#[cfg(windows)]
|
||||
use std::ffi::OsStr;
|
||||
#[cfg(desktop)]
|
||||
use std::io::Cursor;
|
||||
use tauri::{
|
||||
AppHandle, Resource, Runtime,
|
||||
utils::{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#![cfg(any(target_os = "linux", target_os = "macos", windows))]
|
||||
#![allow(dead_code, unused_imports)]
|
||||
|
||||
use std::{
|
||||
@@ -376,7 +377,7 @@ fn stage_app_under_test(root_dir: &Path, target: &str, bundle_target: BundleTarg
|
||||
)
|
||||
});
|
||||
|
||||
return staged;
|
||||
staged
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#![cfg(any(target_os = "linux", target_os = "macos", windows))]
|
||||
#![allow(dead_code, unused_imports)]
|
||||
|
||||
use std::{
|
||||
|
||||
Reference in New Issue
Block a user