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
11 changes: 3 additions & 8 deletions docs/config.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# Things you can configure

# Full list of modifiers: https://docs.rs/global-hotkey/0.7.0/global_hotkey/hotkey/struct.Modifiers.html#impl-Modifiers
# Do note, CMD is Super on MacOS
# If you are not sure, use google or GenAI to find out.
toggle_mod = "SHIFT"

# Full list of keys: https://docs.rs/global-hotkey/0.7.0/global_hotkey/hotkey/enum.Code.html#variants
# Same things as Modifiers, google if unsure. If something should work, but isn't working, open an issue and I'll help
toggle_key = "1"
# Your hotkey that will be used to toggle rustcast
toggle_hotkey = "ALT+SHIFT+1"

placeholder = "Oopsie Dasies"

# Buffer (all fields are optional bools)
Expand Down
3 changes: 1 addition & 2 deletions docs/default.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Default Config

toggle_mod = "ALT"
toggle_key = "Space"
toggle_hotkey = "ALT+SPACE"
placeholder = "Time to be productive!"
search_url = "https://google.com/search?q=%s"
haptic_feedback = false
Expand Down
10 changes: 5 additions & 5 deletions src/app/menubar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This has the menubar icon logic for the app

use global_hotkey::{hotkey::Code, hotkey::Modifiers};
use global_hotkey::hotkey::{Code, HotKey, Modifiers};
use image::{DynamicImage, ImageReader};
use tray_icon::{
Icon, TrayIcon, TrayIconBuilder,
Expand All @@ -18,13 +18,13 @@ use crate::{
use tokio::runtime::Runtime;

/// This create a new menubar icon for the app
pub fn menu_icon(hotkey: (Option<Modifiers>, Code), hotkey_id: u32, sender: ExtSender) -> TrayIcon {
pub fn menu_icon(hotkey: HotKey, sender: ExtSender) -> TrayIcon {
let builder = TrayIconBuilder::new();

let image = get_image();
let icon = Icon::from_rgba(image.as_bytes().to_vec(), image.width(), image.height()).unwrap();

init_event_handler(sender, hotkey_id);
init_event_handler(sender, hotkey.id());

let menu = Menu::with_items(&[
&version_item(),
Expand Down Expand Up @@ -110,12 +110,12 @@ fn hide_tray_icon() -> MenuItem {
MenuItem::with_id("hide_tray_icon", "Hide Tray Icon", true, None)
}

fn open_item(hotkey: (Option<Modifiers>, Code)) -> MenuItem {
fn open_item(hotkey: HotKey) -> MenuItem {
MenuItem::with_id(
"show_rustcast",
"Toggle View",
true,
Some(Accelerator::new(hotkey.0, hotkey.1)),
Some(Accelerator::new(Some(hotkey.mods), hotkey.key)),
)
}

Expand Down
14 changes: 5 additions & 9 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::config::Config;
use crate::utils::open_settings;

use arboard::Clipboard;
use global_hotkey::hotkey::{Code, Modifiers};
use global_hotkey::hotkey::HotKey;
use global_hotkey::{GlobalHotKeyEvent, HotKeyState};

use iced::futures::SinkExt;
Expand Down Expand Up @@ -69,8 +69,8 @@ pub struct Tile {
focused: bool,
frontmost: Option<Retained<NSRunningApplication>>,
config: Config,
open_hotkey_id: u32,
hotkey: (Option<Modifiers>, Code),
/// The opening hotkey
hotkey: HotKey,
clipboard_content: Vec<ClipBoardContentType>,
tray_icon: Option<TrayIcon>,
sender: Option<ExtSender>,
Expand All @@ -79,12 +79,8 @@ pub struct Tile {

impl Tile {
/// Initialise the base window
pub fn new(
hotkey: (Option<Modifiers>, Code),
keybind_id: u32,
config: &Config,
) -> (Self, Task<Message>) {
elm::new(hotkey, keybind_id, config)
pub fn new(hotkey: HotKey, config: &Config) -> (Self, Task<Message>) {
elm::new(hotkey, config)
}

/// This handles the iced's updates, which have all the variants of [Message]
Expand Down
9 changes: 2 additions & 7 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module handles the logic for the new and view functions according to the elm
//! architecture. If the subscription function becomes too large, it should be moved to this file

use global_hotkey::hotkey::{Code, Modifiers};
use global_hotkey::hotkey::HotKey;
use iced::border::Radius;
use iced::widget::scrollable::{Anchor, Direction, Scrollbar};
use iced::widget::text::LineHeight;
Expand Down Expand Up @@ -38,11 +38,7 @@ pub fn default_app_paths() -> Vec<String> {
}

/// Initialise the base window
pub fn new(
hotkey: (Option<Modifiers>, Code),
keybind_id: u32,
config: &Config,
) -> (Tile, Task<Message>) {
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| {
Expand Down Expand Up @@ -78,7 +74,6 @@ pub fn new(
focused: false,
config: config.clone(),
theme: config.theme.to_owned().into(),
open_hotkey_id: keybind_id,
clipboard_content: vec![],
tray_icon: None,
sender: None,
Expand Down
6 changes: 2 additions & 4 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::path::Path;
use std::thread;
use std::time::Duration;

use global_hotkey::hotkey::HotKey;
use iced::Task;
use iced::widget::image::Handle;
use iced::widget::operation;
Expand Down Expand Up @@ -57,9 +56,8 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {

Message::SetSender(sender) => {
tile.sender = Some(sender.clone());
let hotkey_id = HotKey::new(tile.hotkey.0, tile.hotkey.1).id();
if tile.config.show_trayicon {
tile.tray_icon = Some(menu_icon(tile.hotkey, hotkey_id, sender));
tile.tray_icon = Some(menu_icon(tile.hotkey, sender));
}
Task::none()
}
Expand Down Expand Up @@ -271,7 +269,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
}

Message::KeyPressed(hk_id) => {
if hk_id == tile.open_hotkey_id {
if hk_id == tile.hotkey.id {
tile.visible = !tile.visible;
if tile.visible {
Task::chain(
Expand Down
8 changes: 2 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! This is the config file type definitions for rustcast
use std::{path::Path, sync::Arc};

use global_hotkey::hotkey::Code;

use iced::{Font, font::Family, theme::Custom, widget::image::Handle};
use serde::{Deserialize, Serialize};

Expand All @@ -16,8 +14,7 @@ use crate::{
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct Config {
pub toggle_mod: String,
pub toggle_key: Code,
pub toggle_hotkey: String,
pub buffer_rules: Buffer,
pub theme: Theme,
pub placeholder: String,
Expand All @@ -31,8 +28,7 @@ impl Default for Config {
/// The default config
fn default() -> Self {
Self {
toggle_mod: "ALT".to_string(),
toggle_key: Code::Space,
toggle_hotkey: "ALT+SPACE".to_string(),
buffer_rules: Buffer::default(),
theme: Theme::default(),
placeholder: String::from("Time to be productive!"),
Expand Down
13 changes: 3 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use std::path::Path;

use crate::{app::tile::Tile, config::Config};

use global_hotkey::{
GlobalHotKeyManager,
hotkey::{HotKey, Modifiers},
};
use global_hotkey::GlobalHotKeyManager;

fn main() -> iced::Result {
#[cfg(target_os = "macos")]
Expand All @@ -40,11 +37,7 @@ fn main() -> iced::Result {

let manager = GlobalHotKeyManager::new().unwrap();

let modifier = Modifiers::from_name(&config.toggle_mod);

let key = config.toggle_key;

let show_hide = HotKey::new(modifier, key);
let show_hide = config.toggle_hotkey.parse().unwrap();

// Hotkeys are stored as a vec so that hyperkey support can be added later
let hotkeys = vec![show_hide];
Expand All @@ -54,7 +47,7 @@ fn main() -> iced::Result {
.expect("Unable to register hotkey");

iced::daemon(
move || Tile::new((modifier, key), show_hide.id(), &config),
move || Tile::new(show_hide, &config),
Tile::update,
Tile::view,
)
Expand Down