Skip to content

Commit b50dc7e

Browse files
committed
fix: more fixes
1 parent 5eddd19 commit b50dc7e

File tree

9 files changed

+48
-13
lines changed

9 files changed

+48
-13
lines changed

i18n/en/cosmic_initial_setup.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ next = Next
66
password = Password
77
password-confirm = Confirm Password
88
settings = Settings
9+
skip = Skip
910
skip-setup-and-close = Skip setup and close
1011
type-to-search = Type to search…
1112
wifi = Wi-Fi

src/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,18 @@ impl Application for App {
340340

341341
let page = &self.pages[self.page_i];
342342

343-
let skip_setup_and_close = page
344-
.skippable()
345-
.then(|| widget::button::link(fl!("skip-setup-and-close")).on_press(Message::Finish));
343+
let skip_button = page
344+
.optional()
345+
.then(|| widget::button::link(fl!("skip")).on_press(Message::PageOpen(self.page_i + 1)))
346+
.or_else(|| {
347+
page.skippable().then(|| {
348+
widget::button::link(fl!("skip-setup-and-close")).on_press(Message::Finish)
349+
})
350+
});
346351

347352
let mut button_row = widget::row::with_capacity(4)
348353
.spacing(space_xxs)
349-
.push_maybe(skip_setup_and_close)
354+
.push_maybe(skip_button)
350355
.push(widget::horizontal_space());
351356

352357
if let Some(page_i) = self.page_i.checked_sub(1) {

src/page/appearance.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ use crate::{fl, page};
1515
static COSMIC_DARK_SVG: &'static [u8] = include_bytes!("../../res/cosmic-dark.svg");
1616
static COSMIC_LIGHT_SVG: &'static [u8] = include_bytes!("../../res/cosmic-light.svg");
1717

18+
fn dark_icon() -> widget::svg::Handle {
19+
widget::svg::Handle::from_memory(COSMIC_DARK_SVG)
20+
}
21+
22+
fn light_icon() -> widget::svg::Handle {
23+
widget::svg::Handle::from_memory(COSMIC_LIGHT_SVG)
24+
}
25+
1826
struct Theme {
1927
name: String,
2028
builder: ThemeBuilder,
@@ -56,13 +64,13 @@ impl Page {
5664
let mut themes = vec![
5765
Theme {
5866
name: "COSMIC Dark".to_string(),
59-
handle: widget::svg::Handle::from_memory(COSMIC_DARK_SVG),
67+
handle: dark_icon(),
6068
builder: ThemeBuilder::dark(),
6169
is_dark: true,
6270
},
6371
Theme {
6472
name: "COSMIC Light".to_string(),
65-
handle: widget::svg::Handle::from_memory(COSMIC_LIGHT_SVG),
73+
handle: light_icon(),
6674
builder: ThemeBuilder::light(),
6775
is_dark: false,
6876
},
@@ -89,11 +97,12 @@ impl Page {
8997

9098
match ron::de::from_bytes::<ThemeBuilder>(&buffer[..read]) {
9199
Ok(builder) => {
100+
let is_dark = name.ends_with("dark");
92101
themes.push(Theme {
93102
name: name.replace('-', " ").to_title_case(),
94-
handle: widget::svg::Handle::from_memory(COSMIC_DARK_SVG),
103+
handle: if is_dark { dark_icon() } else { light_icon() },
95104
builder,
96-
is_dark: name.ends_with("dark"),
105+
is_dark,
97106
});
98107
}
99108

src/page/layout.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Layout {
2020
pub struct Page {
2121
locale: String,
2222
layouts: Vec<Layout>,
23-
selected: usize,
23+
selected: Option<usize>,
2424
}
2525

2626
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -39,7 +39,7 @@ impl Page {
3939
match message {
4040
Message::Selected(id) => {
4141
if let Some(layout) = self.layouts.get(id) {
42-
self.selected = id;
42+
self.selected = Some(id);
4343
apply_layout(&layout.path);
4444
}
4545
}
@@ -58,6 +58,10 @@ impl super::Page for Page {
5858
self
5959
}
6060

61+
fn skippable(&self) -> bool {
62+
true
63+
}
64+
6165
fn init(&mut self) -> cosmic::Task<super::Message> {
6266
let Ok(layouts_dir) = std::fs::read_dir("/usr/share/cosmic-layouts/") else {
6367
return cosmic::Task::none();
@@ -167,7 +171,7 @@ fn layout_button<'a>(
167171
locale: &str,
168172
layout: &'a Layout,
169173
id: usize,
170-
current: usize,
174+
current: Option<usize>,
171175
spacing: u16,
172176
) -> cosmic::Element<'a, super::Message> {
173177
let name = layout
@@ -186,7 +190,7 @@ fn layout_button<'a>(
186190

187191
let button = widget::button::custom_image_button(thumbnail, None)
188192
.class(cosmic::theme::Button::Image)
189-
.selected(current == id)
193+
.selected(current.map_or(false, |current| current == id))
190194
.on_press(Message::Selected(id).into());
191195

192196
widget::column::with_capacity(2)

src/page/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ pub trait Page {
135135
true
136136
}
137137

138+
fn optional(&self) -> bool {
139+
false
140+
}
141+
138142
fn skippable(&self) -> bool {
139143
false
140144
}

src/page/new_apps.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl super::Page for Page {
2424
self
2525
}
2626

27+
fn skippable(&self) -> bool {
28+
true
29+
}
30+
2731
fn view(&self) -> cosmic::Element<super::Message> {
2832
let cosmic_theme::Spacing { space_s, .. } = cosmic::theme::active().cosmic().spacing;
2933

src/page/new_shortcuts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl super::Page for Page {
2424
self
2525
}
2626

27+
fn skippable(&self) -> bool {
28+
true
29+
}
30+
2731
fn view(&self) -> cosmic::Element<super::Message> {
2832
let cosmic_theme::Spacing { space_s, .. } = cosmic::theme::active().cosmic().spacing;
2933

src/page/wifi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl super::Page for Page {
5050
connection_settings()
5151
}
5252

53-
fn skippable(&self) -> bool {
53+
fn optional(&self) -> bool {
5454
true
5555
}
5656

src/page/workflow.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl super::Page for Page {
2424
self
2525
}
2626

27+
fn skippable(&self) -> bool {
28+
true
29+
}
30+
2731
fn view(&self) -> cosmic::Element<super::Message> {
2832
let cosmic_theme::Spacing { space_xl, .. } = cosmic::theme::active().cosmic().spacing;
2933

0 commit comments

Comments
 (0)