Added autostart option for the program
Moorly CI / windows-build (push) Successful in 3m2s
Moorly CI / linux-build (push) Successful in 4m14s

This commit is contained in:
Squid committed 2026-11-12 19:28:52 +01:00
1 parent 8e17b4a707
commit af4f4c889f
2 files changed
+186

No files matched your search

+66
View File
@@ -18,6 +18,7 @@ use iced::{
};
#[cfg_attr(test, allow(dead_code))]
mod autostart;
mod hotkeys;
mod notifications;
#[allow(dead_code)]
@@ -1779,6 +1780,9 @@ struct Moorly {
close_to_tray_draft: bool,
minimize_to_tray: bool,
minimize_to_tray_draft: bool,
/// Mirrors the OS autostart entry so the settings button knows which
/// action to offer.
autostart_at_login: bool,
drag: Option<TabDrag>,
theme: theme::Preference,
saved_theme: theme::Preference,
@@ -4841,6 +4845,7 @@ impl Default for Moorly {
close_to_tray_draft: close_to_tray,
minimize_to_tray,
minimize_to_tray_draft: minimize_to_tray,
autostart_at_login: autostart::enabled(),
drag: None,
theme,
saved_theme: theme,
@@ -4986,6 +4991,8 @@ enum Message {
SetFadeSettings(bool),
SetCloseToTray(bool),
SetMinimizeToTray(bool),
EnableAutostartAtLogin,
DisableAutostartAtLogin,
SetHideTabClose(bool),
SetShowNewSessionButton(bool),
SetShowCommandPaletteDescription(bool),
@@ -5731,6 +5738,10 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
window_state.quick_menu_open = false;
state.folder_menu = None;
if tab == Tab::Settings && state.settings_section == SettingsSection::General {
state.autostart_at_login = autostart::enabled();
}
// New tabs land at the end, so bring that end into view.
if is_new {
return scroll_tabs_to_end(state, window);
@@ -5751,6 +5762,10 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
Message::SelectSettingsSection(section) => {
state.folder_menu = None;
if section == SettingsSection::General {
state.autostart_at_login = autostart::enabled();
}
if section == state.settings_section && state.pending_settings_section.is_none() {
// Already showing this section.
} else if !state.fade_settings {
@@ -5814,6 +5829,30 @@ 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::EnableAutostartAtLogin => match autostart::enable() {
Ok(()) => state.autostart_at_login = true,
Err(error) => {
state.notifications.add(
notifications::Notification::new(
notifications::NotificationKind::Error,
error,
)
.title("Autostart at login"),
);
}
},
Message::DisableAutostartAtLogin => match autostart::disable() {
Ok(()) => state.autostart_at_login = false,
Err(error) => {
state.notifications.add(
notifications::Notification::new(
notifications::NotificationKind::Error,
error,
)
.title("Autostart at login"),
);
}
},
Message::SetHideTabClose(value) => state.hide_tab_close_draft = value,
Message::SetShowNewSessionButton(value) => state.show_new_session_button_draft = value,
Message::SetShowCommandPaletteDescription(value) => {
@@ -9965,6 +10004,32 @@ fn general_panel(state: &Moorly) -> Element<'_, Message> {
);
}
let login_action: Element<'_, Message> = if state.autostart_at_login {
button("Remove autostart")
.on_press(Message::DisableAutostartAtLogin)
.padding([6, 12])
.style(theme::danger_option)
.into()
} else {
button("Enable autostart")
.on_press(Message::EnableAutostartAtLogin)
.padding([6, 12])
.style(theme::positive_option)
.into()
};
panel = panel.push(
column![
styled_text(&state.typography.h2, "Autostart at login"),
styled_text(
&state.typography.caption,
"Start Moorly automatically when you sign in.",
),
row![login_action, space::horizontal()],
]
.spacing(8),
);
panel.into()
}
@@ -12028,6 +12093,7 @@ mod tests {
close_to_tray_draft: false,
minimize_to_tray: false,
minimize_to_tray_draft: false,
autostart_at_login: false,
drag: None,
theme: theme::Preference::default(),
saved_theme: theme::Preference::default(),