Skip to content

Commit 27518f8

Browse files
edfloreshzEduardo Flores
authored and
Eduardo Flores
committed
improv: add snapshots
1 parent fc2f7eb commit 27518f8

12 files changed

+314
-18
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ron = "0.8.1"
1717
rust-embed = "8.3.0"
1818
paste = "1.0"
1919
anyhow = "1.0.91"
20+
chrono = { version = "0.4.38", features = ["serde"] }
2021

2122
[dependencies.libcosmic]
2223
git = "https://github.com/pop-os/libcosmic.git"

i18n/en/cosmic_ext_tweaks.ftl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
app-title = Tweaks for COSMIC
22
app-description = A tool to customize your COSMIC desktop experience.
33
4+
# Pages
45
home = Home
56
dock = Dock
67
panel = Panel
78
layouts = Layouts
89
color-schemes = Color schemes
10+
snapshots = Snapshots
11+
912
color-schemes-error = Error loading color schemes
1013
import-color-scheme = Import color scheme
1114
delete-color-scheme = Delete color scheme
@@ -36,8 +39,18 @@ spacing-description = Spacing is the space between the icons in the dock or pane
3639
save = Save
3740
cancel = Cancel
3841
close = Close
42+
create = Create
43+
3944
save-current-color-scheme = Save current color scheme
45+
4046
save-current-layout = Save current layout
47+
48+
create-snapshot = Create snapshot
49+
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.
50+
restore-snapshot = Restore snapshot
51+
delete-snapshot = Delete snapshot
52+
no-snapshots = No snapshots available
53+
4154
color-scheme-name = Color scheme name
4255
4356
## About
Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Loading

src/app.rs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ use key_bind::key_binds;
2323
use pages::color_schemes::providers::cosmic_themes::CosmicTheme;
2424

