pub mod command;
mod core;
pub mod cosmic;
#[cfg(all(feature = "winit", feature = "multi-window"))]
pub(crate) mod multi_window;
pub mod settings;
pub mod message {
#[derive(Clone, Debug)]
#[must_use]
pub enum Message<M> {
App(M),
Cosmic(super::cosmic::Message),
#[cfg(feature = "single-instance")]
DbusActivation(super::DbusActivationMessage),
None,
}
pub const fn app<M>(message: M) -> Message<M> {
Message::App(message)
}
pub const fn cosmic<M>(message: super::cosmic::Message) -> Message<M> {
Message::Cosmic(message)
}
pub const fn none<M>() -> Message<M> {
Message::None
}
impl<M> From<M> for Message<M> {
fn from(value: M) -> Self {
Self::App(value)
}
}
}
use std::borrow::Cow;
pub use self::command::Task;
pub use self::core::Core;
pub use self::settings::Settings;
use crate::prelude::*;
use crate::theme::THEME;
use crate::widget::{
container, context_drawer, horizontal_space, id_container, menu, nav_bar, popover,
};
use apply::Apply;
use iced::window;
use iced::{Length, Subscription};
pub use message::Message;
use url::Url;
#[cfg(feature = "single-instance")]
use {
iced_futures::futures::channel::mpsc::{Receiver, Sender},
iced_futures::futures::SinkExt,
std::any::TypeId,
std::collections::HashMap,
zbus::{interface, proxy, zvariant::Value},
};
pub(crate) fn iced_settings<App: Application>(
settings: Settings,
flags: App::Flags,
) -> (iced::Settings, (Core, App::Flags), iced::window::Settings) {
preload_fonts();
let mut core = Core::default();
core.debug = settings.debug;
core.icon_theme_override = settings.default_icon_theme.is_some();
core.set_scale_factor(settings.scale_factor);
core.set_window_width(settings.size.width);
core.set_window_height(settings.size.height);
if let Some(icon_theme) = settings.default_icon_theme {
crate::icon_theme::set_default(icon_theme);
} else {
crate::icon_theme::set_default(crate::config::icon_theme());
}
THEME.lock().unwrap().set_theme(settings.theme.theme_type);
if settings.no_main_window {
core.main_window = Some(iced::window::Id::NONE);
}
let mut iced = iced::Settings::default();
iced.antialiasing = settings.antialiasing;
iced.default_font = settings.default_font;
iced.default_text_size = iced::Pixels(settings.default_text_size);
let exit_on_close = settings.exit_on_close;
iced.is_daemon = false;
iced.exit_on_close_request = settings.is_daemon;
let mut window_settings = iced::window::Settings::default();
window_settings.exit_on_close_request = exit_on_close;
iced.id = Some(App::APP_ID.to_owned());
#[cfg(target_os = "linux")]
{
window_settings.platform_specific.application_id = App::APP_ID.to_string();
}
core.exit_on_main_window_closed = exit_on_close;
if let Some(border_size) = settings.resizable {
window_settings.resize_border = border_size as u32;
window_settings.resizable = true;
}
window_settings.decorations = !settings.client_decorations;
window_settings.size = settings.size;
let min_size = settings.size_limits.min();
if min_size != iced::Size::ZERO {
window_settings.min_size = Some(min_size);
}
let max_size = settings.size_limits.max();
if max_size != iced::Size::INFINITY {
window_settings.max_size = Some(max_size);
}
window_settings.transparent = settings.transparent;
(iced, (core, flags), window_settings)
}
pub fn run<App: Application>(settings: Settings, flags: App::Flags) -> iced::Result {
let default_font = settings.default_font;
let (settings, mut flags, window_settings) = iced_settings::<App>(settings, flags);
#[cfg(not(feature = "multi-window"))]
{
iced::application(
cosmic::Cosmic::title,
cosmic::Cosmic::update,
cosmic::Cosmic::view,
)
.subscription(cosmic::Cosmic::subscription)
.style(cosmic::Cosmic::style)
.theme(cosmic::Cosmic::theme)
.window_size((500.0, 800.0))
.settings(settings)
.window(window_settings)
.run_with(move || cosmic::Cosmic::<App>::init(flags))
}
#[cfg(feature = "multi-window")]
{
let mut app = multi_window::multi_window::<_, _, _, _, App::Executor>(
cosmic::Cosmic::title,
cosmic::Cosmic::update,
cosmic::Cosmic::view,
);
if flags.0.main_window.is_none() {
app = app.window(window_settings);
flags.0.main_window = Some(iced_core::window::Id::RESERVED);
}
app.subscription(cosmic::Cosmic::subscription)
.style(cosmic::Cosmic::style)
.theme(cosmic::Cosmic::theme)
.settings(settings)
.run_with(move || cosmic::Cosmic::<App>::init(flags))
}
}
#[cfg(feature = "single-instance")]
#[derive(Debug, Clone)]
pub struct DbusActivationMessage<Action = String, Args = Vec<String>> {
pub activation_token: Option<String>,
pub desktop_startup_id: Option<String>,
pub msg: DbusActivationDetails<Action, Args>,
}
#[derive(Debug, Clone)]
pub enum DbusActivationDetails<Action = String, Args = Vec<String>> {
Activate,
Open {
url: Vec<Url>,
},
ActivateAction {
action: Action,
args: Args,
},
}
#[cfg(feature = "single-instance")]
#[derive(Debug, Default)]
pub struct DbusActivation(Option<Sender<DbusActivationMessage>>);
#[cfg(feature = "single-instance")]
impl DbusActivation {
#[must_use]
pub fn new() -> Self {
Self(None)
}
pub fn rx(&mut self) -> Receiver<DbusActivationMessage> {
let (tx, rx) = iced_futures::futures::channel::mpsc::channel(10);
self.0 = Some(tx);
rx
}
}
#[cfg(feature = "single-instance")]
#[proxy(interface = "org.freedesktop.DbusActivation", assume_defaults = true)]
pub trait DbusActivationInterface {
fn activate(&mut self, platform_data: HashMap<&str, Value<'_>>) -> zbus::Result<()>;
fn open(
&mut self,
uris: Vec<&str>,
platform_data: HashMap<&str, Value<'_>>,
) -> zbus::Result<()>;
fn activate_action(
&mut self,
action_name: &str,
parameter: Vec<&str>,
platform_data: HashMap<&str, Value<'_>>,
) -> zbus::Result<()>;
}
#[cfg(feature = "single-instance")]
#[interface(name = "org.freedesktop.DbusActivation")]
impl DbusActivation {
async fn activate(&mut self, platform_data: HashMap<&str, Value<'_>>) {
if let Some(tx) = &mut self.0 {
let _ = tx
.send(DbusActivationMessage {
activation_token: platform_data.get("activation-token").and_then(|t| match t {
Value::Str(t) => Some(t.to_string()),
_ => None,
}),
desktop_startup_id: platform_data.get("desktop-startup-id").and_then(
|t| match t {
Value::Str(t) => Some(t.to_string()),
_ => None,
},
),
msg: DbusActivationDetails::Activate,
})
.await;
}
}
async fn open(&mut self, uris: Vec<&str>, platform_data: HashMap<&str, Value<'_>>) {
if let Some(tx) = &mut self.0 {
let _ = tx
.send(DbusActivationMessage {
activation_token: platform_data.get("activation-token").and_then(|t| match t {
Value::Str(t) => Some(t.to_string()),
_ => None,
}),
desktop_startup_id: platform_data.get("desktop-startup-id").and_then(
|t| match t {
Value::Str(t) => Some(t.to_string()),
_ => None,
},
),
msg: DbusActivationDetails::Open {
url: uris.iter().filter_map(|u| Url::parse(u).ok()).collect(),
},
})
.await;
}
}
async fn activate_action(
&mut self,
action_name: &str,
parameter: Vec<&str>,
platform_data: HashMap<&str, Value<'_>>,
) {
if let Some(tx) = &mut self.0 {
let _ = tx
.send(DbusActivationMessage {
activation_token: platform_data.get("activation-token").and_then(|t| match t {
Value::Str(t) => Some(t.to_string()),
_ => None,
}),
desktop_startup_id: platform_data.get("desktop-startup-id").and_then(
|t| match t {
Value::Str(t) => Some(t.to_string()),
_ => None,
},
),
msg: DbusActivationDetails::ActivateAction {
action: action_name.to_string(),
args: parameter
.iter()
.map(std::string::ToString::to_string)
.collect(),
},
})
.await;
}
}
}
#[cfg(feature = "single-instance")]
pub fn run_single_instance<App: Application>(settings: Settings, flags: App::Flags) -> iced::Result
where
App::Flags: CosmicFlags,
App::Message: Clone + std::fmt::Debug + Send + 'static,
{
let activation_token = std::env::var("XDG_ACTIVATION_TOKEN").ok();
let override_single = std::env::var("COSMIC_SINGLE_INSTANCE")
.map(|v| &v.to_lowercase() == "false" || &v == "0")
.unwrap_or_default();
if override_single {
return run::<App>(settings, flags);
}
let path: String = format!("/{}", App::APP_ID.replace('.', "/"));
let Ok(conn) = zbus::blocking::Connection::session() else {
tracing::warn!("Failed to connect to dbus");
return run::<App>(settings, flags);
};
if DbusActivationInterfaceProxyBlocking::builder(&conn)
.destination(App::APP_ID)
.ok()
.and_then(|b| b.path(path).ok())
.and_then(|b| b.destination(App::APP_ID).ok())
.and_then(|b| b.build().ok())
.is_some_and(|mut p| {
match {
let mut platform_data = HashMap::new();
if let Some(activation_token) = activation_token {
platform_data.insert("activation-token", activation_token.into());
}
if let Ok(startup_id) = std::env::var("DESKTOP_STARTUP_ID") {
platform_data.insert("desktop-startup-id", startup_id.into());
}
if let Some(action) = flags.action() {
let action = action.to_string();
p.activate_action(&action, flags.args(), platform_data)
} else {
p.activate(platform_data)
}
} {
Ok(()) => {
tracing::info!("Successfully activated another instance");
true
}
Err(err) => {
tracing::warn!(?err, "Failed to activate another instance");
false
}
}
})
{
tracing::info!("Another instance is running");
Ok(())
} else {
let (settings, mut flags, window_settings) = iced_settings::<App>(settings, flags);
flags.0.single_instance = true;
#[cfg(not(feature = "multi-window"))]
{
iced::application(
cosmic::Cosmic::title,
cosmic::Cosmic::update,
cosmic::Cosmic::view,
)
.subscription(cosmic::Cosmic::subscription)
.style(cosmic::Cosmic::style)
.theme(cosmic::Cosmic::theme)
.window_size((500.0, 800.0))
.settings(settings)
.window(window_settings)
.run_with(move || cosmic::Cosmic::<App>::init(flags))
}
#[cfg(feature = "multi-window")]
{
let mut app = multi_window::multi_window::<_, _, _, _, App::Executor>(
cosmic::Cosmic::title,
cosmic::Cosmic::update,
cosmic::Cosmic::view,
);
if flags.0.main_window.is_none() {
app = app.window(window_settings);
flags.0.main_window = Some(iced_core::window::Id::RESERVED);
}
app.subscription(cosmic::Cosmic::subscription)
.style(cosmic::Cosmic::style)
.theme(cosmic::Cosmic::theme)
.settings(settings)
.run_with(move || cosmic::Cosmic::<App>::init(flags))
}
}
}
pub trait CosmicFlags {
type SubCommand: ToString + std::fmt::Debug + Clone + Send + 'static;
type Args: Into<Vec<String>> + std::fmt::Debug + Clone + Send + 'static;
#[must_use]
fn action(&self) -> Option<&Self::SubCommand> {
None
}
#[must_use]
fn args(&self) -> Vec<&str> {
Vec::new()
}
}
#[allow(unused_variables)]
pub trait Application
where
Self: Sized + 'static,
{
type Executor: iced_futures::Executor;
type Flags;
type Message: Clone + std::fmt::Debug + Send + 'static;
const APP_ID: &'static str;
fn core(&self) -> &Core;
fn core_mut(&mut self) -> &mut Core;
fn init(core: Core, flags: Self::Flags) -> (Self, Task<Self::Message>);
fn context_drawer(&self) -> Option<Element<Self::Message>> {
None
}
fn context_header_actions(&self) -> Vec<Element<Message<Self::Message>>> {
Vec::new()
}
fn context_drawer_header(&self) -> Option<Element<Message<Self::Message>>> {
None
}
fn context_drawer_footer(&self) -> Option<Element<Message<Self::Message>>> {
None
}
fn dialog(&self) -> Option<Element<Self::Message>> {
None
}
fn footer(&self) -> Option<Element<Self::Message>> {
None
}
fn header_start(&self) -> Vec<Element<Self::Message>> {
Vec::new()
}
fn header_center(&self) -> Vec<Element<Self::Message>> {
Vec::new()
}
fn header_end(&self) -> Vec<Element<Self::Message>> {
Vec::new()
}
fn nav_bar(&self) -> Option<Element<Message<Self::Message>>> {
if !self.core().nav_bar_active() {
return None;
}
let nav_model = self.nav_model()?;
let mut nav =
crate::widget::nav_bar(nav_model, |id| Message::Cosmic(cosmic::Message::NavBar(id)))
.on_context(|id| Message::Cosmic(cosmic::Message::NavBarContext(id)))
.context_menu(self.nav_context_menu(self.core().nav_bar_context()))
.into_container()
.width(iced::Length::Shrink)
.height(iced::Length::Shrink);
if !self.core().is_condensed() {
nav = nav.max_width(280);
}
Some(Element::from(nav))
}
fn nav_context_menu(&self, id: nav_bar::Id) -> Option<Vec<menu::Tree<Message<Self::Message>>>> {
None
}
fn nav_model(&self) -> Option<&nav_bar::Model> {
None
}
fn on_app_exit(&mut self) -> Option<Self::Message> {
None
}
fn on_close_requested(&self, id: window::Id) -> Option<Self::Message> {
None
}
fn on_context_drawer(&mut self) -> Task<Self::Message> {
Task::none()
}
fn on_escape(&mut self) -> Task<Self::Message> {
Task::none()
}
fn on_nav_select(&mut self, id: nav_bar::Id) -> Task<Self::Message> {
Task::none()
}
fn on_nav_context(&mut self, id: nav_bar::Id) -> Task<Self::Message> {
Task::none()
}
fn on_search(&mut self) -> Task<Self::Message> {
Task::none()
}
fn on_window_resize(&mut self, id: window::Id, width: f32, height: f32) {}
fn subscription(&self) -> Subscription<Self::Message> {
Subscription::none()
}
fn update(&mut self, message: Self::Message) -> Task<Self::Message> {
Task::none()
}
fn system_theme_update(
&mut self,
keys: &[&'static str],
new_theme: &cosmic_theme::Theme,
) -> Task<Self::Message> {
Task::none()
}
fn system_theme_mode_update(
&mut self,
keys: &[&'static str],
new_theme: &cosmic_theme::ThemeMode,
) -> Task<Self::Message> {
Task::none()
}
fn view(&self) -> Element<Self::Message>;
fn view_window(&self, id: window::Id) -> Element<Self::Message> {
panic!("no view for window {id:?}");
}
fn style(&self) -> Option<iced_runtime::Appearance> {
None
}
#[cfg(feature = "single-instance")]
fn dbus_activation(&mut self, msg: DbusActivationMessage) -> Task<Self::Message> {
Task::none()
}
}
pub trait ApplicationExt: Application {
fn drag(&mut self) -> Task<Self::Message>;
fn maximize(&mut self) -> Task<Self::Message>;
fn minimize(&mut self) -> Task<Self::Message>;
#[cfg(not(feature = "multi-window"))]
fn title(&self) -> &str;
#[cfg(feature = "multi-window")]
fn title(&self, id: window::Id) -> &str;
fn set_context_title(&mut self, title: String) {
self.core_mut().set_context_title(title);
}
fn set_show_context(&mut self, show: bool) {
self.core_mut().set_show_context(show);
}
fn set_header_title(&mut self, title: String) {
self.core_mut().set_header_title(title);
}
#[cfg(not(feature = "multi-window"))]
fn set_window_title(&mut self, title: String) -> Task<Self::Message>;
#[cfg(feature = "multi-window")]
fn set_window_title(&mut self, title: String, id: window::Id) -> Task<Self::Message>;
fn view_main(&self) -> Element<Message<Self::Message>>;
}
impl<App: Application> ApplicationExt for App {
fn drag(&mut self) -> Task<Self::Message> {
self.core().drag(None)
}
fn maximize(&mut self) -> Task<Self::Message> {
self.core().maximize(None, true)
}
fn minimize(&mut self) -> Task<Self::Message> {
self.core().minimize(None)
}
#[cfg(feature = "multi-window")]
fn title(&self, id: window::Id) -> &str {
self.core().title.get(&id).map_or("", |s| s.as_str())
}
#[cfg(not(feature = "multi-window"))]
fn title(&self) -> &str {
self.core()
.main_window_id()
.and_then(|id| self.core().title.get(&id).map(std::string::String::as_str))
.unwrap_or("")
}
#[cfg(feature = "multi-window")]
fn set_window_title(&mut self, title: String, id: window::Id) -> Task<Self::Message> {
self.core_mut().title.insert(id, title.clone());
self.core().set_title(Some(id), title)
}
#[cfg(not(feature = "multi-window"))]
fn set_window_title(&mut self, title: String) -> Task<Self::Message> {
let Some(id) = self.core().main_window_id() else {
return Task::none();
};
self.core_mut().title.insert(id, title.clone());
Task::none()
}
#[allow(clippy::too_many_lines)]
fn view_main(&self) -> Element<Message<Self::Message>> {
let core = self.core();
let is_condensed = core.is_condensed();
let sharp_corners = core.window.sharp_corners;
let content_container = core.window.content_container;
let nav_bar_active = core.nav_bar_active();
let focused = core
.focused_window()
.is_some_and(|i| Some(i) == self.core().main_window_id());
let main_content_padding = if content_container {
if nav_bar_active {
[0, 8, 8, 0]
} else {
[0, 8, 8, 8]
}
} else {
[0, 0, 0, 0]
};
let content_row = crate::widget::row::with_children({
let mut widgets = Vec::with_capacity(3);
let has_nav = if let Some(nav) = self
.nav_bar()
.map(|nav| id_container(nav, iced_core::id::Id::new("COSMIC_nav_bar")))
{
widgets.push(container(nav).padding([0, 8, 8, 8]).into());
true
} else {
false
};
if self.nav_model().is_none() || core.show_content() {
let main_content = self.view().map(Message::App);
let context_width = core.context_width(has_nav);
if core.window.context_is_overlay {
if let Some(context) = self.context_drawer() {
widgets.push(
context_drawer(
&core.window.context_title,
self.context_header_actions(),
self.context_drawer_header(),
self.context_drawer_footer(),
Message::Cosmic(cosmic::Message::ContextDrawer(false)),
main_content,
context.map(Message::App),
context_width,
)
.apply(|drawer| {
Element::from(id_container(
drawer,
iced_core::id::Id::new("COSMIC_context_drawer"),
))
})
.apply(container)
.padding(if content_container {
[0, 8, 8, 0]
} else {
[0, 0, 0, 0]
})
.into(),
);
} else {
widgets.push(container(main_content).padding(main_content_padding).into());
}
} else {
widgets.push(container(main_content).padding(main_content_padding).into());
if let Some(context) = self.context_drawer() {
widgets.push(
crate::widget::ContextDrawer::new_inner(
&core.window.context_title,
self.context_header_actions(),
self.context_drawer_header(),
self.context_drawer_footer(),
context.map(Message::App),
Message::Cosmic(cosmic::Message::ContextDrawer(false)),
context_width,
)
.apply(container)
.width(context_width)
.apply(|drawer| {
Element::from(id_container(
drawer,
iced_core::id::Id::new("COSMIC_context_drawer"),
))
})
.apply(container)
.padding(if content_container {
[0, 8, 8, 0]
} else {
[0, 0, 0, 0]
})
.into(),
)
} else {
widgets.push(horizontal_space().width(Length::Shrink).into());
}
}
}
widgets
});
let content_col = crate::widget::column::with_capacity(2)
.push(content_row)
.push_maybe(
self.footer()
.map(|footer| container(footer.map(Message::App)).padding([0, 8, 8, 8])),
);
let content: Element<_> = if core.window.content_container {
content_col
.apply(container)
.width(iced::Length::Fill)
.height(iced::Length::Fill)
.class(crate::theme::Container::WindowBackground)
.apply(|w| id_container(w, iced_core::id::Id::new("COSMIC_content_container")))
.into()
} else {
content_col.into()
};
let view_column = crate::widget::column::with_capacity(2)
.push_maybe(if core.window.show_headerbar {
Some({
let mut header = crate::widget::header_bar()
.focused(focused)
.title(&core.window.header_title)
.on_drag(Message::Cosmic(cosmic::Message::Drag))
.on_right_click(Message::Cosmic(cosmic::Message::ShowWindowMenu))
.on_double_click(Message::Cosmic(cosmic::Message::Maximize));
if self.nav_model().is_some() {
let toggle = crate::widget::nav_bar_toggle()
.active(core.nav_bar_active())
.selected(focused)
.on_toggle(if is_condensed {
Message::Cosmic(cosmic::Message::ToggleNavBarCondensed)
} else {
Message::Cosmic(cosmic::Message::ToggleNavBar)
})
.class(crate::theme::Button::HeaderBar);
header = header.start(toggle);
}
if core.window.show_close {
header = header.on_close(Message::Cosmic(cosmic::Message::Close));
}
if core.window.show_maximize && crate::config::show_maximize() {
header = header.on_maximize(Message::Cosmic(cosmic::Message::Maximize));
}
if core.window.show_minimize && crate::config::show_minimize() {
header = header.on_minimize(Message::Cosmic(cosmic::Message::Minimize));
}
for element in self.header_start() {
header = header.start(element.map(Message::App));
}
for element in self.header_center() {
header = header.center(element.map(Message::App));
}
for element in self.header_end() {
header = header.end(element.map(Message::App));
}
header.apply(|w| id_container(w, iced_core::id::Id::new("COSMIC_header")))
})
} else {
None
})
.push(content)
.apply(container)
.padding(if sharp_corners { 0 } else { 1 })
.style(move |theme| container::Style {
border: iced::Border {
color: theme.cosmic().bg_divider().into(),
width: if sharp_corners { 0.0 } else { 1.0 },
radius: theme.cosmic().radius_s().map(|x| x + 2.0).into(),
},
..Default::default()
});
let mut popover = popover(view_column).modal(true);
if let Some(dialog) = self
.dialog()
.map(|w| Element::from(id_container(w, iced_core::id::Id::new("COSMIC_dialog"))))
{
popover = popover.popup(dialog.map(Message::App));
}
let view_element: Element<_> = popover.into();
view_element.debug(core.debug)
}
}
#[cfg(feature = "single-instance")]
fn single_instance_subscription<App: ApplicationExt>() -> Subscription<Message<App::Message>> {
use iced_futures::futures::StreamExt;
iced_futures::Subscription::run_with_id(
TypeId::of::<DbusActivation>(),
iced::stream::channel(10, move |mut output| async move {
let mut single_instance: DbusActivation = DbusActivation::new();
let mut rx = single_instance.rx();
if let Ok(builder) = zbus::ConnectionBuilder::session() {
let path: String = format!("/{}", App::APP_ID.replace('.', "/"));
if let Ok(conn) = builder.build().await {
if conn.object_server().at(path, single_instance).await != Ok(true) {
tracing::error!("Failed to serve dbus");
std::process::exit(1);
}
if conn.request_name(App::APP_ID).await.is_err() {
tracing::error!("Failed to serve dbus");
std::process::exit(1);
}
#[cfg(feature = "smol")]
let handle = {
std::thread::spawn(move || {
let conn_clone = _conn.clone();
zbus::block_on(async move {
loop {
conn_clone.executor().tick().await;
}
})
})
};
while let Some(mut msg) = rx.next().await {
if let Some(token) = msg.activation_token.take() {
if let Err(err) = output
.send(Message::Cosmic(cosmic::Message::Activate(token)))
.await
{
tracing::error!(?err, "Failed to send message");
}
}
if let Err(err) = output.send(Message::DbusActivation(msg)).await {
tracing::error!(?err, "Failed to send message");
}
}
}
} else {
tracing::warn!("Failed to connect to dbus for single instance");
}
loop {
iced::futures::pending!();
}
}),
)
}
const EMBEDDED_FONTS: &[&[u8]] = &[
include_bytes!("../../res/Fira/FiraSans-Light.otf"),
include_bytes!("../../res/Fira/FiraSans-Regular.otf"),
include_bytes!("../../res/Fira/FiraSans-SemiBold.otf"),
include_bytes!("../../res/Fira/FiraSans-Bold.otf"),
include_bytes!("../../res/Fira/FiraMono-Regular.otf"),
];
fn preload_fonts() {
let mut font_system = iced::advanced::graphics::text::font_system()
.write()
.unwrap();
EMBEDDED_FONTS
.into_iter()
.for_each(move |font| font_system.load_font(Cow::Borrowed(font)));
}