Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update libcosmic (+ other deps I think) #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
351 changes: 148 additions & 203 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ features = ["fluent-system", "desktop-requester"]
[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic.git"
default-features = false
features = ["tokio", "winit", "desktop", "multi-window"]
features = ["tokio", "winit", "about"]

[features]
default = ["dbus-config", "wgpu"]
default = ["wgpu"]
wgpu = ["libcosmic/wgpu"]
dbus-config = ["libcosmic/dbus-config"]

Expand Down
4 changes: 4 additions & 0 deletions i18n/en-GB/examine.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ wip = Work in Progress
error-occurred = An error has occurred
error-occurred-with-msg = An error has occurred: {$error}

# About
support = Support
repository = Repository

# Distribution Page
pretty-name = Pretty Name
name = Name
Expand Down
4 changes: 4 additions & 0 deletions i18n/en/examine.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ wip = Work in Progress
error-occurred = An error has occurred
error-occurred-with-msg = An error has occurred: {$error}

# About
support = Support
repository = Repository

# Distribution Page
pretty-name = Pretty Name
name = Name
Expand Down
2 changes: 2 additions & 0 deletions res/icons/bundled/info-outline-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 40 additions & 38 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

use crate::config::Config;
use crate::fl;
use cosmic::app::{Core, Task, about::About};
use crate::icons;
use cosmic::app::{Core, Task, context_drawer};
use cosmic::cosmic_config::{self, CosmicConfigEntry};
use cosmic::iced::{stream, Subscription, Alignment, Length};
use cosmic::widget::{self, icon, list_column, menu, nav_bar, row, settings};
use cosmic::widget::{self, icon, list_column, menu, nav_bar, row, settings, about::About};
use cosmic::{theme, Application, ApplicationExt, Apply, Element};
use etc_os_release::OsRelease;
use futures_util::SinkExt;
Expand All @@ -32,8 +33,8 @@ pub enum Message {
LaunchUrl(String),
SubscriptionChannel,
ToggleContextPage(ContextPage),
ToggleContextDrawer,
UpdateConfig(Config),
Cosmic(cosmic::app::cosmic::Message),
}

impl Application for AppModel {
Expand All @@ -59,14 +60,33 @@ impl Application for AppModel {
let mut tasks = vec![];

let about = About::default()
.set_application_name(fl!("app-title"))
.set_application_icon(Self::APP_ID)
.set_developer_name("COSMIC Utilities")
.set_version(env!("CARGO_PKG_VERSION"))
.set_license_type("GPL-3.0")
.set_repository_url(REPOSITORY)
.set_support_url(format!("{REPOSITORY}/issues"))
.set_developers([("Dexter Reed".into(), "[email protected]".into())]);
.name(fl!("app-title"))
.icon(Self::APP_ID)
.author("COSMIC Utilities")
.version(env!("CARGO_PKG_VERSION"))
.license("GPL-3.0-only")
.links([
(
fl!("support"), format!("{REPOSITORY}/issues").as_str(),
),
(
fl!("repository"), REPOSITORY.into(),
),
])
.developers([
(
"Dexter Reed",
"[email protected]"
),
(
"Eduardo Flores",
"[email protected]"
),
(
"Aaron Honeycutt",
"[email protected]"
)
]);

nav.insert()
.text(fl!("distribution"))
Expand Down Expand Up @@ -135,16 +155,12 @@ impl Application for AppModel {
(app, Task::batch(tasks))
}

fn about(&self) -> Option<&About> {
Some(&self.about)
}

fn header_start(&self) -> Vec<Element<Self::Message>> {
let menu_bar = menu::bar(vec![menu::Tree::with_children(
menu::root(fl!("view")),
menu::items(
&self.key_binds,
vec![menu::Item::Button(fl!("about"), MenuAction::About)],
vec![menu::Item::Button(fl!("about"), Some(icons::get_handle("info-outline-symbolic", 14)), MenuAction::About)],
),
)]);

Expand All @@ -155,13 +171,13 @@ impl Application for AppModel {
Some(&self.nav)
}

fn context_drawer(&self) -> Option<Element<Self::Message>> {
fn context_drawer(&self) -> Option<context_drawer::ContextDrawer<Self::Message>> {
if !self.core.window.show_context {
return None;
}

Some(match self.context_page {
ContextPage::About => self.about_view()?.map(Message::Cosmic),
ContextPage::About => context_drawer::about(&self.about, Message::LaunchUrl, Message::ToggleContextDrawer),
})
}

Expand Down Expand Up @@ -481,14 +497,8 @@ impl Application for AppModel {
}

fn update(&mut self, message: Self::Message) -> Task<Self::Message> {
let mut tasks = vec![];
let tasks = vec![];
match message {
Message::Cosmic(message) => {
tasks.push(cosmic::app::command::message(cosmic::app::message::cosmic(
message,
)));
}

Message::LaunchUrl(url) => match open::that_detached(&url) {
Ok(()) => {}
Err(err) => {
Expand All @@ -507,8 +517,10 @@ impl Application for AppModel {
self.context_page = context_page;
self.core.window.show_context = true;
}
}

self.set_context_title(context_page.title());
Message::ToggleContextDrawer => {
self.core.window.show_context = !self.core.window.show_context;
}

Message::UpdateConfig(config) => {
Expand All @@ -534,11 +546,7 @@ impl AppModel {
window_title.push_str(page);
}

if let Some(window_id) = self.core.main_window_id() {
self.set_window_title(window_title.to_string(), window_id)
} else {
Task::none()
}
self.set_window_title(window_title.to_string())
}
}

Expand All @@ -557,13 +565,7 @@ pub enum ContextPage {
About,
}

impl ContextPage {
fn title(&self) -> String {
match self {
Self::About => fl!("about"),
}
}
}
// impl ContextPage {}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MenuAction {
Expand Down
71 changes: 71 additions & 0 deletions src/icons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: GPL-3.0-only

use cosmic::widget::icon;
use std::collections::HashMap;
use std::sync::{Mutex, OnceLock};

pub(crate) static ICON_CACHE: OnceLock<Mutex<IconCache>> = OnceLock::new();

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct IconCacheKey {
name: &'static str,
size: u16,
}

pub struct IconCache {
cache: HashMap<IconCacheKey, icon::Handle>,
}

impl IconCache {
pub fn new() -> Self {
let mut cache = HashMap::new();

macro_rules! bundle {
($name:expr, $size:expr) => {
let data: &'static [u8] =
include_bytes!(concat!("../res/icons/bundled/", $name, ".svg"));
cache.insert(
IconCacheKey {
name: $name,
size: $size,
},
icon::from_svg_bytes(data).symbolic(true),
);
};
}

bundle!("info-outline-symbolic", 14);

Self { cache }
}

#[allow(dead_code)]
pub fn get(&mut self, name: &'static str, size: u16) -> icon::Icon {
let handle = self
.cache
.entry(IconCacheKey { name, size })
.or_insert_with(|| icon::from_name(name).size(size).handle())
.clone();
icon::icon(handle).size(size)
}

pub fn get_handle(&mut self, name: &'static str, size: u16) -> icon::Handle {
let handle = self
.cache
.entry(IconCacheKey { name, size })
.or_insert_with(|| icon::from_name(name).size(size).handle())
.clone();
handle
}
}

#[allow(dead_code)]
pub fn get_icon(name: &'static str, size: u16) -> icon::Icon {
let mut icon_cache = ICON_CACHE.get().unwrap().lock().unwrap();
icon_cache.get(name, size)
}

pub fn get_handle(name: &'static str, size: u16) -> icon::Handle {
let mut icon_cache = ICON_CACHE.get().unwrap().lock().unwrap();
icon_cache.get_handle(name, size)
}
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// SPDX-License-Identifier: GPL-3.0-only

use std::sync::Mutex;

mod app;
mod config;
mod i18n;
mod icons;

fn main() -> cosmic::iced::Result {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn,examine=info,warn")).init();
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
i18n::init(&requested_languages);
let settings = cosmic::app::Settings::default();
icons::ICON_CACHE.get_or_init(|| Mutex::new(icons::IconCache::new()));

let settings = cosmic::app::Settings::default().size_limits(
cosmic::iced::Limits::NONE
.min_width(360.0)
.min_height(180.0),
);
cosmic::app::run::<app::AppModel>(settings, ())
}