2525
use crate::{
26-
core::nav::NavPage,
26+
core::nav::Page,
2727
fl,
2828
pages::{
2929
self,
3030
color_schemes::{config::ColorScheme, preview, ColorSchemeProvider, ColorSchemes},
3131
layouts::Layouts,
32+
snapshots::Snapshots,
3233
},
3334
settings::{AppTheme, TweaksSettings, CONFIG_VERSION},
3435
};
@@ -45,6 +46,7 @@ pub struct TweakTool {
4546
modifiers: Modifiers,
4647
color_schemes: ColorSchemes,
4748
layouts: Layouts,
49+
snapshots: Snapshots,
4850
context_page: ContextPage,
4951
app_themes: Vec<String>,
5052
config_handler: Option<cosmic_config::Config>,
@@ -65,6 +67,7 @@ pub enum Status {
6567
pub enum DialogPage {
6668
SaveCurrentColorScheme(String),
6769
SaveCurrentLayout(String),
70+
CreateSnapshot,
6871
AvailableColorSchemes,
6972
}
7073

@@ -73,6 +76,7 @@ pub enum Message {
7376
Dock(pages::dock::Message),
7477
Panel(pages::panel::Message),
7578
Layouts(pages::layouts::Message),
79+
Snapshots(pages::snapshots::Message),
7680
ColorSchemes(Box<pages::color_schemes::Message>),
7781
DialogUpdate(DialogPage),
7882
DialogComplete,
@@ -177,7 +181,7 @@ impl Application for TweakTool {
177181
return Task::none();
178182
};
179183

180-
let title = if let Some(page) = self.nav_model.data::<NavPage>(id) {
184+
let title = if let Some(page) = self.nav_model.data::<Page>(id) {
181185
format!("{} - {}", page.title(), fl!("app-title"))
182186
} else {
183187
fl!("app-title")
@@ -228,7 +232,7 @@ impl Application for TweakTool {
228232
.spacing(spacing.space_xxs),
229233
)
230234
}
231-
DialogPage::SaveCurrentLayout(name) => widget::dialog(fl!("save-current-color-scheme"))
235+
DialogPage::SaveCurrentLayout(name) => widget::dialog(fl!("save-current-layout"))
232236
.primary_action(
233237
widget::button::suggested(fl!("save"))
234238
.on_press_maybe(Some(Message::DialogComplete)),
@@ -248,6 +252,15 @@ impl Application for TweakTool {
248252
])
249253
.spacing(spacing.space_xxs),
250254
),
255+
DialogPage::CreateSnapshot => widget::dialog(fl!("create-snapshot"))
256+
.body(fl!("create-snapshot-description"))
257+
.primary_action(
258+
widget::button::suggested(fl!("create"))
259+
.on_press_maybe(Some(Message::DialogComplete)),
260+
)
261+
.secondary_action(
262+
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
263+
),
251264
DialogPage::AvailableColorSchemes => {
252265
let show_more_button: Option<Element<Message>> = match self.status {
253266
Status::Idle => Some(
@@ -289,15 +302,15 @@ impl Application for TweakTool {
289302
log::info!("Starting Cosmic Tweak Tool...");
290303

291304
let mut nav_model = segmented_button::SingleSelectModel::default();
292-
for &nav_page in NavPage::all() {
305+
for &nav_page in Page::all() {
293306
let id = nav_model
294307
.insert()
295308
.icon(nav_page.icon())
296309
.text(nav_page.title())
297-
.data::<NavPage>(nav_page)
310+
.data::<Page>(nav_page)
298311
.id();
299312

300-
if nav_page == NavPage::default() {
313+
if nav_page == Page::default() {
301314
nav_model.activate(id);
302315
}
303316
}
@@ -311,6 +324,7 @@ impl Application for TweakTool {
311324
modifiers: Modifiers::empty(),
312325
color_schemes: ColorSchemes::default(),
313326
layouts: Layouts::default(),
327+
snapshots: Snapshots::default(),
314328
context_page: ContextPage::About,
315329
app_themes: vec![fl!("match-desktop"), fl!("dark"), fl!("light")],
316330
config_handler: flags.config_handler,
@@ -336,17 +350,18 @@ impl Application for TweakTool {
336350
fn view(&self) -> Element<Self::Message> {
337351
let spacing = cosmic::theme::active().cosmic().spacing;
338352
let entity = self.nav_model.active();
339-
let nav_page = self.nav_model.data::<NavPage>(entity).unwrap_or_default();
353+
let nav_page = self.nav_model.data::<Page>(entity).unwrap_or_default();
340354

341355
let view = match nav_page {
342-
NavPage::ColorSchemes => self
356+
Page::ColorSchemes => self
343357
.color_schemes
344358
.view()
345359
.map(Box::new)
346360
.map(Message::ColorSchemes),
347-
NavPage::Dock => pages::dock::Dock::default().view().map(Message::Dock),
348-
NavPage::Panel => pages::panel::Panel::default().view().map(Message::Panel),
349-
NavPage::Layouts => self.layouts.view().map(Message::Layouts),
361+
Page::Dock => pages::dock::Dock::default().view().map(Message::Dock),
362+
Page::Panel => pages::panel::Panel::default().view().map(Message::Panel),
363+
Page::Layouts => self.layouts.view().map(Message::Layouts),
364+
Page::Snapshots => self.snapshots.view().map(Message::Snapshots),
350365
};
351366

352367
widget::column::with_children(vec![view])
@@ -466,6 +481,15 @@ impl Application for TweakTool {
466481
)),
467482
_ => commands.push(self.layouts.update(message).map(cosmic::app::Message::App)),
468483
},
484+
Message::Snapshots(message) => match message {
485+
pages::snapshots::Message::OpenSaveDialog => commands
486+
.push(self.update(Message::ToggleDialogPage(DialogPage::CreateSnapshot))),
487+
_ => commands.push(
488+
self.snapshots
489+
.update(message)
490+
.map(cosmic::app::Message::App),
491+
),
492+
},
469493
Message::ColorSchemes(message) => match *message {
470494
pages::color_schemes::Message::SaveCurrentColorScheme(None) => {
471495
commands.push(self.update(Message::ToggleDialogPage(
@@ -507,6 +531,9 @@ impl Application for TweakTool {
507531
DialogPage::SaveCurrentLayout(name) => {
508532
commands.push(self.update(Message::SaveNewLayout(name)))
509533
}
534+
DialogPage::CreateSnapshot => commands.push(self.update(
535+
Message::Snapshots(pages::snapshots::Message::CreateSnapshot),
536+
)),
510537
DialogPage::AvailableColorSchemes => (),
511538
}
512539
}

src/core/icons.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@ impl IconCache {
3333
);
3434
};
3535
}
36-
3736
bundle!("size-horizontally-symbolic", 18);
3837
bundle!("dock-bottom-symbolic", 18);
3938
bundle!("dock-top-symbolic", 18);
4039
bundle!("dark-mode-symbolic", 18);
4140
bundle!("resize-mode-symbolic", 18);
4241
bundle!("view-coverflow-symbolic", 18);
42+
bundle!("snapshots-symbolic", 18);
4343
bundle!("arrow-into-box-symbolic", 16);
4444
bundle!("document-save-symbolic", 16);
4545
bundle!("search-global-symbolic", 16);
46+
bundle!("list-add-symbolic", 16);
4647
bundle!("symbolic-link-symbolic", 14);
4748
bundle!("user-trash-symbolic", 14);
4849
bundle!("folder-download-symbolic", 14);
50+
bundle!("arrow-circular-bottom-right-symbolic", 14);
4951

5052
Self { cache }
5153
}

src/core/nav.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@ use crate::fl;
55
use super::icons;
66

77
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)]
8-
pub enum NavPage {
8+
pub enum Page {
99
#[default]
1010
ColorSchemes,
1111
Dock,
1212
Panel,
1313
Layouts,
14+
Snapshots,
1415
}
1516

16-
impl Default for &NavPage {
17+
impl Default for &Page {
1718
fn default() -> Self {
18-
&NavPage::ColorSchemes
19+
&Page::ColorSchemes
1920
}
2021
}
2122

22-
impl NavPage {
23+
impl Page {
2324
pub fn title(&self) -> String {
2425
match self {
2526
Self::ColorSchemes => fl!("color-schemes"),
2627
Self::Dock => fl!("dock"),
2728
Self::Panel => fl!("panel"),
2829
Self::Layouts => fl!("layouts"),
30+
Self::Snapshots => fl!("snapshots"),
2931
}
3032
}
3133

@@ -35,10 +37,17 @@ impl NavPage {
3537
Self::Dock => icons::get_icon("dock-bottom-symbolic", 18),
3638
Self::Panel => icons::get_icon("dock-top-symbolic", 18),
3739
Self::Layouts => icons::get_icon("view-coverflow-symbolic", 18),
40+
Self::Snapshots => icons::get_icon("snapshots-symbolic", 18),
3841
}
3942
}
4043

4144
pub fn all() -> &'static [Self] {
42-
&[Self::ColorSchemes, Self::Dock, Self::Panel, Self::Layouts]
45+
&[
46+
Self::ColorSchemes,
47+
Self::Dock,
48+
Self::Panel,
49+
Self::Layouts,
50+
Self::Snapshots,
51+
]
4352
}
4453
}

src/pages/layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Layouts {
8282
)
8383
.into(),
8484
])
85-
.spacing(spacing.space_s),
85+
.spacing(spacing.space_xs),
8686
)
8787
.into()
8888
}

src/pages/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod color_schemes;
22
pub mod dock;
33
pub mod layouts;
44
pub mod panel;
5+
pub mod snapshots;

0 commit comments

Comments
 (0)