Skip to content

Commit

Permalink
fix: clock now works!
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
  • Loading branch information
ryanabx committed Aug 22, 2024
1 parent 56405ad commit 7d09a79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,36 @@ use std::{
use chrono::{Timelike, Utc};
use iced::{
futures::SinkExt,
widget::{
column,
text::Style,
},
widget::{column, text::Style},
Color, Command,
};

#[derive(Clone, Debug)]
pub enum ClockMessage {
UpdateClock(String),
UpdateDate(String),
UpdateClock(String, String),
}

#[derive(Clone, Debug)]
pub struct Clock {
_date: String,
date: String,
time: String,
}

impl Clock {
pub fn new() -> Self {
Self {
_date: "".to_string(),
date: "".to_string(),
time: "".to_string(),
}
}

pub fn handle_message(&mut self, clock_message: ClockMessage) -> iced::Command<ClockMessage> {
match clock_message {
ClockMessage::UpdateClock(new_time) => {
println!("Updating time to {}", &new_time);
ClockMessage::UpdateClock(new_time, new_date) => {
self.time = new_time;
self.date = new_date;
Command::none()
}
_ => todo!(),
}
}

Expand All @@ -56,17 +51,17 @@ impl Clock {
}

pub fn subscription(&self) -> iced::Subscription<ClockMessage> {
struct ClockWorker;
iced::subscription::channel(
std::any::TypeId::of::<ClockWorker>(),
100,
std::any::TypeId::of::<ClockMessage>(),
0,
|mut output| async move {
loop {
let now = Utc::now();
let formatted_time = now.format("%Y-%m-%d %H:%M:%S").to_string();
let formatted_time = now.format("%H:%M:%S").to_string();
let formatted_date = now.format("%Y-%m-%d").to_string();
println!("Sending {} to main thread", formatted_time);
output
.send(ClockMessage::UpdateClock(formatted_time))
let _ = output
.send(ClockMessage::UpdateClock(formatted_time, formatted_date))
.await
.unwrap();
println!("Through sending thing");
Expand Down
4 changes: 2 additions & 2 deletions src/settings_tray/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clock_subscription::{Clock, ClockMessage};
use clock::{Clock, ClockMessage};
use iced::widget::row;

mod clock_subscription;
mod clock;

#[derive(Clone, Debug)]
pub struct SettingsTray {
Expand Down

0 comments on commit 7d09a79

Please sign in to comment.