Skip to content

Commit

Permalink
chore: update libcosmic
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Nov 18, 2024
1 parent bc0ca5d commit 42e3955
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 55 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ chrono = { version = "0.4.38", features = ["serde"] }
[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic.git"
default-features = false
features = ["multi-window", "tokio", "winit", "wgpu", "desktop"]
features = ["multi-window", "tokio", "winit", "wgpu", "about"]

[dependencies.cosmic-ext-config-templates]
git = "https://github.com/ryanabx/cosmic-ext-config-templates"
Expand Down
58 changes: 33 additions & 25 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use cosmic::{
app::{self, Core},
app::{self, context_drawer::ContextDrawer, Core},
cosmic_config::{self, Update},
cosmic_theme::{self, ThemeMode},
iced::{
Expand Down Expand Up @@ -88,6 +88,7 @@ pub enum Message {
DialogCancel,
SaveNewColorScheme(String),
ToggleContextPage(ContextPage),
ToggleContextDrawer,
ToggleDialogPage(DialogPage),
AppTheme(usize),
FetchAvailableColorSchemes(ColorSchemeProvider, usize),
Expand Down Expand Up @@ -182,7 +183,7 @@ impl Application for TweakTool {
),
(fl!("repository"), "https://github.com/cosmic-utils/tweaks"),
])
.developers([("Eduardo Flores".into(), "edfloreshz@proton.me".into())]);
.developers([("Eduardo Flores", "edfloreshz@proton.me")]);

let mut app = TweakTool {
core,
Expand Down Expand Up @@ -269,14 +270,19 @@ impl Application for TweakTool {
Task::batch(vec![self.set_window_title(title, win_id)])
}

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

Some(match self.context_page {
ContextPage::About => widget::about(&self.about, Message::Open),
ContextPage::Settings => self.settings(),
ContextPage::About => {
app::context_drawer::about(&self.about, Message::Open, Message::ToggleContextDrawer)
}
ContextPage::Settings => {
app::context_drawer::context_drawer(self.settings(), Message::ToggleContextDrawer)
.title(self.context_page.title())
}
})
}

Expand Down Expand Up @@ -420,7 +426,7 @@ impl Application for TweakTool {
};
}

let mut commands = vec![];
let mut tasks = vec![];
match message {
Message::Open(url) => {
if let Err(err) = open::that_detached(url) {
Expand All @@ -437,7 +443,7 @@ impl Application for TweakTool {
self.offset += self.limit;
let limit = self.limit;
let offset = self.offset;
commands.push(Task::perform(
tasks.push(Task::perform(
async move {
let url = match provider {
ColorSchemeProvider::CosmicThemes => {
Expand Down Expand Up @@ -479,40 +485,42 @@ impl Application for TweakTool {
if self.context_page == page {
self.core.window.show_context = !self.core.window.show_context;
} else {
self.context_page = page.clone();
self.context_page = page;
self.core.window.show_context = true;
}
self.set_context_title(page.clone().title());
}
Message::ToggleContextDrawer => {
self.core.window.show_context = !self.core.window.show_context;
}
Message::Dock(message) => {
commands.push(self.dock.update(message).map(cosmic::app::Message::App))
tasks.push(self.dock.update(message).map(cosmic::app::Message::App))
}
Message::Panel(message) => {
commands.push(self.panel.update(message).map(cosmic::app::Message::App))
tasks.push(self.panel.update(message).map(cosmic::app::Message::App))
}
Message::Layouts(message) => {
tasks.push(self.layouts.update(message).map(cosmic::app::Message::App))
}
Message::Layouts(message) => match message {
_ => commands.push(self.layouts.update(message).map(cosmic::app::Message::App)),
},
Message::Snapshots(message) => match message {
pages::snapshots::Message::OpenSaveDialog => commands.push(self.update(
pages::snapshots::Message::OpenSaveDialog => tasks.push(self.update(
Message::ToggleDialogPage(DialogPage::CreateSnapshot(String::new())),
)),
_ => commands.push(
_ => tasks.push(
self.snapshots
.update(message)
.map(cosmic::app::Message::App),
),
},
Message::ColorSchemes(message) => match *message {
pages::color_schemes::Message::SaveCurrentColorScheme(None) => {
commands.push(self.update(Message::ToggleDialogPage(
tasks.push(self.update(Message::ToggleDialogPage(
DialogPage::SaveCurrentColorScheme(String::new()),
)))
}
pages::color_schemes::Message::OpenAvailableThemes => commands.push(
pages::color_schemes::Message::OpenAvailableThemes => tasks.push(
self.update(Message::ToggleDialogPage(DialogPage::AvailableColorSchemes)),
),
_ => commands.push(
_ => tasks.push(
self.color_schemes
.update(*message)
.map(Box::new)
Expand All @@ -521,13 +529,13 @@ impl Application for TweakTool {
),
},
Message::SaveNewColorScheme(name) => {
commands.push(self.update(Message::ColorSchemes(Box::new(
tasks.push(self.update(Message::ColorSchemes(Box::new(
pages::color_schemes::Message::SaveCurrentColorScheme(Some(name)),
))))
}
Message::ToggleDialogPage(dialog_page) => {
self.dialog_pages.push_back(dialog_page);
commands.push(widget::text_input::focus(self.dialog_text_input.clone()));
tasks.push(widget::text_input::focus(self.dialog_text_input.clone()));
}
Message::DialogUpdate(dialog_page) => {
self.dialog_pages[0] = dialog_page;
Expand All @@ -536,10 +544,10 @@ impl Application for TweakTool {
if let Some(dialog_page) = self.dialog_pages.pop_front() {
match dialog_page {
DialogPage::SaveCurrentColorScheme(name) => {
commands.push(self.update(Message::SaveNewColorScheme(name)))
tasks.push(self.update(Message::SaveNewColorScheme(name)))
}
DialogPage::CreateSnapshot(name) => {
commands.push(self.update(Message::Snapshots(
tasks.push(self.update(Message::Snapshots(
pages::snapshots::Message::CreateSnapshot(name, SnapshotKind::User),
)))
}
Expand All @@ -561,10 +569,10 @@ impl Application for TweakTool {
self.modifiers = modifiers;
}
Message::SystemThemeModeChange => {
commands.push(self.update_config());
tasks.push(self.update_config());
}
}
Task::batch(commands)
Task::batch(tasks)
}

fn subscription(&self) -> cosmic::iced::Subscription<Self::Message> {
Expand Down
25 changes: 11 additions & 14 deletions src/pages/snapshots/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::path::PathBuf;
use std::{
fmt::Display,
path::{Path, PathBuf},
};

use crate::{app::TweakTool, fl};
use chrono::{NaiveDateTime, Utc};
Expand All @@ -9,18 +12,12 @@ use cosmic::{
use cosmic_ext_config_templates::Schema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, CosmicConfigEntry)]
#[derive(Debug, Serialize, Default, Clone, Deserialize, PartialEq, CosmicConfigEntry)]
#[version = 1]
pub struct SnapshotsConfig {
pub snapshots: Vec<Snapshot>,
}

impl Default for SnapshotsConfig {
fn default() -> Self {
Self { snapshots: vec![] }
}
}

impl SnapshotsConfig {
pub fn helper() -> Option<Config> {
Config::new(TweakTool::APP_ID, Self::VERSION).ok()
Expand Down Expand Up @@ -56,19 +53,19 @@ pub enum SnapshotKind {
User,
}

impl ToString for SnapshotKind {
fn to_string(&self) -> String {
impl Display for SnapshotKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::System => fl!("system"),
Self::User => fl!("user"),
Self::System => write!(f, "{}", fl!("system")),
Self::User => write!(f, "{}", fl!("user")),
}
}
}

impl Snapshot {
pub fn new(name: &str, path: &PathBuf, kind: SnapshotKind) -> Self {
pub fn new(name: &str, path: &Path, kind: SnapshotKind) -> Self {
let created = Utc::now().naive_local();
let path = path.join(&name).with_extension("ron");
let path = path.join(name).with_extension("ron");

Self {
name: name.to_string(),
Expand Down

0 comments on commit 42e3955

Please sign in to comment.