Skip to content

Commit

Permalink
feat: add linting & refactor code (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xithrius authored Jan 6, 2023
1 parent b2a4446 commit 5041e3d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
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};

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};

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

0 comments on commit 5041e3d

Please sign in to comment.