Skip to content
Merged
31 changes: 23 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ pub const FILE_SEARCH_BATCH_SIZE: u32 = 10;
/// The rustcast descriptor name to be put for all rustcast commands
pub const RUSTCAST_DESC_NAME: &str = "Utility";

/// The different pages that rustcast can have / has
/// The different pages that rustcast can have / has within the launcher
/// Settings is notably missing since this opens as a new window outside the launcher
#[derive(Debug, Clone, PartialEq)]
pub enum Page {
Main,
FileSearch,
ClipboardHistory,
EmojiSearch,
Settings,
}

/// The settings panel tabs
Expand Down Expand Up @@ -94,7 +94,6 @@ impl std::fmt::Display for Page {
Page::FileSearch => "File search",
Page::EmojiSearch => "Emoji search",
Page::ClipboardHistory => "Clipboard history",
Page::Settings => "Settings",
})
}
}
Expand Down Expand Up @@ -127,7 +126,7 @@ pub enum Editable<T> {
#[derive(Debug, Clone)]
pub enum Message {
UriReceived(String),
WriteConfig(bool),
WriteConfig,
SaveRanking,
ToggleAutoStartup(bool),
LoadRanking,
Expand All @@ -136,7 +135,6 @@ pub enum Message {
ResizeWindow(Id, f32),
OpenWindow,
OpenResult(u32),
OpenToSettings,
SearchQueryChanged(String, Id),
KeyPressed(Shortcut),
FocusTextInput(Move),
Expand Down Expand Up @@ -169,6 +167,8 @@ pub enum Message {
DebouncedSearch(Id),
ThemeModeChanged(bool),
SimulatePaste(i32),
OpenSettingsWindow,
SettingsWindowOpened(window::Id),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -228,6 +228,23 @@ pub fn default_settings() -> Settings {
}
}

pub fn settings_window_settings() -> window::Settings {
Settings {
resizable: false,
decorations: true,
minimizable: false,
level: window::Level::AlwaysOnTop,
transparent: false,
blur: false,
size: iced::Size {
width: 900.,
height: 600.,
},
position: window::Position::Centered,
..Default::default()
}
}

/// A Trait to define that a struct can be converted to an app
pub trait ToApp {
/// Convert self into an app
Expand Down Expand Up @@ -287,7 +304,7 @@ impl ToApps for HashMap<String, String> {
impl DebouncePolicy for Page {
fn debounce_delay(&self, config: &Config) -> Option<Duration> {
match self {
Page::Main | Page::ClipboardHistory | Page::Settings => None,
Page::Main | Page::ClipboardHistory => None,
Page::FileSearch | Page::EmojiSearch => {
Some(Duration::from_millis(config.debounce_delay))
}
Expand All @@ -306,7 +323,6 @@ mod tests {
assert_eq!(Page::FileSearch.to_string(), "File search");
assert_eq!(Page::ClipboardHistory.to_string(), "Clipboard history");
assert_eq!(Page::EmojiSearch.to_string(), "Emoji search");
assert_eq!(Page::Settings.to_string(), "Settings");
}

#[test]
Expand All @@ -318,7 +334,6 @@ mod tests {

assert_eq!(Page::Main.debounce_delay(&config), None);
assert_eq!(Page::ClipboardHistory.debounce_delay(&config), None);
assert_eq!(Page::Settings.debounce_delay(&config), None);
assert_eq!(
Page::FileSearch.debounce_delay(&config),
Some(Duration::from_millis(123))
Expand Down
2 changes: 1 addition & 1 deletion src/app/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl App {
},
App {
ranking: 0,
open_command: AppCommand::Message(Message::SwitchToPage(Page::Settings)),
open_command: AppCommand::Message(Message::OpenSettingsWindow),
desc: RUSTCAST_DESC_NAME.to_string(),
icons: icons.clone(),
display_name: "Open RustCast Preferences".to_string(),
Expand Down
5 changes: 4 additions & 1 deletion src/app/menubar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ fn init_event_handler(sender: ExtSender, shortcut: Shortcut) {
}
"open_preferences" => {
runtime.spawn(async move {
sender.clone().try_send(Message::OpenToSettings).unwrap();
sender
.clone()
.try_send(Message::OpenSettingsWindow)
.unwrap();
});
}
"open_github_page" => {
Expand Down
Loading
Loading