Skip to content
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
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ global-hotkey = "0.7.0"
iced = { version = "0.14.0", features = ["image", "tokio"] }
icns = "0.3.1"
image = "0.25.9"
libc = "0.2.180"
objc2 = "0.6.3"
objc2-app-kit = { version = "0.3.2", features = ["NSImage"] }
objc2-application-services = { version = "0.3.2", default-features = false, features = [
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.93.0"
components = ['rustfmt', 'clippy', 'rust-src', 'rust-analyzer']
11 changes: 0 additions & 11 deletions src/app/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ impl App {
name: format!("Current RustCast Version: {app_version}"),
name_lc: "version".to_string(),
},
App {
open_command: AppCommand::Function(Function::OpenApp(
"/System/Library/CoreServices/Finder.app".to_string(),
)),
desc: "Application".to_string(),
icons: handle_from_icns(Path::new(
"/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns",
)),
name: "Finder".to_string(),
name_lc: "finder".to_string(),
},
]
}

Expand Down
12 changes: 5 additions & 7 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
pub mod elm;
pub mod update;

use crate::app::apps::App;
use crate::app::tile::elm::default_app_paths;
use crate::app::{ArrowKey, Message, Move, Page};
use crate::clipboard::ClipBoardContentType;
use crate::config::Config;
use crate::utils::open_settings;
use crate::{app::apps::App, platform::default_app_paths};

use arboard::Clipboard;
use global_hotkey::hotkey::HotKey;
Expand All @@ -28,11 +27,10 @@ use objc2_app_kit::NSRunningApplication;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use tray_icon::TrayIcon;

use std::collections::BTreeMap;
use std::fs;
use std::ops::Bound;
use std::path::PathBuf;
use std::time::Duration;
use std::{collections::BTreeMap, path::Path};

