Skip to content

Commit d32f8a1

Browse files
Max Verevkinammgws
authored andcommitted
fix loading theme form file
1 parent ea956ce commit d32f8a1

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

src/themes.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,49 @@ impl Default for Theme {
247247
}
248248
}
249249

250+
#[derive(Deserialize, Debug, Clone)]
251+
pub struct ThemeFromFile {
252+
pub native_separators: Option<bool>,
253+
pub idle_bg: Option<String>,
254+
pub idle_fg: Option<String>,
255+
pub info_bg: Option<String>,
256+
pub info_fg: Option<String>,
257+
pub good_bg: Option<String>,
258+
pub good_fg: Option<String>,
259+
pub warning_bg: Option<String>,
260+
pub warning_fg: Option<String>,
261+
pub critical_bg: Option<String>,
262+
pub critical_fg: Option<String>,
263+
pub separator: String,
264+
pub separator_bg: Option<String>,
265+
pub separator_fg: Option<String>,
266+
pub alternating_tint_bg: Option<String>,
267+
pub alternating_tint_fg: Option<String>,
268+
}
269+
270+
impl Into<Theme> for ThemeFromFile {
271+
fn into(self) -> Theme {
272+
Theme {
273+
native_separators: self.native_separators,
274+
idle_bg: self.idle_bg,
275+
idle_fg: self.idle_fg,
276+
info_bg: self.info_bg,
277+
info_fg: self.info_fg,
278+
good_bg: self.good_bg,
279+
good_fg: self.good_fg,
280+
warning_bg: self.warning_bg,
281+
warning_fg: self.warning_fg,
282+
critical_bg: self.critical_bg,
283+
critical_fg: self.critical_fg,
284+
separator: self.separator,
285+
separator_bg: self.separator_bg,
286+
separator_fg: self.separator_fg,
287+
alternating_tint_bg: self.alternating_tint_bg,
288+
alternating_tint_fg: self.alternating_tint_fg,
289+
}
290+
}
291+
}
292+
250293
impl Theme {
251294
pub fn from_name(name: &str) -> Option<Theme> {
252295
match name {
@@ -272,15 +315,17 @@ impl Theme {
272315
.join(file);
273316
let share_path = Path::new(util::USR_SHARE_PATH).join("themes").join(file);
274317

275-
if full_path.exists() {
318+
let theme: Option<ThemeFromFile> = if full_path.exists() {
276319
util::deserialize_file(&full_path).ok()
277320
} else if xdg_path.exists() {
278321
util::deserialize_file(&xdg_path).ok()
279322
} else if share_path.exists() {
280323
util::deserialize_file(&share_path).ok()
281324
} else {
282325
None
283-
}
326+
};
327+
328+
theme.map(|theme| theme.into())
284329
}
285330
}
286331

0 commit comments

Comments
 (0)