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
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on:
pull_request:

permissions:
contents: read

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
fmt:
name: 'Format (rustfmt)'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Rust (stable + rustfmt)
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: cargo fmt --check
run: cargo fmt --all --check

test:
name: 'Test / Clippy (${{ matrix.rust }}, ${{ matrix.os }})'
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os:
- macos-latest
rust:
- stable
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rust (${{ matrix.rust }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: cargo clippy
run: cargo clippy --all-targets

- name: cargo test
run: cargo test --all-targets
25 changes: 0 additions & 25 deletions .github/workflows/merges.yml

This file was deleted.

3 changes: 3 additions & 0 deletions docs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ haptic_feedback = true
# Show the tray icon
show_trayicon = true

# hotkey for opening clipboard history
clipboard_hotkey = "SUPER+SHIFT+2"


[theme]

Expand Down
1 change: 1 addition & 0 deletions docs/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ search_url = "https://google.com/search?q=%s"
haptic_feedback = false
show_trayicon = true
shells = []
clipboard_hotkey = "SUPER+SHIFT+C"

[buffer_rules]
clear_on_hide = true
Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub enum Move {
/// The message type that iced uses for actions that can do something
#[derive(Debug, Clone)]
pub enum Message {
ResizeWindow(Id, f32),
OpenWindow,
SearchQueryChanged(String, Id),
KeyPressed(u32),
Expand Down
10 changes: 8 additions & 2 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ pub struct Tile {
frontmost: Option<Retained<NSRunningApplication>>,
pub config: Config,
/// The opening hotkey
hotkey: HotKey,
clipboard_hotkey: Option<HotKey>,
hotkeys: Hotkeys,
clipboard_content: Vec<ClipBoardContentType>,
tray_icon: Option<TrayIcon>,
sender: Option<ExtSender>,
page: Page,
pub height: f32,
}

#[derive(Clone)]
pub struct Hotkeys {
pub toggle: HotKey,
pub clipboard_hotkey: HotKey,
}

impl Tile {
Expand Down
18 changes: 12 additions & 6 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use iced::{Length::Fill, widget::text_input};

use rayon::slice::ParallelSliceMut;

use crate::app::DEFAULT_WINDOW_HEIGHT;
use crate::app::pages::emoji::emoji_page;
use crate::app::tile::AppIndex;
use crate::app::tile::{AppIndex, Hotkeys};
use crate::config::Theme;
use crate::styles::{contents_style, rustcast_text_input_style, tint, with_alpha};
use crate::{app::WINDOW_WIDTH, platform};
Expand Down Expand Up @@ -42,6 +43,14 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
options.par_sort_by_key(|x| x.name.len());
let options = AppIndex::from_apps(options);

let hotkeys = Hotkeys {
toggle: hotkey,
clipboard_hotkey: config
.clipboard_hotkey
.parse()
.unwrap_or("SUPER+SHIFT+C".parse().unwrap()),
};

(
Tile {
query: String::new(),
Expand All @@ -50,12 +59,8 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
results: vec![],
options,
emoji_apps: AppIndex::from_apps(App::emoji_apps()),
hotkey,
hotkeys,
visible: true,
clipboard_hotkey: config
.clipboard_hotkey
.clone()
.and_then(|x| x.parse::<HotKey>().ok()),
frontmost: None,
focused: false,
config: config.clone(),
Expand All @@ -64,6 +69,7 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
tray_icon: None,
sender: None,
page: Page::Main,
height: DEFAULT_WINDOW_HEIGHT,
},
Task::batch([open.map(|_| Message::OpenWindow)]),
)
Expand Down
104 changes: 49 additions & 55 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use iced::widget::image::Handle;
use iced::widget::operation;
use iced::widget::operation::AbsoluteOffset;
use iced::window;
use iced::window::Id;
use rayon::slice::ParallelSliceMut;

use crate::app::WINDOW_WIDTH;
Expand Down Expand Up @@ -50,7 +51,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
Message::SetSender(sender) => {
tile.sender = Some(sender.clone());
if tile.config.show_trayicon {
tile.tray_icon = Some(menu_icon(tile.hotkey, sender));
tile.tray_icon = Some(menu_icon(tile.hotkeys.toggle, sender));
}
Task::none()
}
Expand Down Expand Up @@ -158,6 +159,17 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
])
}

Message::ResizeWindow(id, height) => {
tile.height = height;
window::resize(
id,
iced::Size {
width: WINDOW_WIDTH,
height,
},
)
}

Message::OpenFocused => match tile.results.get(tile.focus_id as usize) {
Some(App {
open_command: AppCommand::Function(func),
Expand Down Expand Up @@ -198,11 +210,8 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
}

Message::KeyPressed(hk_id) => {
let is_clipboard_hotkey = tile
.clipboard_hotkey
.map(|hotkey| hotkey.id == hk_id)
.unwrap_or(false);
let is_open_hotkey = hk_id == tile.hotkey.id;
let is_clipboard_hotkey = tile.hotkeys.clipboard_hotkey.id == hk_id;
let is_open_hotkey = hk_id == tile.hotkeys.toggle.id;

let clipboard_page_task = if is_clipboard_hotkey {
Task::done(Message::SwitchToPage(Page::ClipboardHistory))
Expand All @@ -214,7 +223,12 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {

if is_open_hotkey || is_clipboard_hotkey {
if !tile.visible {
return Task::batch([open_window(), clipboard_page_task]);
tile.height = if is_clipboard_hotkey {
((7 * 55) + 35 + DEFAULT_WINDOW_HEIGHT as usize) as f32
} else {
DEFAULT_WINDOW_HEIGHT
};
return Task::batch([open_window(tile.height), clipboard_page_task]);
}

tile.visible = !tile.visible;
Expand Down Expand Up @@ -316,6 +330,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
}

Message::SearchQueryChanged(input, id) => {
let mut task = Task::none();
tile.focus_id = 0;

if tile.config.haptic_feedback {
Expand All @@ -327,13 +342,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
let prev_size = tile.results.len();
if tile.query_lc.is_empty() && tile.page != Page::ClipboardHistory {
tile.results = vec![];
return window::resize(
id,
iced::Size {
width: WINDOW_WIDTH,
height: DEFAULT_WINDOW_HEIGHT,
},
);
return Task::done(Message::ResizeWindow(id, DEFAULT_WINDOW_HEIGHT));
} else if tile.query_lc == "randomvar" {
let rand_num = rand::random_range(0..100);
tile.results = vec![App {
Expand All @@ -343,13 +352,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
name: rand_num.to_string(),
name_lc: String::new(),
}];
return window::resize(
id,
iced::Size {
width: WINDOW_WIDTH,
height: 55. + DEFAULT_WINDOW_HEIGHT,
},
);
return single_item_resize_task(id);
} else if tile.query_lc == "67" {
tile.results = vec![App {
open_command: AppCommand::Function(Function::RandomVar(67)),
Expand All @@ -358,13 +361,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
name: 67.to_string(),
name_lc: String::new(),
}];
return window::resize(
id,
iced::Size {
width: WINDOW_WIDTH,
height: 55. + DEFAULT_WINDOW_HEIGHT,
},
);
return single_item_resize_task(id);
} else if tile.query_lc.ends_with("?") {
tile.results = vec![App {
open_command: AppCommand::Function(Function::GoogleSearch(tile.query.clone())),
Expand All @@ -373,14 +370,12 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
name: format!("Search for: {}", tile.query),
name_lc: String::new(),
}];
return window::resize(
id,
iced::Size::new(WINDOW_WIDTH, 55. + DEFAULT_WINDOW_HEIGHT),
);
} else if tile.query_lc == "cbhist" {
task = task.chain(Task::done(Message::SwitchToPage(Page::ClipboardHistory)));
tile.page = Page::ClipboardHistory
} else if tile.query_lc == "main" {
tile.page = Page::Main
} else if tile.query_lc == "main" && tile.page != Page::Main {
task = task.chain(Task::done(Message::SwitchToPage(Page::Main)));
tile.page = Page::Main;
}
tile.handle_search_query_changed();

Expand Down Expand Up @@ -460,39 +455,38 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
let max_elem = min(5, new_length);

if prev_size != new_length && tile.page != Page::ClipboardHistory {
Task::batch([
window::resize(
task.chain(Task::batch([
Task::done(Message::ResizeWindow(
id,
iced::Size {
width: WINDOW_WIDTH,
height: ((max_elem * 55) + 35 + DEFAULT_WINDOW_HEIGHT as usize) as f32,
},
),
((max_elem * 55) + 35 + DEFAULT_WINDOW_HEIGHT as usize) as f32,
)),
Task::done(Message::ChangeFocus(ArrowKey::Left)),
])
]))
} else if tile.page == Page::ClipboardHistory {
Task::batch([
window::resize(
task.chain(Task::batch([
Task::done(Message::ResizeWindow(
id,
iced::Size {
width: WINDOW_WIDTH,
height: ((7 * 55) + 35 + DEFAULT_WINDOW_HEIGHT as usize) as f32,
},
),
((7 * 55) + 35 + DEFAULT_WINDOW_HEIGHT as usize) as f32,
)),
Task::done(Message::ChangeFocus(ArrowKey::Left)),
])
]))
} else {
Task::none()
task
}
}
}
}

fn open_window() -> Task<Message> {
Task::chain(
fn open_window(height: f32) -> Task<Message> {
Task::batch([
window::open(default_settings())
.1
.map(|_| Message::OpenWindow),
.map(move |id| Message::ResizeWindow(id, height)),
Task::done(Message::OpenWindow),
operation::focus("query"),
)
])
}

fn single_item_resize_task(id: Id) -> Task<Message> {
Task::done(Message::ResizeWindow(id, 55. + DEFAULT_WINDOW_HEIGHT))
}
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
#[serde(default)]
pub struct Config {
pub toggle_hotkey: String,
pub clipboard_hotkey: Option<String>,
pub clipboard_hotkey: String,
pub buffer_rules: Buffer,
pub theme: Theme,
pub placeholder: String,
Expand All @@ -30,7 +30,7 @@ impl Default for Config {
fn default() -> Self {
Self {
toggle_hotkey: "ALT+SPACE".to_string(),
clipboard_hotkey: None,
clipboard_hotkey: "SUPER+SHIFT+C".to_string(),
buffer_rules: Buffer::default(),
theme: Theme::default(),
placeholder: String::from("Time to be productive!"),
Expand Down
Loading