use iced::{
Element, Length, Subscription, Task, Theme, system,
theme::Mode,
widget::{container, text},
};
enum Message {
ThemeModeChanged(Mode),
}
struct App {
theme_light: Theme,
theme_dark: Theme,
mode: Mode,
}
impl App {
fn new() -> Self {
Self {
theme_light: Theme::Light,
theme_dark: Theme::Dark,
mode: Mode::None,
}
}
fn update(&mut self, msg: Message) -> Task<Message> {
match msg {
Message::ThemeModeChanged(mode) => self.mode = mode,
};
Task::none()
}
fn theme(&self) -> Theme {
match self.mode {
Mode::None => self.theme_light.clone(),
Mode::Light => self.theme_light.clone(),
Mode::Dark => self.theme_dark.clone(),
}
}
fn subscription(&self) -> Subscription<Message> {
system::theme_changes().map(|mode| {
std::println!("theme changed! {mode:?}");
Message::ThemeModeChanged(mode)
})
}
fn view(&self) -> Element<'_, Message> {
container(text!("Hello Theme Changes"))
.center(Length::Fill)
.into()
}
}
fn main() -> Result<(), iced::Error> {
iced::application(App::new, App::update, App::view)
.subscription(App::subscription)
.theme(App::theme)
.run()
}
When I change from "Light" to "Dark" or vice-versa in the macOS Settings app's Appearance pane, it should print a message and change the appearance of the app.
Is your issue REALLY a bug?
Is there an existing issue for this?
Is this issue related to iced?
What happened?
I am attempting to use
iced::system::theme_changesto create a subscription to notify my app when the system switches between light and dark mode, so my app can follow. It is not working on macOS 15.7. I found a relevant discussion in the discord from last December, but could not find any resolution for that issue. I have a minimal reproduction working:What is the expected behavior?
When I change from "Light" to "Dark" or vice-versa in the macOS Settings app's Appearance pane, it should print a message and change the appearance of the app.
Version
crates.io release
Operating System
macOS
Do you have any log output?