Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of #![warn(clippy::nursery, clippy::pedantic)]. #27

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#![warn(clippy::nursery, clippy::pedantic)]

mod util;

use tauri::{
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
};

#[allow(unused_imports)]
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial};
Xithrius marked this conversation as resolved.
Show resolved Hide resolved

use util::{
convert_all_app_icons_to_png, create_preferences_if_missing, get_icon, handle_input,
launch_on_login, open_command,
};
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial};
Xithrius marked this conversation as resolved.
Show resolved Hide resolved

fn create_system_tray() -> SystemTray {
let quit = CustomMenuItem::new("Quit".to_string(), "Quit");
Expand All @@ -21,6 +27,7 @@ fn create_system_tray() -> SystemTray {
.add_item(quit);
SystemTray::new().with_menu(tray_menu)
}

fn main() {
convert_all_app_icons_to_png();
create_preferences_if_missing();
Expand Down
20 changes: 13 additions & 7 deletions src-tauri/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ mod calculator;
mod icons;
mod preferences;
mod search;
use std::process::Command;

extern crate directories;
use directories::ProjectDirs;
extern crate plist;

use auto_launch::AutoLaunchBuilder;
use calculator::calculate;
use directories::ProjectDirs;
use std::{process::Command, time::Instant};

pub use icons::convert_all_app_icons_to_png;
pub use preferences::create_preferences_if_missing;
pub use search::{search, similarity_sort, ResultType};
use std::time::Instant;
pub use search::{search, similarity_sort};

pub enum ResultType {
Applications = 1,
Files = 2,
Calculation = 3,
}

#[tauri::command]
pub async fn handle_input(input: String) -> (Vec<String>, f32, i32) {
Expand Down Expand Up @@ -59,12 +67,10 @@ pub fn get_icon(app_name: &str) -> String {
let icon_path = icon_dir.join(app_name.to_owned() + &".png");
if icon_path.exists() {
return icon_path.to_str().unwrap().to_owned();
} else {
return String::from("");
}
} else {
return String::from("");
}
return String::from("");
}

#[tauri::command]
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/util/calculator.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use chrono::{Local, TimeZone};
use chrono_tz::OffsetName;
use chrono_tz::Tz;
use chrono_tz::{OffsetName, Tz};

use num_format::SystemLocale;
use smartcalc::*;
use smartcalc::SmartCalc;

pub fn calculate(input: &str) -> String {
let locale = SystemLocale::default().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/util/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ fn get_icon_path(app_path: &str) -> String {
if icon_path.is_some() {
let icon_path = icon_path.unwrap().as_string().unwrap();
return app_path.to_owned() + &"/Contents/Resources/" + icon_path + &".icns";
} else {
return String::from("");
}

return String::from("");
}
Err(_) => {
return String::from("");
Expand Down
26 changes: 16 additions & 10 deletions src-tauri/src/util/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ struct Theme {
dark_overlay: String,
}

impl Default for Theme {
fn default() -> Self {
Self {
primary_bg_color: String::from("rgba(20, 20, 30, 0.6)"),
secondary_bg_color: String::from("rgba(84, 101, 115, 0.6)"),
primary_text_color: String::from("#FFFFFF"),
secondary_text_color: String::from("#878787"),
primary_accent_color: String::from("#556CE5"),
secondary_accent_color: String::from("#48A5FF"),
highlight_overlay: String::from("rgba(255, 255, 255, 0.1)"),
dark_overlay: String::from("rgba(0, 0, 0, 0.1)"),
}
}
}

#[derive(Serialize, Deserialize)]
struct Preferences {
shortcut: String,
Expand All @@ -35,16 +50,7 @@ pub fn create_preferences_if_missing() {
fs::write(preferences_path, &preference_text).unwrap();
}
if !theme_path.exists() {
let theme = Theme {
primary_bg_color: String::from("rgba(20, 20, 30, 0.6)"),
secondary_bg_color: String::from("rgba(84, 101, 115, 0.6)"),
primary_text_color: String::from("#FFFFFF"),
secondary_text_color: String::from("#878787"),
primary_accent_color: String::from("#556CE5"),
secondary_accent_color: String::from("#48A5FF"),
highlight_overlay: String::from("rgba(255, 255, 255, 0.1)"),
dark_overlay: String::from("rgba(0, 0, 0, 0.1)"),
};
let theme = Theme::default();
let theme_text = serde_json::to_string(&theme).unwrap();
fs::write(theme_path, &theme_text).unwrap();
}
Expand Down
6 changes: 0 additions & 6 deletions src-tauri/src/util/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ use rust_search::SearchBuilder;
use std::path::Path;
use strsim::jaro_winkler;

pub enum ResultType {
Applications = 1,
Files = 2,
Calculation = 3,
}

fn file_name_from_path(path: &str) -> String {
let path = Path::new(path);
let file_name = path.file_name().unwrap().to_str().unwrap();
Expand Down