Skip to content

Commit b3d586a

Browse files
committed
Merge branch 'master' of https://github.com/ChisomUma/rustcast
2 parents 9e9cd5b + 2459783 commit b3d586a

15 files changed

Lines changed: 428 additions & 114 deletions

File tree

Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
### Via Homebrew:
4949

5050
```
51-
brew install --cask RustCastLabs/tap/rustcast
51+
brew install --cask unsecretised/tap/rustcast
5252
```
5353

5454
### Via github releases

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ <h2>Up and running<br />in 30 seconds</h2>
359359
</div>
360360
<div class="install-code" id="brew-code">
361361
<span class="comment"># Tap the cask and install</span><br>
362-
<span class="cmd">brew tap</span> RustCastLabs/tap<br>
362+
<span class="cmd">brew tap</span> unsecretised/tap<br>
363363
<span class="cmd">brew install --cask</span> rustcast<br>
364364
</div>
365365
</div>

src/app.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::app::apps::{App, AppCommand, ICNS_ICON};
55
use crate::commands::Function;
66
use crate::config::{Config, MainPage, Shelly};
77
use crate::debounce::DebouncePolicy;
8+
use crate::platform::macos::launching::Shortcut;
89
use crate::utils::icns_data_to_handle;
910
use crate::{app::tile::ExtSender, clipboard::ClipBoardContentType};
1011
use iced::time::Duration;
@@ -81,6 +82,7 @@ pub enum Editable<T> {
8182
pub enum Message {
8283
WriteConfig(bool),
8384
SaveRanking,
85+
ToggleAutoStartup(bool),
8486
LoadRanking,
8587
ToggleFavouriteApp(String),
8688
UpdateAvailable,
@@ -89,7 +91,7 @@ pub enum Message {
8991
OpenResult(u32),
9092
OpenToSettings,
9193
SearchQueryChanged(String, Id),
92-
KeyPressed(u32),
94+
KeyPressed(Shortcut),
9395
FocusTextInput(Move),
9496
HideWindow(Id),
9597
RunFunction(Function),
@@ -124,6 +126,7 @@ pub enum SetConfigFields {
124126
ClipboardHotkey(String),
125127
PlaceHolder(String),
126128
SearchUrl(String),
129+
ClipboardHistory(bool),
127130
HapticFeedback(bool),
128131
ShowMenubarIcon(bool),
129132
SetPage(MainPage),

src/app/apps.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io::Cursor;
66

77
use iced::{
88
Alignment,
9-
Length::Fill,
9+
Length::{self, Fill},
1010
widget::{
1111
Button, Row, Text, container,
1212
image::{Handle, Viewer},
@@ -18,7 +18,7 @@ use crate::{
1818
app::{Message, Page, RUSTCAST_DESC_NAME},
1919
clipboard::ClipBoardContentType,
2020
commands::Function,
21-
styles::{result_button_style, result_row_container_style},
21+
styles::{favourite_button_style, result_button_style, result_row_container_style},
2222
utils::icns_data_to_handle,
2323
};
2424

@@ -214,9 +214,10 @@ impl App {
214214
let name = self.search_name.clone();
215215
let theme_clone = theme.clone();
216216
row = row.push(
217-
Button::new("♥️")
217+
Button::new(Text::new("♥️").width(Length::Fill).align_x(Alignment::End))
218218
.on_press_with(move || Message::ToggleFavouriteApp(name.clone()))
219-
.style(move |_, _| result_button_style(&theme_clone)),
219+
.width(Length::Fill)
220+
.style(move |_, status| favourite_button_style(&theme_clone, status)),
220221
);
221222

222223
let msg = on_press.or(match self.open_command.clone() {

src/app/menubar.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{collections::HashMap, io::Cursor};
44

5-
use global_hotkey::hotkey::{Code, HotKey, Modifiers};
5+
use global_hotkey::hotkey::{Code, Modifiers};
66
use image::{DynamicImage, ImageReader};
77
use log::info;
88
use tray_icon::{
@@ -16,6 +16,7 @@ use tray_icon::{
1616
use crate::{
1717
app::{Message, tile::ExtSender},
1818
config::Config,
19+
platform::macos::launching::Shortcut,
1920
utils::open_url,
2021
};
2122

@@ -39,14 +40,15 @@ pub fn menu_icon(config: Config, sender: ExtSender) -> TrayIcon {
3940
}
4041

4142
pub fn menu_builder(config: Config, sender: ExtSender, update_item: bool) -> Menu {
42-
let hotkey = config.toggle_hotkey.parse::<HotKey>().ok();
43+
let shortcut =
44+
Shortcut::parse(&config.toggle_hotkey).unwrap_or(Shortcut::parse("opt+space").unwrap());
4345

4446
let mut modes = config.modes;
4547
if !modes.contains_key("default") {
4648
modes.insert("Default".to_string(), "default".to_string());
4749
}
4850

49-
init_event_handler(sender, hotkey.map(|x| x.id));
51+
init_event_handler(sender, shortcut);
5052

5153
Menu::with_items(&[
5254
&MenuItem::with_id(
@@ -64,7 +66,7 @@ pub fn menu_builder(config: Config, sender: ExtSender, update_item: bool) -> Men
6466
&open_github_item(),
6567
&PredefinedMenuItem::separator(),
6668
&refresh_item(),
67-
&open_item(hotkey),
69+
&open_item(),
6870
&mode_item(modes),
6971
&PredefinedMenuItem::separator(),
7072
&open_issue_item(),
@@ -86,10 +88,12 @@ fn get_image() -> DynamicImage {
8688
.unwrap()
8789
}
8890

89-
fn init_event_handler(sender: ExtSender, hotkey_id: Option<u32>) {
91+
fn init_event_handler(sender: ExtSender, shortcut: Shortcut) {
9092
let runtime = Runtime::new().unwrap();
93+
let shortcut = shortcut.clone();
9194

9295
MenuEvent::set_event_handler(Some(move |x: MenuEvent| {
96+
let shortcut = shortcut.clone();
9397
let sender = sender.clone();
9498
let sender = sender.0.clone();
9599
info!("Menubar event called: {}", x.id.0);
@@ -107,11 +111,12 @@ fn init_event_handler(sender: ExtSender, hotkey_id: Option<u32>) {
107111
open_url("https://github.com/RustCastLabs/rustcast/issues/new");
108112
}
109113
"show_rustcast" => {
110-
if let Some(hk) = hotkey_id {
111-
runtime.spawn(async move {
112-
sender.clone().try_send(Message::KeyPressed(hk)).unwrap();
113-
});
114-
}
114+
runtime.spawn(async move {
115+
sender
116+
.clone()
117+
.try_send(Message::KeyPressed(shortcut.clone()))
118+
.unwrap();
119+
});
115120
}
116121
"update" => {
117122
open_url("https://github.com/RustCastLabs/rustcast/releases/latest");
@@ -178,13 +183,8 @@ fn mode_item(modes: HashMap<String, String>) -> Submenu {
178183
Submenu::with_items("Modes", true, &items).unwrap()
179184
}
180185

181-
fn open_item(hotkey: Option<HotKey>) -> MenuItem {
182-
MenuItem::with_id(
183-
"show_rustcast",
184-
"Toggle View",
185-
true,
186-
hotkey.map(|hk| Accelerator::new(Some(hk.mods), hk.key)),
187-
)
186+
fn open_item() -> MenuItem {
187+
MenuItem::with_id("show_rustcast", "Toggle View", true, None)
188188
}
189189

190190
fn open_github_item() -> MenuItem {

src/app/pages/settings.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
4444
.width(Length::Fill)
4545
.style(move |_, _| settings_text_input_item_style(&hotkey_theme))
4646
.into(),
47-
notice_item(theme.clone(), "Requires a restart"),
47+
notice_item(theme.clone(), "Use \"+\" as a seperator"),
4848
]);
4949

5050
let cb_theme = theme.clone();
@@ -56,7 +56,7 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
5656
.width(Length::Fill)
5757
.style(move |_, _| settings_text_input_item_style(&cb_theme))
5858
.into(),
59-
notice_item(theme.clone(), "Requires a restart"),
59+
notice_item(theme.clone(), "Use \"+\" as a seperator"),
6060
]);
6161

6262
let placeholder_theme = theme.clone();
@@ -83,6 +83,23 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
8383
notice_item(theme.clone(), "Which search engine to use (%s = query)"),
8484
]);
8585

86+
let theme_clone = theme.clone();
87+
let clipboard_history = Row::from_iter([
88+
settings_hint_text(theme.clone(), "Enable Clipboard history"),
89+
checkbox(config.clone().cbhist)
90+
.style(move |_, _| settings_checkbox_style(&theme_clone))
91+
.on_toggle(|input| Message::SetConfig(SetConfigFields::ClipboardHistory(input)))
92+
.into(),
93+
notice_item(
94+
theme.clone(),
95+
"If you want your clipboard history to be stored",
96+
),
97+
])
98+
.align_y(Alignment::Center)
99+
.spacing(SETTINGS_ITEM_COL_SPACING * 2)
100+
.padding(SETTINGS_ITEM_PADDING)
101+
.height(SETTINGS_ITEM_HEIGHT);
102+
86103
let theme_clone = theme.clone();
87104
let current_delay = config.debounce_delay;
88105
let debounce = settings_item_column([
@@ -102,6 +119,16 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
102119
),
103120
]);
104121

122+
let theme_clone = theme.clone();
123+
let start_at_login = settings_item_row([
124+
settings_hint_text(theme.clone(), "Start at login"),
125+
checkbox(config.clone().start_at_login)
126+
.style(move |_, _| settings_checkbox_style(&theme_clone))
127+
.on_toggle(Message::ToggleAutoStartup)
128+
.into(),
129+
notice_item(theme.clone(), "If you want rustcast to start on login"),
130+
]);
131+
105132
let theme_clone = theme.clone();
106133
let haptic = Row::from_iter([
107134
settings_hint_text(theme.clone(), "Haptic feedback"),
@@ -394,8 +421,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
394421
placeholder_setting.into(),
395422
search.into(),
396423
debounce.into(),
424+
start_at_login.into(),
397425
haptic.into(),
398426
tray_icon.into(),
427+
clipboard_history.into(),
399428
auto_suggest.into(),
400429
show_scrollbar.into(),
401430
clear_on_hide.into(),

src/app/tile.rs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ pub mod update;
55
use crate::app::apps::App;
66
use crate::app::{ArrowKey, Message, Move, Page};
77
use crate::clipboard::ClipBoardContentType;
8-
use crate::config::Config;
8+
use crate::config::{Config, Shelly};
99
use crate::debounce::Debouncer;
1010
use crate::platform::default_app_paths;
11+
use crate::platform::macos::launching::Shortcut;
1112

12-
use global_hotkey::hotkey::HotKey;
13-
use global_hotkey::{GlobalHotKeyEvent, HotKeyState};
1413

1514
use iced::futures::SinkExt;
1615
use iced::futures::channel::mpsc::{Sender, channel};
@@ -191,9 +190,9 @@ pub struct Tile {
191190
/// Stores the toggle [`HotKey`] and the Clipboard [`HotKey`]
192191
#[derive(Clone, Debug)]
193192
pub struct Hotkeys {
194-
pub toggle: HotKey,
195-
pub clipboard_hotkey: HotKey,
196-
pub shells: HashMap<u32, String>,
193+
pub toggle: Shortcut,
194+
pub clipboard_hotkey: Shortcut,
195+
pub shells: HashMap<Shortcut, Shelly>,
197196
}
198197

199198
impl Tile {
@@ -230,7 +229,6 @@ impl Tile {
230229
_ => None,
231230
});
232231
Subscription::batch([
233-
Subscription::run(handle_hotkeys),
234232
Subscription::run(handle_hot_reloading),
235233
keyboard,
236234
Subscription::run(handle_recipient),
@@ -242,37 +240,34 @@ impl Tile {
242240
if let keyboard::Event::KeyPressed { key, modifiers, .. } = event {
243241
match key {
244242
keyboard::Key::Named(Named::ArrowUp) => {
245-
return Some(Message::ChangeFocus(ArrowKey::Up, 1));
243+
Some(Message::ChangeFocus(ArrowKey::Up, 1))
246244
}
247245
keyboard::Key::Named(Named::ArrowLeft) => {
248-
return Some(Message::ChangeFocus(ArrowKey::Left, 1));
246+
Some(Message::ChangeFocus(ArrowKey::Left, 1))
249247
}
250248
keyboard::Key::Named(Named::ArrowRight) => {
251-
return Some(Message::ChangeFocus(ArrowKey::Right, 1));
249+
Some(Message::ChangeFocus(ArrowKey::Right, 1))
252250
}
253251
keyboard::Key::Named(Named::ArrowDown) => {
254-
return Some(Message::ChangeFocus(ArrowKey::Down, 1));
252+
Some(Message::ChangeFocus(ArrowKey::Down, 1))
255253
}
256254
keyboard::Key::Character(chr) => {
257255
if modifiers.command() && chr.to_string() == "r" {
258-
return Some(Message::ReloadConfig);
256+
Some(Message::ReloadConfig)
259257
} else if chr.to_string() == "p" && modifiers.control() {
260-
return Some(Message::ChangeFocus(ArrowKey::Up, 1));
258+
Some(Message::ChangeFocus(ArrowKey::Up, 1))
261259
} else if chr.to_string() == "n" && modifiers.control() {
262-
return Some(Message::ChangeFocus(ArrowKey::Down, 1));
260+
Some(Message::ChangeFocus(ArrowKey::Down, 1))
263261
} else {
264-
return Some(Message::FocusTextInput(Move::Forwards(
265-
chr.to_string(),
266-
)));
262+
Some(Message::FocusTextInput(Move::Forwards(chr.to_string())))
267263
}
268264
}
269-
keyboard::Key::Named(Named::Enter) => return Some(Message::OpenFocused),
265+
keyboard::Key::Named(Named::Enter) => Some(Message::OpenFocused),
270266
keyboard::Key::Named(Named::Backspace) => {
271-
return Some(Message::FocusTextInput(Move::Back));
267+
Some(Message::FocusTextInput(Move::Back))
272268
}
273-
_ => {}
269+
_ => None,
274270
}
275-
None
276271
} else {
277272
None
278273
}
@@ -338,22 +333,6 @@ impl Tile {
338333
}
339334
}
340335

341-
/// This is the subscription function that handles hotkeys, e.g. for hiding / showing the window
342-
fn handle_hotkeys() -> impl futures::Stream<Item = Message> {
343-
stream::channel(100, async |mut output| {
344-
let receiver = GlobalHotKeyEvent::receiver();
345-
loop {
346-
info!("Hotkey received");
347-
if let Ok(event) = receiver.recv()
348-
&& event.state == HotKeyState::Pressed
349-
{
350-
output.try_send(Message::KeyPressed(event.id)).unwrap();
351-
}
352-
tokio::time::sleep(Duration::from_millis(100)).await;
353-
}
354-
})
355-
}
356-
357336
/// This is the subscription function that handles the change in clipboard history
358337
fn handle_clipboard_history() -> impl futures::Stream<Item = Message> {
359338
stream::channel(100, async |mut output| {
@@ -629,7 +608,6 @@ fn handle_recipient() -> impl futures::Stream<Item = Message> {
629608
let abcd = recipient
630609
.try_recv()
631610
.map(async |msg| {
632-
info!("Sending a message");
633611
output.send(msg).await.unwrap();
634612
})
635613
.ok();

0 commit comments

Comments
 (0)