Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions i18n/en/cosmic_ext_tweaks.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ app-description = A tool to customize your COSMIC™ desktop experience.

# Pages
home = Home
date-time = Date and time
dock = Dock
panel = Panel
color-schemes = Color schemes
Expand Down Expand Up @@ -129,6 +130,10 @@ match-desktop = Match desktop
dark = Dark
light = Light

## Date-time
time-format = Date & time format
.format-strftime = Format date and time with strftime

# Menu
view = View

Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct App {
handler: cosmic::cosmic_config::Config,
config: core::config::TweaksConfig,
color_schemes: pages::ColorSchemes,
date_time: pages::DateTime,
dock: pages::Dock,
panel: pages::Panel,
layouts: pages::Layouts,
Expand Down
3 changes: 2 additions & 1 deletion src/app/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use cosmic::{
widget::{self, about::About},
};

use crate::app::App;
use crate::app::flags::Flags;
use crate::app::message::Message;
use crate::app::page::Page;
use crate::app::{App, pages::DateTime};
use crate::app::{context::ContextPage, pages::snapshots::config::SnapshotKind};

use super::Cosmic;
Expand Down Expand Up @@ -76,6 +76,7 @@ impl Cosmic {
config: flags.config,
color_schemes,
layouts: Layouts::default(),
date_time: DateTime::default(),
dock: Dock::default(),
panel: Panel::default(),
snapshots: Snapshots::default(),
Expand Down
1 change: 1 addition & 0 deletions src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use cosmic::{

#[derive(Debug, Clone)]
pub enum Message {
DateTime(pages::date_time::Message),
Dock(pages::dock::Message),
Panel(pages::panel::Message),
Layouts(pages::layouts::Message),
Expand Down
6 changes: 6 additions & 0 deletions src/app/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{fl, icon};
pub enum Page {
#[default]
ColorSchemes,
DateTime,
Dock,
Panel,
Layouts,
Expand All @@ -23,6 +24,7 @@ impl Page {
pub fn title(&self) -> String {
match self {
Self::ColorSchemes => fl!("color-schemes"),
Self::DateTime => fl!("date-time"),
Self::Dock => fl!("dock"),
Self::Panel => fl!("panel"),
Self::Layouts => fl!("layouts"),
Expand All @@ -34,6 +36,9 @@ impl Page {
pub fn icon(&self) -> Icon {
match self {
Self::ColorSchemes => icon!("dark-mode-symbolic", 18),
Self::DateTime => cosmic::widget::icon::from_name("x-office-calendar-symbolic")
.icon()
.size(18),
Self::Dock => icon!("dock-bottom-symbolic", 18),
Self::Panel => icon!("dock-top-symbolic", 18),
Self::Layouts => icon!("view-coverflow-symbolic", 18),
Expand All @@ -45,6 +50,7 @@ impl Page {
pub fn all() -> &'static [Self] {
&[
Self::ColorSchemes,
Self::DateTime,
Self::Dock,
Self::Panel,
Self::Layouts,
Expand Down
68 changes: 68 additions & 0 deletions src/app/pages/date_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use cosmic::{
Element, Task,
cosmic_config::{self, ConfigGet, ConfigSet},
widget::{self, settings},
};

use crate::{app, fl};

const CONF_NAME: &str = "com.system76.CosmicAppletTime";
const CONF_VERS: u64 = 1;
const CONF_STRF: &str = "format_strftime";

pub struct DateTime {
config: Option<cosmic_config::Config>,
/// Experimental strftime formatting.
format_strftime: String,
}

impl Default for DateTime {
fn default() -> Self {
let config = cosmic_config::Config::new(CONF_NAME, CONF_VERS)
.inspect_err(|err| error!("Failed creating config handler for {CONF_NAME}: {err}"))
.ok();
let format_strftime = config
.as_ref()
.and_then(|config| config.get(CONF_STRF).ok())
.unwrap_or_default();

Self {
config,
format_strftime,
}
}
}

impl DateTime {
pub fn view(&self) -> Element<'_, Message> {
settings::section()
.title(fl!("time-format"))
.add(
settings::item::builder(fl!("time-format", "format-strftime")).control(
widget::text_input("", &self.format_strftime).on_input(Message::Strftime),
),
)
.into()
}

pub fn update(&mut self, message: Message) -> Task<app::message::Message> {
match message {
Message::Strftime(format) => {
self.format_strftime = format;

if let Some(config) = self.config.as_ref()
&& let Err(e) = config.set(CONF_STRF, &self.format_strftime)
{
warn!("Error saving {CONF_NAME}/{CONF_STRF} - {e}");
};
}
}

Task::none()
}
}

#[derive(Debug, Clone)]
pub enum Message {
Strftime(String),
}
2 changes: 2 additions & 0 deletions src/app/pages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
pub mod color_schemes;
pub mod date_time;
pub mod dock;
pub mod layouts;
pub mod panel;
pub mod shortcuts;
pub mod snapshots;

pub use color_schemes::ColorSchemes;
pub use date_time::DateTime;
pub use dock::Dock;
pub use layouts::Layouts;
pub use panel::Panel;
Expand Down
3 changes: 3 additions & 0 deletions src/app/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ impl Cosmic {
Message::ToggleContextDrawer => {
app.core_mut().window.show_context = !app.core().window.show_context;
}
Message::DateTime(message) => {
tasks.push(app.date_time.update(message).map(cosmic::action::app))
}
Message::Dock(message) => tasks.push(app.dock.update(message).map(cosmic::action::app)),
Message::Panel(message) => {
tasks.push(app.panel.update(message).map(cosmic::action::app))
Expand Down
1 change: 1 addition & 0 deletions src/app/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Cosmic {
.view()
.map(Box::new)
.map(Message::ColorSchemes),
Page::DateTime => app.date_time.view().map(Message::DateTime),
Page::Dock => app.dock.view().map(Message::Dock),
Page::Panel => app.panel.view().map(Message::Panel),
Page::Layouts => app.layouts.view().map(Message::Layouts),
Expand Down