Skip to content

Commit c977433

Browse files
authored
Merge pull request #207 from unsecretised/settings-page
Settings page
2 parents 4a7eff1 + ce64125 commit c977433

14 files changed

Lines changed: 684 additions & 385 deletions

File tree

Cargo.lock

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

src/app.rs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum Page {
3737
FileSearch,
3838
ClipboardHistory,
3939
EmojiSearch,
40+
Settings,
4041
}
4142

4243
impl std::fmt::Display for Page {
@@ -46,6 +47,7 @@ impl std::fmt::Display for Page {
4647
Page::FileSearch => "File search",
4748
Page::EmojiSearch => "Emoji search",
4849
Page::ClipboardHistory => "Clipboard history",
50+
Page::Settings => "Settings",
4951
})
5052
}
5153
}
@@ -70,15 +72,18 @@ pub enum Move {
7072
/// The message type that iced uses for actions that can do something
7173
#[derive(Debug, Clone)]
7274
pub enum Message {
75+
WriteConfig,
7376
UpdateAvailable,
7477
ResizeWindow(Id, f32),
7578
OpenWindow,
79+
OpenToSettings,
7680
SearchQueryChanged(String, Id),
7781
KeyPressed(u32),
7882
FocusTextInput(Move),
7983
HideWindow(Id),
8084
RunFunction(Function),
8185
OpenFocused,
86+
SetConfig(SetConfigFields),
8287
ReturnFocus,
8388
EscKeyPressed(Id),
8489
ClearSearchResults,
@@ -97,6 +102,37 @@ pub enum Message {
97102
DebouncedSearch(Id),
98103
}
99104

105+
#[derive(Debug, Clone)]
106+
pub enum SetConfigFields {
107+
ToDefault,
108+
ToggleHotkey(String),
109+
ClipboardHotkey(String),
110+
PlaceHolder(String),
111+
SearchUrl(String),
112+
HapticFeedback(bool),
113+
ShowMenubarIcon(bool),
114+
// Modes(HashMap<String, String>),
115+
// Aliases(HashMap<String, String>),
116+
// SearchDirs(Vec<String>),
117+
DebounceDelay(u64),
118+
SetThemeFields(SetConfigThemeFields),
119+
SetBufferFields(SetConfigBufferFields),
120+
}
121+
122+
#[derive(Debug, Clone)]
123+
pub enum SetConfigThemeFields {
124+
TextColor(f32, f32, f32),
125+
BackgroundColor(f32, f32, f32),
126+
ShowIcons(bool),
127+
Font(String),
128+
}
129+
130+
#[derive(Debug, Clone)]
131+
pub enum SetConfigBufferFields {
132+
ClearOnHide(bool),
133+
ClearOnEnter(bool),
134+
}
135+
100136
/// The window settings for rustcast
101137
pub fn default_settings() -> Settings {
102138
Settings {
@@ -173,10 +209,10 @@ impl ToApps for HashMap<String, String> {
173209
impl DebouncePolicy for Page {
174210
fn debounce_delay(&self, config: &Config) -> Option<Duration> {
175211
match self {
176-
Page::Main => None,
177-
Page::FileSearch => Some(Duration::from_millis(config.debounce_delay)),
178-
Page::ClipboardHistory => None,
179-
Page::EmojiSearch => Some(Duration::from_millis(config.debounce_delay)),
212+
Page::Main | Page::ClipboardHistory | Page::Settings => None,
213+
Page::FileSearch | Page::EmojiSearch => {
214+
Some(Duration::from_millis(config.debounce_delay))
215+
}
180216
}
181217
}
182218
}

src/app/apps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl App {
110110
},
111111
App {
112112
ranking: 0,
113-
open_command: AppCommand::Function(Function::OpenPrefPane),
113+
open_command: AppCommand::Message(Message::SwitchToPage(Page::Settings)),
114114
desc: RUSTCAST_DESC_NAME.to_string(),
115115
icons: icons.clone(),
116116
display_name: "Open RustCast Preferences".to_string(),

src/app/menubar.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tray_icon::{
1616
use crate::{
1717
app::{Message, tile::ExtSender},
1818
config::Config,
19-
utils::{open_settings, open_url},
19+
utils::open_url,
2020
};
2121

2222
const DISCORD_LINK: &str = "https://discord.gg/bDfNYPbnC5";
@@ -124,7 +124,9 @@ fn init_event_handler(sender: ExtSender, hotkey_id: u32) {
124124
open_url("https://github.com/unsecretised/rustcast/discussions/new?category=q-a");
125125
}
126126
"open_preferences" => {
127-
open_settings();
127+
runtime.spawn(async move {
128+
sender.clone().try_send(Message::OpenToSettings).unwrap();
129+
});
128130
}
129131
"open_github_page" => {
130132
open_url("https://github.com/unsecretised/rustcast");

0 commit comments

Comments
 (0)