/// This is a wrapper around the sender to disable dropping
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -254,7 +252,7 @@ fn handle_hot_reloading() -> impl futures::Stream<Item = Message> {
let paths = default_app_paths();
let mut total_files: usize = paths
.par_iter()
.map(|dir| count_dirs_in_dir(&dir.to_owned().into()))
.map(|dir| count_dirs_in_dir(Path::new(dir)))
.sum();

loop {
Expand All @@ -265,7 +263,7 @@ fn handle_hot_reloading() -> impl futures::Stream<Item = Message> {

let current_total_files: usize = paths
.par_iter()
.map(|dir| count_dirs_in_dir(&dir.to_owned().into()))
.map(|dir| count_dirs_in_dir(Path::new(dir)))
.sum();

if current_content != content {
Expand All @@ -281,7 +279,7 @@ fn handle_hot_reloading() -> impl futures::Stream<Item = Message> {
})
}

fn count_dirs_in_dir(dir: &PathBuf) -> usize {
fn count_dirs_in_dir(dir: impl AsRef<Path>) -> usize {
// Read the directory; if it fails, treat as empty
let entries = match fs::read_dir(dir) {
Ok(e) => e,
Expand Down
35 changes: 6 additions & 29 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,32 @@ use iced::{Alignment, Color, Length, Vector, window};
use iced::{Element, Task};
use iced::{Length::Fill, widget::text_input};

use rayon::{
iter::{IntoParallelRefIterator, ParallelIterator},
slice::ParallelSliceMut,
};
use rayon::slice::ParallelSliceMut;

use crate::app::WINDOW_WIDTH;
use crate::app::pages::clipboard::clipboard_view;
use crate::app::pages::emoji::emoji_page;
use crate::app::tile::AppIndex;
use crate::config::Theme;
use crate::styles::{contents_style, rustcast_text_input_style, tint, with_alpha};
use crate::{app::WINDOW_WIDTH, platform};
use crate::{app::pages::clipboard::clipboard_view, platform::get_installed_apps};
use crate::{
app::{Message, Page, apps::App, default_settings, tile::Tile},
config::Config,
macos::{self, transform_process_to_ui_element},
utils::get_installed_apps,
platform::transform_process_to_ui_element,
};

pub fn default_app_paths() -> Vec<String> {
let user_local_path = std::env::var("HOME").unwrap() + "/Applications/";

let paths = vec![
"/Applications/".to_string(),
user_local_path,
"/System/Applications/".to_string(),
"/System/Applications/Utilities/".to_string(),
];

paths
}

/// Initialise the base window
pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
let (id, open) = window::open(default_settings());

let open = open.discard().chain(window::run(id, |handle| {
macos::macos_window_config(&handle.window_handle().expect("Unable to get window handle"));
platform::window_config(&handle.window_handle().expect("Unable to get window handle"));
transform_process_to_ui_element();
}));

let store_icons = config.theme.show_icons;

let paths = default_app_paths();

let mut options: Vec<App> = paths
.par_iter()
.map(|path| get_installed_apps(path, store_icons))
.flatten()
.collect();
let mut options = get_installed_apps(store_icons);

options.extend(config.shells.iter().map(|x| x.to_app()));
options.extend(App::basic_apps());
Expand Down
28 changes: 7 additions & 21 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,25 @@ use iced::widget::image::Handle;
use iced::widget::operation;
use iced::widget::operation::AbsoluteOffset;
use iced::window;
use rayon::iter::IntoParallelRefIterator;
use rayon::iter::ParallelIterator;
use rayon::slice::ParallelSliceMut;

use crate::app::ArrowKey;
use crate::app::DEFAULT_WINDOW_HEIGHT;
use crate::app::Move;
use crate::app::RUSTCAST_DESC_NAME;
use crate::app::WINDOW_WIDTH;
use crate::app::apps::App;
use crate::app::apps::AppCommand;
use crate::app::default_settings;
use crate::app::menubar::menu_icon;
use crate::app::tile::AppIndex;
use crate::app::tile::elm::default_app_paths;
use crate::app::{Message, Page, tile::Tile};
use crate::calculator::Expr;
use crate::clipboard::ClipBoardContentType;
use crate::commands::Function;
use crate::config::Config;
use crate::haptics::HapticPattern;
use crate::haptics::perform_haptic;
use crate::unit_conversion;
use crate::utils::get_installed_apps;
use crate::utils::is_valid_url;
use crate::{
app::{Message, Page, tile::Tile},
macos::focus_this_app,
};
use crate::{app::ArrowKey, platform::focus_this_app};
use crate::{app::DEFAULT_WINDOW_HEIGHT, platform::perform_haptic};
use crate::{app::Move, platform::HapticPattern};
use crate::{app::RUSTCAST_DESC_NAME, platform::get_installed_apps};

pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
match message {
Expand Down Expand Up @@ -182,12 +173,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
Err(_) => return Task::none(),
};

let mut new_options: Vec<App> = default_app_paths()
.par_iter()
.map(|path| get_installed_apps(path, new_config.theme.show_icons))
.flatten()
.collect();

let mut new_options = get_installed_apps(new_config.theme.show_icons);
new_options.extend(new_config.shells.iter().map(|x| x.to_app()));
new_options.extend(App::basic_apps());
new_options.par_sort_by_key(|x| x.name.len());
Expand Down Expand Up @@ -318,7 +304,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {

Message::SearchQueryChanged(input, id) => {
tile.focus_id = 0;
#[cfg(target_os = "macos")]

if tile.config.haptic_feedback {
perform_haptic(HapticPattern::Alignment);
}
Expand Down
10 changes: 4 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ mod calculator;
mod clipboard;
mod commands;
mod config;
mod haptics;
mod macos;
mod platform;
mod styles;
mod unit_conversion;
mod utils;
Expand All @@ -18,11 +17,10 @@ use crate::{

use global_hotkey::GlobalHotKeyManager;

use self::platform::set_activation_policy_accessory;

fn main() -> iced::Result {
#[cfg(target_os = "macos")]
{
macos::set_activation_policy_accessory();
}
set_activation_policy_accessory();

let home = std::env::var("HOME").unwrap();

Expand Down
Loading