Added program icons
This commit is contained in:
1 parent
4494dee4a8
commit
cb512d743b
9 files changed
+540
-92
No files matched your search
+170
-45
@@ -20,6 +20,7 @@ use iced::{
|
||||
#[cfg_attr(test, allow(dead_code))]
|
||||
mod autostart;
|
||||
mod hotkeys;
|
||||
mod icons;
|
||||
mod notifications;
|
||||
mod single_instance;
|
||||
#[allow(dead_code)]
|
||||
@@ -101,6 +102,9 @@ fn main() -> iced::Result {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
icons::install_linux_icon();
|
||||
|
||||
let result = iced::daemon(boot, update, view)
|
||||
.title(window_title)
|
||||
.theme(|state: &Moorly, _window| state.theme.iced())
|
||||
@@ -123,6 +127,7 @@ fn window_settings(size: Size, position: Option<Point>) -> window::Settings {
|
||||
position: position.map_or(window::Position::Default, window::Position::Specific),
|
||||
min_size: Some(Size::new(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)),
|
||||
exit_on_close_request: false,
|
||||
icon: icons::window_icon(),
|
||||
..window::Settings::default()
|
||||
}
|
||||
}
|
||||
@@ -155,7 +160,7 @@ fn boot() -> (Moorly, Task<Message>) {
|
||||
hotkeys::start(global_hotkey_bindings(&state));
|
||||
|
||||
#[cfg(not(test))]
|
||||
match tray::start() {
|
||||
match tray::start(state.tray_icon_style) {
|
||||
Ok(()) => {
|
||||
state.tray_available = true;
|
||||
tray::set_window_visible(true);
|
||||
@@ -1648,9 +1653,8 @@ impl Command {
|
||||
}
|
||||
|
||||
// Best matches first; ties keep the original command order.
|
||||
commands.sort_by_key(|command| {
|
||||
std::cmp::Reverse(fuzzy_score(&command.label(state), query))
|
||||
});
|
||||
commands
|
||||
.sort_by_key(|command| std::cmp::Reverse(fuzzy_score(&command.label(state), query)));
|
||||
|
||||
commands
|
||||
}
|
||||
@@ -1861,8 +1865,7 @@ fn copy_terminal_selection(state: &mut Moorly, id: u32) -> Task<Message> {
|
||||
|
||||
/// Reads the clipboard and hands it back for a single paste into the terminal.
|
||||
fn paste_terminal_clipboard(id: u32) -> Task<Message> {
|
||||
iced::clipboard::read()
|
||||
.map(move |contents| Message::TerminalPasteContents(id, contents))
|
||||
iced::clipboard::read().map(move |contents| Message::TerminalPasteContents(id, contents))
|
||||
}
|
||||
|
||||
/// Clipboard bytes for a paste, ignoring a missing or empty clipboard. Line
|
||||
@@ -1936,6 +1939,8 @@ struct Moorly {
|
||||
close_to_tray_draft: bool,
|
||||
minimize_to_tray: bool,
|
||||
minimize_to_tray_draft: bool,
|
||||
tray_icon_style: icons::TrayIconStyle,
|
||||
tray_icon_style_draft: icons::TrayIconStyle,
|
||||
right_click_behavior: RightClickBehavior,
|
||||
right_click_behavior_draft: RightClickBehavior,
|
||||
right_click_menu_open: bool,
|
||||
@@ -2768,6 +2773,9 @@ struct GeneralConfig {
|
||||
/// Minimizing the main window hides it to the tray instead.
|
||||
#[serde(default)]
|
||||
minimize_to_tray: bool,
|
||||
/// Icon variant shown in the system tray.
|
||||
#[serde(default)]
|
||||
tray_icon_style: icons::TrayIconStyle,
|
||||
#[serde(default)]
|
||||
right_click_behavior: RightClickBehavior,
|
||||
}
|
||||
@@ -2778,6 +2786,7 @@ impl Default for GeneralConfig {
|
||||
fade_settings: true,
|
||||
close_to_tray: false,
|
||||
minimize_to_tray: false,
|
||||
tray_icon_style: icons::TrayIconStyle::default(),
|
||||
right_click_behavior: RightClickBehavior::default(),
|
||||
}
|
||||
}
|
||||
@@ -4872,6 +4881,29 @@ fn new_tab_close_animation() -> Animation<bool> {
|
||||
Animation::new(false).duration(Duration::from_millis(750))
|
||||
}
|
||||
|
||||
/// Applies a tray icon variant to the running tray. On failure the previous
|
||||
/// icon stays in place and the error is reported to the user.
|
||||
fn set_tray_icon_style(state: &mut Moorly, style: icons::TrayIconStyle) -> bool {
|
||||
#[cfg(test)]
|
||||
{
|
||||
let _ = (state, style);
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
{
|
||||
if let Err(error) = tray::set_icon(style) {
|
||||
state.notifications.add(
|
||||
notifications::Notification::new(notifications::NotificationKind::Error, error)
|
||||
.title("System tray icon"),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Commits the draft settings to the running state.
|
||||
fn apply_settings(state: &mut Moorly) {
|
||||
state.show_start_tab = state.show_start_tab_draft;
|
||||
@@ -4879,6 +4911,7 @@ fn apply_settings(state: &mut Moorly) {
|
||||
state.fade_settings = state.fade_settings_draft;
|
||||
state.close_to_tray = state.close_to_tray_draft;
|
||||
state.minimize_to_tray = state.minimize_to_tray_draft;
|
||||
state.tray_icon_style = state.tray_icon_style_draft;
|
||||
state.right_click_behavior = state.right_click_behavior_draft;
|
||||
state.hide_tab_close = state.hide_tab_close_draft;
|
||||
state.show_new_session_button = state.show_new_session_button_draft;
|
||||
@@ -4922,6 +4955,7 @@ fn undo_settings(state: &mut Moorly) {
|
||||
state.fade_settings_draft = state.fade_settings;
|
||||
state.close_to_tray_draft = state.close_to_tray;
|
||||
state.minimize_to_tray_draft = state.minimize_to_tray;
|
||||
state.tray_icon_style_draft = state.tray_icon_style;
|
||||
state.right_click_behavior_draft = state.right_click_behavior;
|
||||
state.hide_tab_close_draft = state.hide_tab_close;
|
||||
state.show_new_session_button_draft = state.show_new_session_button;
|
||||
@@ -4975,6 +5009,7 @@ fn config_file(state: &Moorly) -> ConfigFile {
|
||||
fade_settings: state.fade_settings,
|
||||
close_to_tray: state.close_to_tray,
|
||||
minimize_to_tray: state.minimize_to_tray,
|
||||
tray_icon_style: state.tray_icon_style,
|
||||
right_click_behavior: state.right_click_behavior,
|
||||
},
|
||||
startup: StartupConfig {
|
||||
@@ -5078,6 +5113,7 @@ impl Default for Moorly {
|
||||
let fade_settings = config.general.fade_settings;
|
||||
let close_to_tray = config.general.close_to_tray;
|
||||
let minimize_to_tray = config.general.minimize_to_tray;
|
||||
let tray_icon_style = config.general.tray_icon_style;
|
||||
let hide_tab_close = config.appearance.hide_tab_close;
|
||||
let show_new_session_button = config.appearance.show_new_session_button;
|
||||
let show_command_palette_description = config.appearance.show_command_palette_description;
|
||||
@@ -5116,6 +5152,8 @@ impl Default for Moorly {
|
||||
close_to_tray_draft: close_to_tray,
|
||||
minimize_to_tray,
|
||||
minimize_to_tray_draft: minimize_to_tray,
|
||||
tray_icon_style,
|
||||
tray_icon_style_draft: tray_icon_style,
|
||||
right_click_behavior: config.general.right_click_behavior,
|
||||
right_click_behavior_draft: config.general.right_click_behavior,
|
||||
right_click_menu_open: false,
|
||||
@@ -5273,6 +5311,7 @@ enum Message {
|
||||
SetFadeSettings(bool),
|
||||
SetCloseToTray(bool),
|
||||
SetMinimizeToTray(bool),
|
||||
SetTrayIconStyle(icons::TrayIconStyle),
|
||||
SetRightClickBehavior(RightClickBehavior),
|
||||
ToggleRightClickBehaviorMenu,
|
||||
EnableAutostartAtLogin,
|
||||
@@ -6161,6 +6200,11 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
Message::SetFadeSettings(value) => state.fade_settings_draft = value,
|
||||
Message::SetCloseToTray(value) => state.close_to_tray_draft = value,
|
||||
Message::SetMinimizeToTray(value) => state.minimize_to_tray_draft = value,
|
||||
Message::SetTrayIconStyle(style) => {
|
||||
if set_tray_icon_style(state, style) {
|
||||
state.tray_icon_style_draft = style;
|
||||
}
|
||||
}
|
||||
Message::SetRightClickBehavior(behavior) => {
|
||||
state.right_click_behavior_draft = behavior;
|
||||
state.right_click_menu_open = false;
|
||||
@@ -6172,11 +6216,8 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
Ok(()) => state.autostart_at_login = true,
|
||||
Err(error) => {
|
||||
state.notifications.add(
|
||||
notifications::Notification::new(
|
||||
notifications::NotificationKind::Error,
|
||||
error,
|
||||
)
|
||||
.title("Autostart at login"),
|
||||
notifications::Notification::new(notifications::NotificationKind::Error, error)
|
||||
.title("Autostart at login"),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -6184,11 +6225,8 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
Ok(()) => state.autostart_at_login = false,
|
||||
Err(error) => {
|
||||
state.notifications.add(
|
||||
notifications::Notification::new(
|
||||
notifications::NotificationKind::Error,
|
||||
error,
|
||||
)
|
||||
.title("Autostart at login"),
|
||||
notifications::Notification::new(notifications::NotificationKind::Error, error)
|
||||
.title("Autostart at login"),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -6275,7 +6313,15 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
save_config(state);
|
||||
sync_global_hotkeys(state);
|
||||
}
|
||||
Message::UndoChanges => undo_settings(state),
|
||||
Message::UndoChanges => {
|
||||
let tray_icon_changed = state.tray_icon_style_draft != state.tray_icon_style;
|
||||
undo_settings(state);
|
||||
|
||||
if tray_icon_changed {
|
||||
let style = state.tray_icon_style;
|
||||
set_tray_icon_style(state, style);
|
||||
}
|
||||
}
|
||||
Message::Notification(action) => match action {
|
||||
notifications::Message::Dismiss(id) => state.notifications.dismiss(id),
|
||||
},
|
||||
@@ -10423,6 +10469,39 @@ fn general_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
);
|
||||
}
|
||||
|
||||
let mut tray_style_picker = row![].spacing(6);
|
||||
for style in icons::TrayIconStyle::ALL {
|
||||
let item = button(text(style.label()))
|
||||
.on_press(Message::SetTrayIconStyle(style))
|
||||
.padding([6, 10]);
|
||||
|
||||
tray_style_picker = tray_style_picker.push(if style == state.tray_icon_style_draft {
|
||||
item.style(theme::selected_option)
|
||||
} else {
|
||||
item.style(theme::outlined_option)
|
||||
});
|
||||
}
|
||||
|
||||
panel = panel.push(
|
||||
column![
|
||||
styled_text(&state.typography.h2, "System Tray"),
|
||||
row![
|
||||
column![
|
||||
styled_text(&state.typography.h3, "Tray icon style"),
|
||||
styled_text(
|
||||
&state.typography.caption,
|
||||
"Choose the icon shown in the system tray.",
|
||||
),
|
||||
]
|
||||
.spacing(4),
|
||||
space::horizontal(),
|
||||
tray_style_picker,
|
||||
]
|
||||
.align_y(Alignment::Center),
|
||||
]
|
||||
.spacing(8),
|
||||
);
|
||||
|
||||
panel = panel.push(
|
||||
column![
|
||||
styled_text(&state.typography.h2, "Right-click behavior"),
|
||||
@@ -10586,9 +10665,11 @@ fn autostart_choices(state: &Moorly) -> Vec<AutostartChoice> {
|
||||
for (profile_index, profile) in folder.profiles.iter().enumerate() {
|
||||
// Hide everything already in the draft list, including profiles
|
||||
// added since the last save.
|
||||
if state.autostart_profiles_draft.iter().any(|entry| {
|
||||
autostart_target(state, entry) == Some((folder_index, profile_index))
|
||||
}) {
|
||||
if state
|
||||
.autostart_profiles_draft
|
||||
.iter()
|
||||
.any(|entry| autostart_target(state, entry) == Some((folder_index, profile_index)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -10827,7 +10908,12 @@ fn startup_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
|
||||
let choices = autostart_choices(state);
|
||||
let add = button("Add")
|
||||
.on_press_maybe(state.autostart_choice.is_some().then_some(Message::AddAutostartProfile))
|
||||
.on_press_maybe(
|
||||
state
|
||||
.autostart_choice
|
||||
.is_some()
|
||||
.then_some(Message::AddAutostartProfile),
|
||||
)
|
||||
.padding([6, 16])
|
||||
.style(theme::positive_option);
|
||||
|
||||
@@ -11041,6 +11127,7 @@ fn settings_dirty(state: &Moorly) -> bool {
|
||||
|| state.command_palette_enabled_draft != state.command_palette_enabled
|
||||
|| state.close_to_tray_draft != state.close_to_tray
|
||||
|| state.minimize_to_tray_draft != state.minimize_to_tray
|
||||
|| state.tray_icon_style_draft != state.tray_icon_style
|
||||
|| state.right_click_behavior_draft != state.right_click_behavior
|
||||
|| state.theme_choice != state.saved_theme_choice
|
||||
|| state.shortcuts != state.saved_shortcuts
|
||||
@@ -12655,6 +12742,8 @@ mod tests {
|
||||
close_to_tray_draft: false,
|
||||
minimize_to_tray: false,
|
||||
minimize_to_tray_draft: false,
|
||||
tray_icon_style: super::icons::TrayIconStyle::default(),
|
||||
tray_icon_style_draft: super::icons::TrayIconStyle::default(),
|
||||
right_click_behavior: super::RightClickBehavior::default(),
|
||||
right_click_behavior_draft: super::RightClickBehavior::default(),
|
||||
right_click_menu_open: false,
|
||||
@@ -12834,10 +12923,7 @@ mod tests {
|
||||
// The quick rows plus both profiles.
|
||||
let quick_rows = 1 + usize::from(cfg!(windows));
|
||||
assert_eq!(choices.len(), quick_rows + 2);
|
||||
assert_eq!(
|
||||
choices[0].profile.kind,
|
||||
super::AutostartKind::QuickTerminal
|
||||
);
|
||||
assert_eq!(choices[0].profile.kind, super::AutostartKind::QuickTerminal);
|
||||
|
||||
let beta = choices
|
||||
.iter()
|
||||
@@ -12858,11 +12944,7 @@ mod tests {
|
||||
// Added profiles leave the drop-down until the draft is undone.
|
||||
let remaining = super::autostart_choices(&state);
|
||||
assert_eq!(remaining.len(), quick_rows + 1);
|
||||
assert!(
|
||||
!remaining
|
||||
.iter()
|
||||
.any(|choice| choice.profile.name == "Beta")
|
||||
);
|
||||
assert!(!remaining.iter().any(|choice| choice.profile.name == "Beta"));
|
||||
|
||||
let _ = update(&mut state, Message::AutostartChoiceSelected(alpha.clone()));
|
||||
let _ = update(&mut state, Message::AddAutostartProfile);
|
||||
@@ -12910,10 +12992,7 @@ mod tests {
|
||||
let quick = super::autostart_choices(&state)[0].clone();
|
||||
|
||||
for _ in 0..3 {
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::AutostartChoiceSelected(quick.clone()),
|
||||
);
|
||||
let _ = update(&mut state, Message::AutostartChoiceSelected(quick.clone()));
|
||||
let _ = update(&mut state, Message::AddAutostartProfile);
|
||||
}
|
||||
|
||||
@@ -13022,8 +13101,14 @@ mod tests {
|
||||
);
|
||||
|
||||
// Plain Ctrl+C stays an interrupt and Ctrl+V stays normal input.
|
||||
assert_eq!(terminal_clipboard_action(&key("c"), ctrl, copy, paste), None);
|
||||
assert_eq!(terminal_clipboard_action(&key("v"), ctrl, copy, paste), None);
|
||||
assert_eq!(
|
||||
terminal_clipboard_action(&key("c"), ctrl, copy, paste),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
terminal_clipboard_action(&key("v"), ctrl, copy, paste),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
terminal_clipboard_action(&key("x"), ctrl | shift, copy, paste),
|
||||
None
|
||||
@@ -13172,6 +13257,53 @@ mod tests {
|
||||
assert!(!super::settings_dirty(&state));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tray_icon_style_changes_wait_for_save_or_undo() {
|
||||
let mut state = state();
|
||||
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::SetTrayIconStyle(super::icons::TrayIconStyle::Monochrome),
|
||||
);
|
||||
assert_eq!(state.tray_icon_style, super::icons::TrayIconStyle::Color);
|
||||
assert_eq!(
|
||||
state.tray_icon_style_draft,
|
||||
super::icons::TrayIconStyle::Monochrome
|
||||
);
|
||||
assert!(super::settings_dirty(&state));
|
||||
|
||||
let _ = update(&mut state, Message::UndoChanges);
|
||||
assert_eq!(
|
||||
state.tray_icon_style_draft,
|
||||
super::icons::TrayIconStyle::Color
|
||||
);
|
||||
assert!(!super::settings_dirty(&state));
|
||||
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::SetTrayIconStyle(super::icons::TrayIconStyle::Monochrome),
|
||||
);
|
||||
super::apply_settings(&mut state);
|
||||
assert_eq!(
|
||||
state.tray_icon_style,
|
||||
super::icons::TrayIconStyle::Monochrome
|
||||
);
|
||||
assert_eq!(state.tray_icon_style_draft, state.tray_icon_style);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_tray_icon_style_defaults_to_color() {
|
||||
let config: super::ConfigFile = toml::from_str("[general]\nfade_settings = true").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
config.general.tray_icon_style,
|
||||
super::icons::TrayIconStyle::Color
|
||||
);
|
||||
|
||||
let text = toml::to_string_pretty(&config).unwrap();
|
||||
assert!(text.contains("tray_icon_style = \"color\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minimizing_hides_to_tray_only_when_enabled() {
|
||||
let window = test_window();
|
||||
@@ -14409,11 +14541,7 @@ mod tests {
|
||||
let _ = update(&mut state, Message::ApplyShortcut);
|
||||
|
||||
assert_eq!(
|
||||
state
|
||||
.shortcuts
|
||||
.close_tab
|
||||
.as_ref()
|
||||
.map(ToString::to_string),
|
||||
state.shortcuts.close_tab.as_ref().map(ToString::to_string),
|
||||
Some("Ctrl+Shift+K".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -14655,10 +14783,7 @@ mod tests {
|
||||
assert!(super::settings_dirty(&state));
|
||||
|
||||
let _ = update(&mut state, Message::UndoChanges);
|
||||
assert_eq!(
|
||||
state.right_click_behavior_draft,
|
||||
state.right_click_behavior
|
||||
);
|
||||
assert_eq!(state.right_click_behavior_draft, state.right_click_behavior);
|
||||
|
||||
let _ = update(
|
||||
&mut state,
|
||||
|
||||
Reference in new issue
Block a user