Skip to content

Commit

Permalink
fmt clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 11, 2024
1 parent 33f1250 commit 4cb12c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
45 changes: 27 additions & 18 deletions crates/rattler_menuinst/src/linux/menu_xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use chrono::Utc;
use fs_err::{self as fs, File};
use quick_xml::events::Event;
use quick_xml::{Reader, Writer};
use thiserror::Error;
use std::io::Write;
use std::path::PathBuf;
use thiserror::Error;

Check failure on line 7 in crates/rattler_menuinst/src/linux/menu_xml.rs

View workflow job for this annotation

GitHub Actions / Check intra-doc links

unused import: `thiserror::Error`

Check failure on line 7 in crates/rattler_menuinst/src/linux/menu_xml.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

unused import: `thiserror::Error`

Check failure on line 7 in crates/rattler_menuinst/src/linux/menu_xml.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

unused import: `thiserror::Error`

use crate::{slugify, MenuInstError};

Expand Down Expand Up @@ -56,16 +56,16 @@ impl MenuXml {
self.menu_config_location.display(),
self.name
);

let contents = self.contents()?;
let mut reader = Reader::from_str(&contents);
reader.config_mut().trim_text(true);

let mut writer = Writer::new_with_indent(Vec::new(), b' ', 2);
let mut buf = Vec::new();
let mut skip_menu = false;
let mut depth = 0;

loop {
match reader.read_event_into(&mut buf)? {
Event::Start(e) => {
Expand Down Expand Up @@ -103,10 +103,10 @@ impl MenuXml {
}
buf.clear();
}

self.write_menu_file(&writer.into_inner())
}

pub fn has_menu(&self) -> Result<bool, MenuInstError> {
let contents = self.contents()?;
let mut reader = Reader::from_str(&contents);
Expand Down Expand Up @@ -163,9 +163,11 @@ impl MenuXml {
let mut reader = reader;
loop {
match reader.read_event_into(&mut buf) {
Ok(Event::Start(e)) => if e.name().as_ref() == b"Menu" {
return true;
},
Ok(Event::Start(e)) => {
if e.name().as_ref() == b"Menu" {
return true;
}
}
Ok(Event::Eof) => break,
_ => (),
}
Expand Down Expand Up @@ -231,7 +233,13 @@ fn main() {
let menu_config = PathBuf::from("applications.menu");
let system_menu_config = PathBuf::from("system_applications.menu");

let menu_xml = MenuXml::new(menu_config, system_menu_config, "Test Menu".to_string(), "user".to_string()).unwrap();
let menu_xml = MenuXml::new(
menu_config,
system_menu_config,
"Test Menu".to_string(),
"user".to_string(),
)
.unwrap();
menu_xml.ensure_menu_file().unwrap();

if menu_xml.has_menu().unwrap() {
Expand All @@ -258,7 +266,8 @@ mod tests {
system_menu_config,
"Test Menu".to_string(),
"user".to_string(),
).unwrap();
)
.unwrap();

(temp_dir, menu_xml)
}
Expand Down Expand Up @@ -325,7 +334,7 @@ mod tests {
#[test]
fn test_remove_menu_xml_structure() {
let (_temp_dir, menu_xml) = setup_test_dir();

// Create initial menu file with content
let initial_content = r#"<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
"http://standards.freedesktop.org/menu-spec/menu-1.0.dtd">
Expand All @@ -340,23 +349,23 @@ mod tests {
</Include>
</Menu>
</Menu>"#;

fs::write(&menu_xml.menu_config_location, initial_content).unwrap();

// Remove the menu
menu_xml.remove_menu().unwrap();

// Read and verify the result
let result = fs::read_to_string(&menu_xml.menu_config_location).unwrap();

insta::assert_snapshot!(result);
}

#[test]
// load file from test data (example.menu) and add a new entry, then remove it
fn test_add_and_remove_menu_xml_structure() {
let (_temp_dir, menu_xml) = setup_test_dir();

let test_data = test_data();
let schema_path = test_data.join("linux-menu/example.menu");

Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_menuinst/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use crate::{

use fs_err as fs;

mod create_shortcut;
mod knownfolders;
mod lex;
mod create_shortcut;

pub struct Directories {
start_menu: PathBuf,
Expand Down
19 changes: 5 additions & 14 deletions crates/rattler_menuinst/src/windows/create_shortcut.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use windows::{
core::*,
Win32::System::Com::*,
Win32::UI::Shell::*,
Win32::System::Com::StructuredStorage::*,
Win32::Storage::EnhancedStorage::PKEY_AppUserModel_ID,
core::*, Win32::Storage::EnhancedStorage::PKEY_AppUserModel_ID,
Win32::System::Com::StructuredStorage::*, Win32::System::Com::*, Win32::UI::Shell::*,
};
use PropertiesSystem::IPropertyStore;

Expand All @@ -24,11 +21,8 @@ fn create_shortcut(
panic!("Failed to initialize COM");
}

let shell_link: IShellLinkW = CoCreateInstance(
&ShellLink as *const GUID,
None,
CLSCTX_INPROC_SERVER
)?;
let shell_link: IShellLinkW =
CoCreateInstance(&ShellLink as *const GUID, None, CLSCTX_INPROC_SERVER)?;

// Get IPersistFile interface
let persist_file: IPersistFile = shell_link.cast()?;
Expand All @@ -47,10 +41,7 @@ fn create_shortcut(
}

if let Some(icon_path) = iconpath {
shell_link.SetIconLocation(
&HSTRING::from(icon_path),
iconindex.unwrap_or(0)
)?;
shell_link.SetIconLocation(&HSTRING::from(icon_path), iconindex.unwrap_or(0))?;
}

// Handle App User Model ID if provided
Expand Down

0 comments on commit 4cb12c3

Please sign in to comment.