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

Snapshots #47

Merged
merged 3 commits into from
Nov 6, 2024
Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ron = "0.8.1"
rust-embed = "8.3.0"
paste = "1.0"
anyhow = "1.0.91"
chrono = { version = "0.4.38", features = ["serde"] }

[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic.git"
Expand Down
20 changes: 20 additions & 0 deletions i18n/en/cosmic_ext_tweaks.ftl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
app-title = Tweaks for COSMIC
app-description = A tool to customize your COSMIC desktop experience.

# Pages
home = Home
dock = Dock
panel = Panel
layouts = Layouts
color-schemes = Color schemes
snapshots = Snapshots

color-schemes-error = Error loading color schemes
import-color-scheme = Import color scheme
delete-color-scheme = Delete color scheme
Expand Down Expand Up @@ -36,8 +39,25 @@ spacing-description = Spacing is the space between the icons in the dock or pane
save = Save
cancel = Cancel
close = Close
create = Create

save-current-color-scheme = Save current color scheme

save-current-layout = Save current layout

create-snapshot = Create snapshot
create-snapshot-description = You are about to create a snapshot, this will save the current state of your desktop and make it possible to restore it later on.
restore-snapshot = Restore snapshot
delete-snapshot = Delete snapshot
no-snapshots = No snapshots available
snapshot-name = Snapshot name
name = Name
type = Type
created = Created
actions = Actions
system = System
user = User

color-scheme-name = Color scheme name

## About
Expand Down
2 changes: 2 additions & 0 deletions res/icons/bundled/arrow-circular-bottom-right-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/icons/bundled/snapshots-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 52 additions & 36 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ use key_bind::key_binds;
use pages::color_schemes::providers::cosmic_themes::CosmicTheme;

use crate::{
core::nav::NavPage,
core::nav::Page,
fl,
pages::{
self,
color_schemes::{config::ColorScheme, preview, ColorSchemeProvider, ColorSchemes},
layouts::Layouts,
snapshots::{config::SnapshotKind, Snapshots},
},
settings::{AppTheme, TweaksSettings, CONFIG_VERSION},
};
Expand All @@ -45,6 +46,7 @@ pub struct TweakTool {
modifiers: Modifiers,
color_schemes: ColorSchemes,
layouts: Layouts,
snapshots: Snapshots,
context_page: ContextPage,
app_themes: Vec<String>,
config_handler: Option<cosmic_config::Config>,
Expand All @@ -64,7 +66,7 @@ pub enum Status {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum DialogPage {
SaveCurrentColorScheme(String),
SaveCurrentLayout(String),
CreateSnapshot(String),
AvailableColorSchemes,
}

Expand All @@ -73,6 +75,7 @@ pub enum Message {
Dock(pages::dock::Message),
Panel(pages::panel::Message),
Layouts(pages::layouts::Message),
Snapshots(pages::snapshots::Message),
ColorSchemes(Box<pages::color_schemes::Message>),
DialogUpdate(DialogPage),
DialogComplete,
Expand All @@ -87,7 +90,6 @@ pub enum Message {
Key(Modifiers, Key),
Modifiers(Modifiers),
SystemThemeModeChange,
SaveNewLayout(String),
}

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -177,7 +179,7 @@ impl Application for TweakTool {
return Task::none();
};

let title = if let Some(page) = self.nav_model.data::<NavPage>(id) {
let title = if let Some(page) = self.nav_model.data::<Page>(id) {
format!("{} - {}", page.title(), fl!("app-title"))
} else {
fl!("app-title")
Expand Down Expand Up @@ -223,30 +225,28 @@ impl Application for TweakTool {
.on_input(move |name| {
Message::DialogUpdate(DialogPage::SaveCurrentColorScheme(name))
})
.on_submit(Message::DialogComplete)
.into(),
])
.spacing(spacing.space_xxs),
)
}
DialogPage::SaveCurrentLayout(name) => widget::dialog(fl!("save-current-color-scheme"))
DialogPage::CreateSnapshot(name) => widget::dialog(fl!("create-snapshot"))
.body(fl!("create-snapshot-description"))
.primary_action(
widget::button::suggested(fl!("save"))
widget::button::suggested(fl!("create"))
.on_press_maybe(Some(Message::DialogComplete)),
)
.secondary_action(
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
)
.control(
widget::column::with_children(vec![
widget::text::body(fl!("color-scheme-name")).into(),
widget::text_input("", name.as_str())
.id(self.dialog_text_input.clone())
.on_input(move |name| {
Message::DialogUpdate(DialogPage::SaveCurrentLayout(name))
})
.into(),
])
.spacing(spacing.space_xxs),
widget::text_input(fl!("snapshot-name"), name.as_str())
.id(self.dialog_text_input.clone())
.on_input(move |name| {
Message::DialogUpdate(DialogPage::CreateSnapshot(name))
})
.on_submit(Message::DialogComplete),
),
DialogPage::AvailableColorSchemes => {
let show_more_button: Option<Element<Message>> = match self.status {
Expand Down Expand Up @@ -289,15 +289,15 @@ impl Application for TweakTool {
log::info!("Starting Cosmic Tweak Tool...");

let mut nav_model = segmented_button::SingleSelectModel::default();
for &nav_page in NavPage::all() {
for &nav_page in Page::all() {
let id = nav_model
.insert()
.icon(nav_page.icon())
.text(nav_page.title())
.data::<NavPage>(nav_page)
.data::<Page>(nav_page)
.id();

if nav_page == NavPage::default() {
if nav_page == Page::default() {
nav_model.activate(id);
}
}
Expand All @@ -311,6 +311,7 @@ impl Application for TweakTool {
modifiers: Modifiers::empty(),
color_schemes: ColorSchemes::default(),
layouts: Layouts::default(),
snapshots: Snapshots::default(),
context_page: ContextPage::About,
app_themes: vec![fl!("match-desktop"), fl!("dark"), fl!("light")],
config_handler: flags.config_handler,
Expand All @@ -321,10 +322,18 @@ impl Application for TweakTool {
offset: 0,
};

let mut tasks = vec![app.update(Message::FetchAvailableColorSchemes(
ColorSchemeProvider::CosmicThemes,
app.limit,
))];
let mut tasks = vec![
app.update(Message::FetchAvailableColorSchemes(
ColorSchemeProvider::CosmicThemes,
app.limit,
)),
app.update(Message::Snapshots(
pages::snapshots::Message::CreateSnapshot(
"Application opened".into(),
SnapshotKind::System,
),
)),
];

if let Some(id) = app.core.main_window_id() {
tasks.push(app.set_window_title(fl!("app-title"), id));
Expand All @@ -336,17 +345,18 @@ impl Application for TweakTool {
fn view(&self) -> Element<Self::Message> {
let spacing = cosmic::theme::active().cosmic().spacing;
let entity = self.nav_model.active();
let nav_page = self.nav_model.data::<NavPage>(entity).unwrap_or_default();
let nav_page = self.nav_model.data::<Page>(entity).unwrap_or_default();

let view = match nav_page {
NavPage::ColorSchemes => self
Page::ColorSchemes => self
.color_schemes
.view()
.map(Box::new)
.map(Message::ColorSchemes),
NavPage::Dock => pages::dock::Dock::default().view().map(Message::Dock),
NavPage::Panel => pages::panel::Panel::default().view().map(Message::Panel),
NavPage::Layouts => self.layouts.view().map(Message::Layouts),
Page::Dock => pages::dock::Dock::default().view().map(Message::Dock),
Page::Panel => pages::panel::Panel::default().view().map(Message::Panel),
Page::Layouts => self.layouts.view().map(Message::Layouts),
Page::Snapshots => self.snapshots.view().map(Message::Snapshots),
};

widget::column::with_children(vec![view])
Expand Down Expand Up @@ -461,11 +471,18 @@ impl Application for TweakTool {
.map(cosmic::app::Message::App),
),
Message::Layouts(message) => match message {
pages::layouts::Message::OpenSaveDialog => commands.push(self.update(
Message::ToggleDialogPage(DialogPage::SaveCurrentLayout(String::new())),
)),
_ => commands.push(self.layouts.update(message).map(cosmic::app::Message::App)),
},
Message::Snapshots(message) => match message {
pages::snapshots::Message::OpenSaveDialog => commands.push(self.update(
Message::ToggleDialogPage(DialogPage::CreateSnapshot(String::new())),
)),
_ => commands.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(
Expand All @@ -488,9 +505,6 @@ impl Application for TweakTool {
pages::color_schemes::Message::SaveCurrentColorScheme(Some(name)),
))))
}
Message::SaveNewLayout(name) => commands.push(self.update(Message::Layouts(
pages::layouts::Message::SaveCurrentLayout(name),
))),
Message::ToggleDialogPage(dialog_page) => {
self.dialog_pages.push_back(dialog_page);
commands.push(widget::text_input::focus(self.dialog_text_input.clone()));
Expand All @@ -504,8 +518,10 @@ impl Application for TweakTool {
DialogPage::SaveCurrentColorScheme(name) => {
commands.push(self.update(Message::SaveNewColorScheme(name)))
}
DialogPage::SaveCurrentLayout(name) => {
commands.push(self.update(Message::SaveNewLayout(name)))
DialogPage::CreateSnapshot(name) => {
commands.push(self.update(Message::Snapshots(
pages::snapshots::Message::CreateSnapshot(name, SnapshotKind::User),
)))
}
DialogPage::AvailableColorSchemes => (),
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ impl IconCache {
);
};
}

bundle!("size-horizontally-symbolic", 18);
bundle!("dock-bottom-symbolic", 18);
bundle!("dock-top-symbolic", 18);
bundle!("dark-mode-symbolic", 18);
bundle!("resize-mode-symbolic", 18);
bundle!("view-coverflow-symbolic", 18);
bundle!("snapshots-symbolic", 18);
bundle!("arrow-into-box-symbolic", 16);
bundle!("document-save-symbolic", 16);
bundle!("search-global-symbolic", 16);
bundle!("list-add-symbolic", 16);
bundle!("symbolic-link-symbolic", 14);
bundle!("user-trash-symbolic", 14);
bundle!("folder-download-symbolic", 14);
bundle!("arrow-circular-bottom-right-symbolic", 14);

Self { cache }
}
Expand Down
19 changes: 14 additions & 5 deletions src/core/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ use crate::fl;
use super::icons;

#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)]
pub enum NavPage {
pub enum Page {
#[default]
ColorSchemes,
Dock,
Panel,
Layouts,
Snapshots,
}

impl Default for &NavPage {
impl Default for &Page {
fn default() -> Self {
&NavPage::ColorSchemes
&Page::ColorSchemes
}
}

impl NavPage {
impl Page {
pub fn title(&self) -> String {
match self {
Self::ColorSchemes => fl!("color-schemes"),
Self::Dock => fl!("dock"),
Self::Panel => fl!("panel"),
Self::Layouts => fl!("layouts"),
Self::Snapshots => fl!("snapshots"),
}
}

Expand All @@ -35,10 +37,17 @@ impl NavPage {
Self::Dock => icons::get_icon("dock-bottom-symbolic", 18),
Self::Panel => icons::get_icon("dock-top-symbolic", 18),
Self::Layouts => icons::get_icon("view-coverflow-symbolic", 18),
Self::Snapshots => icons::get_icon("snapshots-symbolic", 18),
}
}

pub fn all() -> &'static [Self] {
&[Self::ColorSchemes, Self::Dock, Self::Panel, Self::Layouts]
&[
Self::ColorSchemes,
Self::Dock,
Self::Panel,
Self::Layouts,
Self::Snapshots,
]
}
}
Loading
Loading