Skip to content

Commit ce64125

Browse files
committed
add a to default button
1 parent 84979e9 commit ce64125

7 files changed

Lines changed: 27 additions & 64 deletions

File tree

src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub enum Message {
104104

105105
#[derive(Debug, Clone)]
106106
pub enum SetConfigFields {
107+
ToDefault,
107108
ToggleHotkey(String),
108109
ClipboardHotkey(String),
109110
PlaceHolder(String),

src/app/pages/settings.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
292292
font_family.into(),
293293
text_clr.into(),
294294
bg_clr.into(),
295-
savebutton(theme.clone()),
295+
Row::from_iter([savebutton(theme.clone()), default_button(theme.clone())])
296+
.spacing(5)
297+
.width(Length::Fill)
298+
.into(),
296299
])
297300
.spacing(10),
298301
))
@@ -317,6 +320,19 @@ fn savebutton(theme: Theme) -> Element<'static, Message> {
317320
.into()
318321
}
319322

323+
fn default_button(theme: Theme) -> Element<'static, Message> {
324+
Button::new(
325+
Text::new("To default")
326+
.align_x(Alignment::Center)
327+
.width(Length::Fill)
328+
.font(theme.font()),
329+
)
330+
.style(move |_, _| settings_save_button_style(&theme))
331+
.width(Length::Fill)
332+
.on_press(Message::SetConfig(SetConfigFields::ToDefault))
333+
.into()
334+
}
335+
320336
fn settings_hint_text(theme: Theme, text: impl ToString) -> Element<'static, Message> {
321337
let text = text.to_string();
322338

src/app/tile.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
pub mod elm;
33
pub mod update;
44

5+
use crate::app::apps::App;
56
use crate::app::{ArrowKey, Message, Move, Page};
67
use crate::clipboard::ClipBoardContentType;
78
use crate::config::Config;
89
use crate::debounce::Debouncer;
9-
use crate::{app::apps::App, platform::default_app_paths};
1010

1111
use arboard::Clipboard;
1212
use global_hotkey::hotkey::HotKey;
@@ -31,8 +31,6 @@ use tray_icon::TrayIcon;
3131

3232
use std::collections::HashMap;
3333
use std::fmt::Debug;
34-
use std::fs;
35-
use std::path::Path;
3634
use std::str::FromStr;
3735
use std::time::Duration;
3836

@@ -181,7 +179,6 @@ impl Tile {
181179
keyboard,
182180
Subscription::run(handle_recipient),
183181
Subscription::run(check_version),
184-
// Subscription::run(handle_hot_reloading),
185182
Subscription::run(handle_clipboard_history),
186183
Subscription::run(handle_file_search),
187184
window::close_events().map(Message::HideWindow),
@@ -281,57 +278,6 @@ impl Tile {
281278
}
282279
}
283280

284-
#[allow(unused)]
285-
/// This is the subscription function that handles hot reloading of the config
286-
fn handle_hot_reloading() -> impl futures::Stream<Item = Message> {
287-
stream::channel(100, async |mut output| {
288-
let config_path =
289-
&(std::env::var("HOME").unwrap_or("".to_owned()) + "/.config/rustcast/config.toml");
290-
let mut last_modified = fs::metadata(config_path).unwrap().modified().unwrap();
291-
292-
let paths = default_app_paths();
293-
let mut total_files: usize = paths
294-
.par_iter()
295-
.map(|dir| count_dirs_in_dir(Path::new(dir)))
296-
.sum();
297-
298-
loop {
299-
let last_modified_check = fs::metadata(config_path).unwrap().modified().unwrap();
300-
301-
let current_total_files: usize = paths
302-
.par_iter()
303-
.map(|dir| count_dirs_in_dir(Path::new(dir)))
304-
.sum();
305-
306-
if last_modified_check != last_modified {
307-
last_modified = last_modified_check;
308-
info!("Config file was modified");
309-
let _ = output.send(Message::ReloadConfig).await;
310-
} else if total_files != current_total_files {
311-
total_files = current_total_files;
312-
info!("App count was changed");
313-
let _ = output.send(Message::ReloadConfig).await;
314-
}
315-
316-
tokio::time::sleep(Duration::from_millis(1000)).await;
317-
}
318-
})
319-
}
320-
321-
/// Helper fn for counting directories (since macos `.app`'s are directories) inside a directory
322-
fn count_dirs_in_dir(dir: impl AsRef<Path>) -> usize {
323-
// Read the directory; if it fails, treat as empty
324-
let entries = match fs::read_dir(dir) {
325-
Ok(e) => e,
326-
Err(_) => return 0,
327-
};
328-
329-
entries
330-
.filter_map(|entry| entry.ok())
331-
.filter(|entry| entry.file_type().map(|t| t.is_dir()).unwrap_or(false))
332-
.count()
333-
}
334-
335281
/// This is the subscription function that handles hotkeys, e.g. for hiding / showing the window
336282
fn handle_hotkeys() -> impl futures::Stream<Item = Message> {
337283
stream::channel(100, async |mut output| {

src/app/tile/elm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
155155
.id("results")
156156
.height(height as u32);
157157

158-
let text = if !tile.query_lc.is_empty() {
158+
let text = if tile.query_lc.is_empty() {
159+
tile.page.to_string()
160+
} else {
159161
match results_count {
160162
1 => "1 result found".to_string(),
161163
0 => "No results found".to_string(),
162164
count => {
163165
format!("{count} results found")
164166
}
165167
}
166-
} else {
167-
tile.page.to_string()
168168
};
169169

170170
let contents = container(

src/app/tile/update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
542542
SetConfigFields::SetBufferFields(SetConfigBufferFields::ClearOnEnter(clear)) => {
543543
final_config.buffer_rules.clear_on_enter = clear
544544
}
545+
SetConfigFields::ToDefault => final_config = Config::default(),
545546
};
546547

547548
tile.config = final_config;

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
};
1515

1616
/// The main config struct (effectively the config file's "schema")
17-
#[derive(Debug, Clone, Deserialize, Serialize)]
17+
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
1818
#[serde(default)]
1919
pub struct Config {
2020
pub toggle_hotkey: String,
@@ -56,7 +56,7 @@ impl Default for Config {
5656
}
5757

5858
/// The settings you can set for the theme
59-
#[derive(Debug, Clone, Deserialize, Serialize)]
59+
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
6060
#[serde(default)]
6161
pub struct Theme {
6262
pub text_color: (f32, f32, f32),
@@ -157,7 +157,7 @@ impl Theme {
157157
/// - clear_on_hide is whether the buffer should be cleared when the window is hidden
158158
/// - clear_on_enter is whether the buffer should be cleared when the user presses enter after
159159
/// searching
160-
#[derive(Debug, Clone, Deserialize, Serialize)]
160+
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
161161
#[serde(default)]
162162
pub struct Buffer {
163163
pub clear_on_hide: bool,
@@ -176,7 +176,7 @@ impl Default for Buffer {
176176
/// Command is the command it will run when the button is clicked
177177
/// Icon_path is the path to an icon, but this is optional
178178
/// Alias is the text that is used to call this command / search for it
179-
#[derive(Debug, Clone, Deserialize, Serialize)]
179+
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
180180
pub struct Shelly {
181181
command: String,
182182
icon_path: Option<String>,

src/platform/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! This handles all of the platform specific stuff.
22
use iced::wgpu::rwh::WindowHandle;
33

4-
pub use self::cross::default_app_paths;
54
use crate::app::apps::App;
65

76
mod cross;

0 commit comments

Comments
 (0)