mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 11:22:04 +00:00
chore: fix a few internal docs and apply clippy suggestions (#13131)
* chore: fix a few internal docs * Remove label clone * Unused allow lint * No way clippy just updated * `cargo clippy --fix -- -W clippy::redundant_clone` * format
This commit is contained in:
parent
cf0b3588a3
commit
80dccb6a2e
@ -108,7 +108,6 @@ pub fn rust_section_item(dep: &str, crate_version: CrateVersion) -> SectionItem
|
||||
"🦀",
|
||||
crate_version,
|
||||
version_suffix
|
||||
.clone()
|
||||
.map(|s| format!(",{s}"))
|
||||
.unwrap_or_else(|| "".into())
|
||||
))
|
||||
|
||||
@ -52,7 +52,7 @@ pub trait AppSettings {
|
||||
enabled_features.push("default".into());
|
||||
}
|
||||
|
||||
let target: String = if let Some(target) = options.target.clone() {
|
||||
let target: String = if let Some(target) = options.target {
|
||||
target
|
||||
} else {
|
||||
tauri_utils::platform::target_triple()?
|
||||
|
||||
@ -835,7 +835,7 @@ impl AppSettings for RustAppSettings {
|
||||
.get("deep-link")
|
||||
.and_then(|c| c.get("desktop").cloned())
|
||||
{
|
||||
let protocols: DesktopDeepLinks = serde_json::from_value(plugin_config.clone())?;
|
||||
let protocols: DesktopDeepLinks = serde_json::from_value(plugin_config)?;
|
||||
settings.deep_link_protocols = Some(match protocols {
|
||||
DesktopDeepLinks::One(p) => vec![p],
|
||||
DesktopDeepLinks::List(p) => p,
|
||||
|
||||
@ -31,7 +31,7 @@ impl<'a> SveltePartialLoader<'a> {
|
||||
let mut pointer = 0;
|
||||
|
||||
// find opening "<script"
|
||||
let offset = script_start_finder.find(self.source_text[pointer..].as_bytes())?;
|
||||
let offset = script_start_finder.find(&self.source_text.as_bytes()[pointer..])?;
|
||||
pointer += offset + SCRIPT_START.len();
|
||||
|
||||
// find closing ">"
|
||||
@ -45,7 +45,7 @@ impl<'a> SveltePartialLoader<'a> {
|
||||
let js_start = pointer;
|
||||
|
||||
// find "</script>"
|
||||
let offset = script_end_finder.find(self.source_text[pointer..].as_bytes())?;
|
||||
let offset = script_end_finder.find(&self.source_text.as_bytes()[pointer..])?;
|
||||
let js_end = pointer + offset;
|
||||
|
||||
let source_text = &self.source_text[js_start..js_end];
|
||||
|
||||
@ -25,7 +25,7 @@ impl<'a> VuePartialLoader<'a> {
|
||||
/// Each *.vue file can contain at most
|
||||
/// * one `<script>` block (excluding `<script setup>`).
|
||||
/// * one `<script setup>` block (excluding normal `<script>`).
|
||||
/// <https://vuejs.org/api/sfc-spec.html#script>
|
||||
/// <https://vuejs.org/api/sfc-spec.html#script>
|
||||
fn parse_scripts(&self) -> Vec<JavaScriptSource<'a>> {
|
||||
let mut pointer = 0;
|
||||
let Some(result1) = self.parse_script(&mut pointer) else {
|
||||
@ -42,7 +42,7 @@ impl<'a> VuePartialLoader<'a> {
|
||||
let script_end_finder = Finder::new(SCRIPT_END);
|
||||
|
||||
// find opening "<script"
|
||||
let offset = script_start_finder.find(self.source_text[*pointer..].as_bytes())?;
|
||||
let offset = script_start_finder.find(&self.source_text.as_bytes()[*pointer..])?;
|
||||
*pointer += offset + SCRIPT_START.len();
|
||||
|
||||
// find closing ">"
|
||||
@ -57,7 +57,7 @@ impl<'a> VuePartialLoader<'a> {
|
||||
let js_start = *pointer;
|
||||
|
||||
// find "</script>"
|
||||
let offset = script_end_finder.find(self.source_text[*pointer..].as_bytes())?;
|
||||
let offset = script_end_finder.find(&self.source_text.as_bytes()[*pointer..])?;
|
||||
let js_end = *pointer + offset;
|
||||
*pointer += offset + SCRIPT_END.len();
|
||||
|
||||
|
||||
@ -210,7 +210,7 @@ fn run_build(
|
||||
args: build_options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
config: build_options.config.clone(),
|
||||
config: build_options.config,
|
||||
target_device: None,
|
||||
};
|
||||
let handle = write_options(
|
||||
|
||||
@ -157,7 +157,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
|
||||
.as_ref()
|
||||
.map(|d| d.target().triple.to_string())
|
||||
.unwrap_or_else(|| Target::all().values().next().unwrap().triple.into());
|
||||
dev_options.target = Some(target_triple.clone());
|
||||
dev_options.target = Some(target_triple);
|
||||
|
||||
let (interface, config, metadata) = {
|
||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||
|
||||
@ -1116,7 +1116,6 @@ impl WindowBuilder for WindowBuilderWrapper {
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused_variables, unused_mut)]
|
||||
fn theme(mut self, theme: Option<Theme>) -> Self {
|
||||
self.inner = self.inner.with_theme(if let Some(t) = theme {
|
||||
match t {
|
||||
|
||||
@ -295,7 +295,7 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st
|
||||
fn create_window<F: Fn(RawWindow) + Send + 'static>(
|
||||
&self,
|
||||
pending: PendingWindow<T, Self::Runtime>,
|
||||
before_window_creation: Option<F>,
|
||||
after_window_creation: Option<F>,
|
||||
) -> Result<DetachedWindow<T, Self::Runtime>>;
|
||||
|
||||
/// Create a new webview.
|
||||
|
||||
@ -576,8 +576,7 @@ impl<T: UserEvent, R: Runtime<T>> PartialEq for DetachedWindow<T, R> {
|
||||
}
|
||||
|
||||
/// A raw window type that contains fields to access
|
||||
/// the HWND on Windows, gtk::ApplicationWindow on Linux and
|
||||
/// NSView on macOS.
|
||||
/// the HWND on Windows, gtk::ApplicationWindow on Linux
|
||||
pub struct RawWindow<'a> {
|
||||
#[cfg(windows)]
|
||||
pub hwnd: isize,
|
||||
|
||||
@ -450,7 +450,7 @@ mod tests {
|
||||
))
|
||||
.unwrap(),
|
||||
CapabilityFile::NamedList {
|
||||
capabilities: vec![capability.clone()]
|
||||
capabilities: vec![capability]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ fn extend_identifier_schema(schema: &mut RootSchema, acl: &BTreeMap<String, Mani
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let new_subschemas = Box::new(SubschemaValidation {
|
||||
one_of: Some(permission_schemas.clone()),
|
||||
one_of: Some(permission_schemas),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
|
||||
@ -228,15 +228,15 @@ pub fn does_supported_file_name_exist(target: Target, path: impl Into<PathBuf>)
|
||||
///
|
||||
/// Hierarchy:
|
||||
/// 1. Check if `tauri.conf.json` exists
|
||||
/// a. Parse it with `serde_json`
|
||||
/// b. Parse it with `json5` if `serde_json` fails
|
||||
/// c. Return original `serde_json` error if all above steps failed
|
||||
/// a. Parse it with `serde_json`
|
||||
/// b. Parse it with `json5` if `serde_json` fails
|
||||
/// c. Return original `serde_json` error if all above steps failed
|
||||
/// 2. Check if `tauri.conf.json5` exists
|
||||
/// a. Parse it with `json5`
|
||||
/// b. Return error if all above steps failed
|
||||
/// a. Parse it with `json5`
|
||||
/// b. Return error if all above steps failed
|
||||
/// 3. Check if `Tauri.json` exists
|
||||
/// a. Parse it with `toml`
|
||||
/// b. Return error if all above steps failed
|
||||
/// a. Parse it with `toml`
|
||||
/// b. Return error if all above steps failed
|
||||
/// 4. Return error if all above steps failed
|
||||
pub fn parse(target: Target, path: impl Into<PathBuf>) -> Result<(Config, PathBuf), ConfigError> {
|
||||
do_parse(target, path.into())
|
||||
|
||||
@ -53,7 +53,7 @@ impl MimeType {
|
||||
|
||||
/// parse a URI suffix to convert text/plain mimeType to their actual web compatible mimeType with specified fallback for unknown file extensions.
|
||||
pub fn parse_from_uri_with_fallback(uri: &str, fallback: MimeType) -> MimeType {
|
||||
let suffix = uri.split('.').last();
|
||||
let suffix = uri.split('.').next_back();
|
||||
match suffix {
|
||||
Some("bin") => Self::OctetStream,
|
||||
Some("css" | "less" | "sass" | "styl") => Self::Css,
|
||||
|
||||
@ -240,7 +240,7 @@ const CARGO_OUTPUT_DIRECTORIES: &[&str] = &["debug", "release", "custom-profile"
|
||||
fn is_cargo_output_directory(path: &std::path::Path) -> bool {
|
||||
let last_component = path
|
||||
.components()
|
||||
.last()
|
||||
.next_back()
|
||||
.unwrap()
|
||||
.as_os_str()
|
||||
.to_str()
|
||||
|
||||
@ -329,7 +329,7 @@ mod test {
|
||||
fn listeners_check_key(e in "[a-z]+") {
|
||||
let listeners: Listeners = Default::default();
|
||||
// clone e as the key
|
||||
let key = crate::EventName::new(e.clone()).unwrap();
|
||||
let key = crate::EventName::new(e).unwrap();
|
||||
// pass e and an dummy func into listen
|
||||
listeners.listen(key.clone(), EventTarget::Any, event_fn);
|
||||
|
||||
@ -344,7 +344,7 @@ mod test {
|
||||
#[test]
|
||||
fn listeners_check_fn(e in "[a-z]+") {
|
||||
let listeners: Listeners = Default::default();
|
||||
let key = crate::EventName::new(e.clone()).unwrap();
|
||||
let key = crate::EventName::new(e).unwrap();
|
||||
// pass e and an dummy func into listen
|
||||
listeners.listen(key.clone(), EventTarget::Any, event_fn);
|
||||
|
||||
@ -369,7 +369,7 @@ mod test {
|
||||
#[test]
|
||||
fn check_on_event(e in "[a-z]+", d in "[a-z]+") {
|
||||
let listeners: Listeners = Default::default();
|
||||
let key = crate::EventName::new(e.clone()).unwrap();
|
||||
let key = crate::EventName::new(e).unwrap();
|
||||
// call listen with key and the event_fn dummy func
|
||||
listeners.listen(key.clone(), EventTarget::Any, event_fn);
|
||||
// call on event with key and d.
|
||||
|
||||
@ -1134,7 +1134,7 @@ mod tests {
|
||||
let denied_commands = [(
|
||||
command.to_string(),
|
||||
vec![ResolvedCommand {
|
||||
windows: windows.clone(),
|
||||
windows,
|
||||
..Default::default()
|
||||
}],
|
||||
)]
|
||||
@ -1186,7 +1186,7 @@ mod tests {
|
||||
let resolved_webview_window_remote_cmd = ResolvedCommand {
|
||||
windows: vec![Pattern::new(window).unwrap()],
|
||||
webviews: vec![Pattern::new(webview).unwrap()],
|
||||
referenced_by: referenced_by.clone(),
|
||||
referenced_by,
|
||||
context: ExecutionContext::Remote {
|
||||
url: remote_url.parse().unwrap(),
|
||||
},
|
||||
|
||||
@ -39,7 +39,7 @@ const MIN_JSON_PARSE_LEN: usize = 10_240;
|
||||
///
|
||||
/// 1. `serde_json`'s ability to correctly escape and format json into a string.
|
||||
/// 2. JavaScript engines not accepting anything except another unescaped, literal single quote
|
||||
/// character to end a string that was opened with it.
|
||||
/// character to end a string that was opened with it.
|
||||
fn serialize_js_with<F: FnOnce(&str) -> String>(
|
||||
json_string: String,
|
||||
options: serialize_to_javascript::Options,
|
||||
|
||||
@ -440,7 +440,7 @@ fn parse_invoke_request<R: Runtime>(
|
||||
let (parts, mut body) = request.into_parts();
|
||||
|
||||
// skip leading `/`
|
||||
let cmd = percent_encoding::percent_decode(parts.uri.path()[1..].as_bytes())
|
||||
let cmd = percent_encoding::percent_decode(&parts.uri.path().as_bytes()[1..])
|
||||
.decode_utf8_lossy()
|
||||
.to_string();
|
||||
|
||||
@ -629,7 +629,7 @@ mod tests {
|
||||
"anotherKey": "asda",
|
||||
});
|
||||
|
||||
let mut headers = headers.clone();
|
||||
let mut headers = headers;
|
||||
headers.insert(
|
||||
CONTENT_TYPE,
|
||||
HeaderValue::from_str(mime::APPLICATION_JSON.as_ref()).unwrap(),
|
||||
|
||||
@ -586,10 +586,7 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
|
||||
self.manager().get_webview(label).and_then(|webview| {
|
||||
let window = webview.window();
|
||||
if window.is_webview_window() {
|
||||
Some(WebviewWindow {
|
||||
window: window.clone(),
|
||||
webview,
|
||||
})
|
||||
Some(WebviewWindow { window, webview })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -605,13 +602,7 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
|
||||
.filter_map(|(label, webview)| {
|
||||
let window = webview.window();
|
||||
if window.is_webview_window() {
|
||||
Some((
|
||||
label,
|
||||
WebviewWindow {
|
||||
window: window.clone(),
|
||||
webview,
|
||||
},
|
||||
))
|
||||
Some((label, WebviewWindow { window, webview }))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@ -178,16 +178,12 @@ impl<R: Runtime> WebviewManager<R> {
|
||||
current_window_label = serde_json::to_string(window_label)?,
|
||||
current_webview_label = serde_json::to_string(&label)?,
|
||||
));
|
||||
all_initialization_scripts.push(
|
||||
self
|
||||
.initialization_script(
|
||||
app_manager,
|
||||
&ipc_init.into_string(),
|
||||
&pattern_init.into_string(),
|
||||
use_https_scheme,
|
||||
)?
|
||||
.to_string(),
|
||||
);
|
||||
all_initialization_scripts.push(self.initialization_script(
|
||||
app_manager,
|
||||
&ipc_init.into_string(),
|
||||
&pattern_init.into_string(),
|
||||
use_https_scheme,
|
||||
)?);
|
||||
|
||||
for plugin_init_script in plugin_init_scripts {
|
||||
all_initialization_scripts.push(plugin_init_script.to_string());
|
||||
|
||||
@ -188,7 +188,7 @@ pub fn basename<R: Runtime>(app: AppHandle<R>, path: &str, ext: Option<&str>) ->
|
||||
let maybe_stripped = if let Some(ext) = ext {
|
||||
p.strip_suffix(ext).unwrap_or(&p).to_string()
|
||||
} else {
|
||||
p.to_string()
|
||||
p
|
||||
};
|
||||
Ok(maybe_stripped)
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ fn get_response(
|
||||
window_origin: &str,
|
||||
) -> Result<Response<Cow<'static, [u8]>>, Box<dyn std::error::Error>> {
|
||||
// skip leading `/`
|
||||
let path = percent_encoding::percent_decode(request.uri().path()[1..].as_bytes())
|
||||
let path = percent_encoding::percent_decode(&request.uri().path().as_bytes()[1..])
|
||||
.decode_utf8_lossy()
|
||||
.to_string();
|
||||
|
||||
|
||||
@ -266,7 +266,7 @@ mod tests {
|
||||
let dropping_struct = DroppingStruct(drop_flag.clone());
|
||||
|
||||
let _drop_flag_ignore = Arc::new(RwLock::new(false));
|
||||
let _dropping_struct_ignore = DroppingStruct(_drop_flag_ignore.clone());
|
||||
let _dropping_struct_ignore = DroppingStruct(_drop_flag_ignore);
|
||||
|
||||
state.set::<DroppingStruct>(dropping_struct);
|
||||
assert!(!state.set::<DroppingStruct>(_dropping_struct_ignore));
|
||||
|
||||
@ -1114,10 +1114,7 @@ impl<'de, R: Runtime> CommandArg<'de, R> for WebviewWindow<R> {
|
||||
let webview = command.message.webview();
|
||||
let window = webview.window();
|
||||
if window.is_webview_window() {
|
||||
return Ok(Self {
|
||||
window: window.clone(),
|
||||
webview,
|
||||
});
|
||||
return Ok(Self { window, webview });
|
||||
}
|
||||
|
||||
Err(InvokeError::from("current webview is not a WebviewWindow"))
|
||||
|
||||
@ -341,7 +341,10 @@ tauri::Builder::default()
|
||||
self,
|
||||
webview: Option<PendingWebview<EventLoopMessage, R>>,
|
||||
) -> crate::Result<Window<R>> {
|
||||
let mut pending = PendingWindow::new(self.window_builder.clone(), self.label.clone())?;
|
||||
#[cfg(desktop)]
|
||||
let theme = self.window_builder.get_theme();
|
||||
|
||||
let mut pending = PendingWindow::new(self.window_builder, self.label)?;
|
||||
if let Some(webview) = webview {
|
||||
pending.set_webview(webview);
|
||||
}
|
||||
@ -362,7 +365,7 @@ tauri::Builder::default()
|
||||
#[cfg(desktop)]
|
||||
let handler = app_manager
|
||||
.menu
|
||||
.prepare_window_menu_creation_handler(window_menu.as_ref(), self.window_builder.get_theme());
|
||||
.prepare_window_menu_creation_handler(window_menu.as_ref(), theme);
|
||||
#[cfg(not(desktop))]
|
||||
#[allow(clippy::type_complexity)]
|
||||
let handler: Option<Box<dyn Fn(tauri_runtime::window::RawWindow<'_>) + Send>> = None;
|
||||
|
||||
@ -16,7 +16,7 @@ fn get_stream_response(
|
||||
request: http::Request<Vec<u8>>,
|
||||
) -> Result<http::Response<Vec<u8>>, Box<dyn std::error::Error>> {
|
||||
// skip leading `/`
|
||||
let path = percent_encoding::percent_decode(request.uri().path()[1..].as_bytes())
|
||||
let path = percent_encoding::percent_decode(&request.uri().path().as_bytes()[1..])
|
||||
.decode_utf8_lossy()
|
||||
.to_string();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user