From 600d0be8ac33322edd74384256f5f6f5776e7b34 Mon Sep 17 00:00:00 2001 From: Francesco Pio Gaglione Date: Sun, 12 Jan 2025 17:15:24 +0100 Subject: [PATCH] pr fixes --- .gitignore | 3 +- Cargo.lock | 109 ++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 2 +- i18n/en/chronos.ftl | 2 + i18n/it/chronos.ftl | 3 ++ src/app.rs | 86 ++++++++++++++++----------------- src/pages/pomodoro.rs | 41 ++++++++-------- src/pages/settings.rs | 64 +++++++++++-------------- 8 files changed, 198 insertions(+), 112 deletions(-) diff --git a/.gitignore b/.gitignore index a025932..f9c1b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ debian/* .flatpak .flatpak-builder build-dir -repo \ No newline at end of file +repo +.idea \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 658c37a..4f09125 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -913,7 +913,7 @@ version = "0.2.2" source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-0.13#a83bf83784276aaa882ef13555295a2ad9edd265" dependencies = [ "dnd", - "mime", + "mime 0.1.0", "smithay-clipboard", ] @@ -1108,7 +1108,7 @@ dependencies = [ "atomicwrites", "cosmic-config-derive", "cosmic-settings-daemon", - "dirs", + "dirs 5.0.1", "futures-util", "iced_futures", "known-folders", @@ -1136,7 +1136,7 @@ name = "cosmic-freedesktop-icons" version = "0.2.6" source = "git+https://github.com/pop-os/freedesktop-icons#5a3b4163148a9600a54cc846aa863f4e6389635d" dependencies = [ - "dirs", + "dirs 5.0.1", "once_cell", "rust-ini", "thiserror", @@ -1196,7 +1196,7 @@ dependencies = [ "almost", "cosmic-config", "csscolorparser", - "dirs", + "dirs 5.0.1", "lazy_static", "palette", "ron", @@ -1409,13 +1409,22 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dirs" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" +dependencies = [ + "dirs-sys 0.3.7", +] + [[package]] name = "dirs" version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", ] [[package]] @@ -1428,6 +1437,17 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -1492,7 +1512,7 @@ version = "0.1.0" source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-0.13#a83bf83784276aaa882ef13555295a2ad9edd265" dependencies = [ "bitflags 2.6.0", - "mime", + "mime 0.1.0", "raw-window-handle", "smithay-client-toolkit", "smithay-clipboard", @@ -1928,6 +1948,19 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "freedesktop-desktop-entry" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c201444ddafb5506fe85265b48421664ff4617e3b7090ef99e42a0070c1aead0" +dependencies = [ + "dirs 3.0.2", + "gettext-rs", + "memchr", + "thiserror", + "xdg", +] + [[package]] name = "fsevent-sys" version = "4.1.0" @@ -2086,6 +2119,26 @@ dependencies = [ "wasi", ] +[[package]] +name = "gettext-rs" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44e92f7dc08430aca7ed55de161253a22276dfd69c5526e5c5e95d1f7cf338a" +dependencies = [ + "gettext-sys", + "locale_config", +] + +[[package]] +name = "gettext-sys" +version = "0.22.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb45773f5b8945f12aecd04558f545964f943dacda1b1155b3d738f5469ef661" +dependencies = [ + "cc", + "temp-dir", +] + [[package]] name = "gif" version = "0.13.1" @@ -2390,7 +2443,7 @@ dependencies = [ "iced_widget", "iced_winit", "image", - "mime", + "mime 0.1.0", "thiserror", "window_clipboard", ] @@ -2414,7 +2467,7 @@ dependencies = [ "dnd", "glam", "log", - "mime", + "mime 0.1.0", "num-traits", "once_cell", "palette", @@ -2906,6 +2959,7 @@ dependencies = [ "cosmic-theme", "css-color", "derive_setters", + "freedesktop-desktop-entry", "iced", "iced_core", "iced_futures", @@ -2916,9 +2970,14 @@ dependencies = [ "iced_widget", "iced_winit", "lazy_static", + "libc", + "license", + "mime 0.3.17", "palette", "rfd", + "rustix 0.38.37", "serde", + "shlex", "slotmap", "smol 2.0.2", "taffy", @@ -2968,6 +3027,17 @@ dependencies = [ "redox_syscall 0.5.6", ] +[[package]] +name = "license" +version = "3.6.0+3.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b517725daf998729e5ef4c4881cdde19cd5bbdde09741ba1b0f1ba0ce018961" +dependencies = [ + "reword", + "serde", + "serde_json", +] + [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -3166,6 +3236,12 @@ dependencies = [ "smithay-clipboard", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -4245,6 +4321,15 @@ dependencies = [ "usvg", ] +[[package]] +name = "reword" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe272098dce9ed76b479995953f748d1851261390b08f8a0ff619c885a1f0765" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "rfd" version = "0.14.1" @@ -4849,6 +4934,12 @@ dependencies = [ "windows-version", ] +[[package]] +name = "temp-dir" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc1ee6eef34f12f765cb94725905c6312b6610ab2b0940889cfe58dae7bc3c72" + [[package]] name = "tempfile" version = "3.13.0" @@ -5705,7 +5796,7 @@ dependencies = [ "clipboard_wayland", "clipboard_x11", "dnd", - "mime", + "mime 0.1.0", "raw-window-handle", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 068ec2b..9c2c71a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ features = ["fluent-system", "desktop-requester"] [dependencies.libcosmic] git = "https://github.com/pop-os/libcosmic.git" default-features = false -features = ["dbus-config", "tokio", "winit", "wgpu", "smol"] +features = ["dbus-config", "tokio", "winit", "wgpu", "smol", "about"] # Uncomment to test a locally-cloned libcosmic # [patch.'https://github.com/pop-os/libcosmic'] diff --git a/i18n/en/chronos.ftl b/i18n/en/chronos.ftl index 705ad8a..74c0aa7 100644 --- a/i18n/en/chronos.ftl +++ b/i18n/en/chronos.ftl @@ -1,6 +1,8 @@ app-title = Chronos about = About view = View +support = Support +repository = Repository pomodoro = Pomodoro diff --git a/i18n/it/chronos.ftl b/i18n/it/chronos.ftl index ed58c08..4ceda5a 100644 --- a/i18n/it/chronos.ftl +++ b/i18n/it/chronos.ftl @@ -1,6 +1,9 @@ app-title = Chronos about = Informazioni view = Visualizza +support = Supporto +repository = Repository + pomodoro = Pomodoro diff --git a/src/app.rs b/src/app.rs index 63ee21d..e957766 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3,10 +3,12 @@ use crate::config::Config; use crate::core::nav::NavPage; use crate::{fl, pages}; -use cosmic::app::{Command, Core}; +use cosmic::app::context_drawer; +use cosmic::app::{Core, Task}; use cosmic::cosmic_config::{self, CosmicConfigEntry}; use cosmic::iced::time; use cosmic::iced::{Alignment, Length, Subscription}; +use cosmic::widget::about::About; use cosmic::widget::{self, menu, nav_bar}; use cosmic::{cosmic_theme, theme, Application, ApplicationExt, Element}; use std::collections::HashMap; @@ -29,6 +31,7 @@ pub struct AppModel { key_binds: HashMap, // Configuration data that persists between application runs. config: Config, + about: About, pub pomodoro: pages::pomodoro::Pomodoro, pub settings: pages::settings::Settings, @@ -41,7 +44,8 @@ pub struct AppModel { pub enum Message { OpenRepositoryUrl, SubscriptionChannel, - ToggleContextPage(ContextPage), + ToggleContextPage, + Open(String), UpdateConfig(Config), // pages @@ -85,7 +89,7 @@ impl Application for AppModel { } /// Initializes the application with any given flags and startup commands. - fn init(core: Core, _flags: Self::Flags) -> (Self, Command) { + fn init(core: Core, _flags: Self::Flags) -> (Self, Task) { // Create a nav bar with three page items. let mut nav = nav_bar::Model::default(); @@ -102,6 +106,21 @@ impl Application for AppModel { } } + let about = About::default() + .name(fl!("app-title")) + .icon(Self::APP_ID) + .version("0.1.4") + .author("Francesco Pio Gaglione") + .license("GPL-3.0-only") + .links([ + ( + fl!("support"), + "https://github.com/cosmic-utils/chronos/issues", + ), + (fl!("repository"), "https://github.com/cosmic-utils/chronos"), + ]) + .developers([("Francesco Pio Gaglione", "francesco.gaglione.p@gmail.com")]); + // Construct the app model with the runtime's core. let mut app = AppModel { core, @@ -121,6 +140,7 @@ impl Application for AppModel { } }) .unwrap_or_default(), + about, pomodoro: pages::pomodoro::Pomodoro::default(), settings: pages::settings::Settings::default(), pomodoro_tick_state: PomodoroTickState::Idle, @@ -138,7 +158,7 @@ impl Application for AppModel { menu::root(fl!("view")), menu::items( &self.key_binds, - vec![menu::Item::Button(fl!("about"), MenuAction::About)], + vec![menu::Item::Button(fl!("about"), None, MenuAction::About)], ), )]); @@ -151,13 +171,15 @@ impl Application for AppModel { } /// Display a context drawer if the context page is requested. - fn context_drawer(&self) -> Option> { + fn context_drawer(&self) -> Option> { if !self.core.window.show_context { return None; } Some(match self.context_page { - ContextPage::About => self.about(), + ContextPage::About => { + context_drawer::about(&self.about, Message::Open, Message::ToggleContextPage) + } }) } @@ -174,7 +196,7 @@ impl Application for AppModel { .padding(spacing.space_xs) .width(Length::Fill) .height(Length::Fill) - .align_items(Alignment::Center) + .align_x(Alignment::Center) .into() } @@ -197,7 +219,7 @@ impl Application for AppModel { /// /// Commands may be returned for asynchronous execution of code in the background /// on the application's async runtime. - fn update(&mut self, message: Self::Message) -> Command { + fn update(&mut self, message: Self::Message) -> Task { let mut commands = vec![]; match message { Message::OpenRepositoryUrl => { @@ -208,18 +230,8 @@ impl Application for AppModel { // For example purposes only. } - Message::ToggleContextPage(context_page) => { - if self.context_page == context_page { - // Close the context drawer if the toggled context page is the same. - self.core.window.show_context = !self.core.window.show_context; - } else { - // Open the context drawer to display the requested context page. - self.context_page = context_page; - self.core.window.show_context = true; - } - - // Set the title of the context drawer. - self.set_context_title(context_page.title()); + Message::ToggleContextPage => { + self.core.window.show_context = !self.core.window.show_context; } Message::UpdateConfig(config) => { @@ -250,12 +262,17 @@ impl Application for AppModel { Message::PausePomodoroTimer => { self.pomodoro_tick_state = PomodoroTickState::Idle; } + Message::Open(url) => { + if let Err(err) = open::that_detached(url) { + log::error!("{err}") + } + } } - Command::batch(commands) + Task::batch(commands) } /// Called when a nav item is selected. - fn on_nav_select(&mut self, id: nav_bar::Id) -> Command { + fn on_nav_select(&mut self, id: nav_bar::Id) -> Task { // Activate the page in the model. self.nav.activate(id); @@ -264,29 +281,8 @@ impl Application for AppModel { } impl AppModel { - /// The about page for this app. - pub fn about(&self) -> Element { - let cosmic_theme::Spacing { space_xxs, .. } = theme::active().cosmic().spacing; - - let icon = widget::svg(widget::svg::Handle::from_memory(APP_ICON)); - - let title = widget::text::title3(fl!("app-title")); - - let link = widget::button::link(REPOSITORY) - .on_press(Message::OpenRepositoryUrl) - .padding(0); - - widget::column() - .push(icon) - .push(title) - .push(link) - .align_items(Alignment::Center) - .spacing(space_xxs) - .into() - } - /// Updates the header and window titles. - pub fn update_title(&mut self) -> Command { + pub fn update_title(&mut self) -> Task { let mut window_title = fl!("app-title"); if let Some(page) = self.nav.text(self.nav.active()) { @@ -323,7 +319,7 @@ impl menu::action::MenuAction for MenuAction { fn message(&self) -> Self::Message { match self { - MenuAction::About => Message::ToggleContextPage(ContextPage::About), + MenuAction::About => Message::ToggleContextPage, } } } diff --git a/src/pages/pomodoro.rs b/src/pages/pomodoro.rs index d7add81..0906913 100644 --- a/src/pages/pomodoro.rs +++ b/src/pages/pomodoro.rs @@ -1,7 +1,8 @@ +use cosmic::iced::Alignment; use cosmic::{ iced::{self, Length, Padding}, widget::{self, icon}, - Command, Element, + Element, Task, }; use notify_rust::Notification; @@ -64,20 +65,20 @@ impl Pomodoro { fl!("pause") }) .width(Length::Fill) - .horizontal_alignment(iced::alignment::Horizontal::Center), + .align_x(iced::alignment::Horizontal::Center), ) .push( widget::text::title1(self.format_slider_value()) .width(Length::Fill) - .horizontal_alignment(iced::alignment::Horizontal::Center), + .align_x(iced::alignment::Horizontal::Center), ) - .push(widget::vertical_space(Length::from(10))) + .push(widget::Space::with_height(10)) .push( widget::progress_bar(0.0..=self.slider_max_value, self.slider_value) .width(Length::Fixed(250.0)) .height(Length::Fixed(4.0)), ) - .push(widget::vertical_space(Length::from(10))) + .push(widget::Space::with_height(10)) .push( widget::row() .push( @@ -96,12 +97,12 @@ impl Pomodoro { }), ) .push(self.history_view()) - .align_items(iced::Alignment::Center); + .align_x(Alignment::Center); widget::container(col) - .width(iced::Length::Fill) - .height(iced::Length::Fill) - .center_y() + .width(Length::Fill) + .height(Length::Fill) + .align_x(Alignment::Center) .into() } @@ -124,7 +125,7 @@ impl Pomodoro { self.format_seconds(seconds.clone()), )) .width(Length::Fill) - .align_items(iced::Alignment::End), + .align_x(Alignment::End), ), ); } @@ -142,21 +143,21 @@ impl Pomodoro { self.format_seconds(seconds.clone()), )) .width(Length::Fill) - .align_items(iced::Alignment::End), + .align_x(Alignment::End), ), ); } } - inner_col = inner_col.push(widget::vertical_space(Length::from(5))); + inner_col = inner_col.push(widget::Space::with_height(5)); inner_col = inner_col.push(widget::divider::horizontal::default()); - inner_col = inner_col.push(widget::vertical_space(Length::from(5))); + inner_col = inner_col.push(widget::Space::with_height(5)); } } else { inner_col = inner_col.push(widget::text::text(fl!("no-elements"))); } widget::column() - .push(widget::vertical_space(Length::from(20))) + .push(widget::Space::with_height(20)) .push( widget::column() .width(Length::Fixed(350.)) @@ -168,19 +169,19 @@ impl Pomodoro { left: 10., }), ) - .push(widget::vertical_space(Length::from(5))) + .push(widget::Space::with_height(5)) .push( widget::container( widget::column().push(inner_col).padding(Padding::from(10)), ) - .style(cosmic::theme::Container::Card) + .class(cosmic::theme::Container::Card) .width(Length::Fixed(350.)), ), ) .into() } - pub fn update(&mut self, message: PomodoroMessage) -> Command { + pub fn update(&mut self, message: PomodoroMessage) -> Task { let mut commands = Vec::new(); match message { PomodoroMessage::UpdateConfig => { @@ -232,7 +233,7 @@ impl Pomodoro { } } PomodoroMessage::StartPomodoro => { - commands.push(Command::perform(async {}, |_| Message::StartPomodoroTimer)); + commands.push(Task::perform(async {}, |_| Message::StartPomodoroTimer)); self.in_action = true; if self.notifications_active { let _ = Notification::new() @@ -243,7 +244,7 @@ impl Pomodoro { } } PomodoroMessage::PausePomodoro => { - commands.push(Command::perform(async {}, |_| Message::PausePomodoroTimer)); + commands.push(Task::perform(async {}, |_| Message::PausePomodoroTimer)); if self.notifications_active { let _ = Notification::new() .summary(&fl!("pomodoro-paused")) @@ -264,7 +265,7 @@ impl Pomodoro { self.reset_all(); } } - Command::batch(commands) + Task::batch(commands) } fn reset_all(&mut self) { diff --git a/src/pages/settings.rs b/src/pages/settings.rs index 0f1980b..3c35fc3 100644 --- a/src/pages/settings.rs +++ b/src/pages/settings.rs @@ -1,17 +1,17 @@ +use crate::{app::Message, config::Config, fl}; +use cosmic::iced_core::alignment::Horizontal; use cosmic::{ iced::{self, Length}, - widget::{self, spin_button}, - Command, Element, + widget::{self}, + Element, Task, }; -use crate::{app::Message, config::Config, fl}; - #[derive(Debug, Clone)] pub enum SettingsMessage { TimerDurationChanged(f32), PauseDurationChanged(f32), LongPauseDurationChanged(f32), - PomodoroBeforeLongPauseChanged(spin_button::Message), + PomodoroBeforeLongPauseChanged(u32), NotificationToggle(bool), } @@ -46,9 +46,9 @@ impl Settings { col = col.push(self.timer_view()); widget::container(col) - .width(iced::Length::Fill) - .height(iced::Length::Shrink) - .center_y() + .width(Length::Fill) + .height(Length::Shrink) + .align_x(Horizontal::Center) .into() } @@ -74,7 +74,7 @@ impl Settings { fl!("minutes") ))) .width(Length::Fill) - .align_items(iced::Alignment::End), + .align_x(iced::Alignment::End), ), ) .push( @@ -87,7 +87,7 @@ impl Settings { .height(38), ) .push(widget::divider::horizontal::default()) - .push(widget::vertical_space(Length::from(10))) + .push(widget::Space::with_height(10)) .push( widget::row() .push( @@ -103,7 +103,7 @@ impl Settings { fl!("minutes") ))) .width(Length::Fill) - .align_items(iced::Alignment::End), + .align_x(iced::Alignment::End), ), ) .push( @@ -115,7 +115,7 @@ impl Settings { .width(Length::Fill) .height(38), ) - .push(widget::vertical_space(Length::from(10))) + .push(widget::Space::with_height(10)) .push( widget::row() .push( @@ -131,7 +131,7 @@ impl Settings { fl!("minutes") ))) .width(Length::Fill) - .align_items(iced::Alignment::End), + .align_x(iced::Alignment::End), ), ) .push( @@ -153,34 +153,37 @@ impl Settings { .push( widget::column() .push(widget::spin_button( - &self.pomodoro_before_long_pause_str, + self.pomodoro_before_long_pause_str.clone(), + self.pomodoro_before_long_pause, + 1, + 0, + 100, SettingsMessage::PomodoroBeforeLongPauseChanged, )) .width(Length::Fill) - .align_items(iced::Alignment::End), + .align_x(iced::Alignment::End), ), ), ), ) - .push(widget::vertical_space(Length::from(20))); + .push(widget::Space::with_height(20)); element = element.push( widget::settings::section().title(fl!("notifications")).add( widget::column() .width(Length::Fill) .push(widget::text::text(fl!("activate-notification"))) - .push(widget::toggler( - None, - self.notification_active, - SettingsMessage::NotificationToggle, - )), + .push( + widget::toggler(self.notification_active) + .on_toggle(SettingsMessage::NotificationToggle), + ), ), ); element.into() } - pub fn update(&mut self, message: SettingsMessage) -> Command { + pub fn update(&mut self, message: SettingsMessage) -> Task { let mut commands = Vec::new(); match message { SettingsMessage::TimerDurationChanged(value) => { @@ -205,18 +208,7 @@ impl Settings { .set_long_pause_duration(&config.0.unwrap(), self.long_pause_duration as u32); } SettingsMessage::PomodoroBeforeLongPauseChanged(message) => { - match message { - spin_button::Message::Increment => { - if self.pomodoro_before_long_pause < 15 { - self.pomodoro_before_long_pause += 1; - } - } - spin_button::Message::Decrement => { - if self.pomodoro_before_long_pause > 0 { - self.pomodoro_before_long_pause -= 1; - } - } - } + self.pomodoro_before_long_pause = message.clone(); self.pomodoro_before_long_pause_str = self.pomodoro_before_long_pause.to_string(); let mut config = Config::load(); let _ = config.1.set_pomodoro_before_long_pause( @@ -230,9 +222,9 @@ impl Settings { let _ = config.1.set_notifications_active(&config.0.unwrap(), value); } } - commands.push(Command::perform(async {}, |_| { + commands.push(Task::perform(async {}, |_| { Message::Pomodoro(super::pomodoro::PomodoroMessage::UpdateConfig) })); - Command::batch(commands) + Task::batch(commands) } }