Skip to content

Commit 9bcff82

Browse files
committed
feat: initial support
1 parent 47c103b commit 9bcff82

File tree

14 files changed

+258
-77
lines changed

14 files changed

+258
-77
lines changed

Cargo.lock

Lines changed: 46 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
@@ -6,4 +6,5 @@ edition = "2024"
66
[dependencies]
77
anyhow = "1.0.99"
88
clap = { version = "4.5.47", features = ["derive"] }
9+
getrandom = "0.3.3"
910
thiserror = "2.0.16"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
An unnecessarily written in Rust app that changes Wine (classic) theme to match
88
KDE Breeze colors.
99

10-
Adapted from [Zeinok's Wine Breeze Theme Registry](https://gist.github.com/Zeinok/ceaf6ff204792dde0ae31e0199d89398).
10+
Inspired by [Zeinok's Wine Breeze Theme](https://gist.github.com/Zeinok/ceaf6ff204792dde0ae31e0199d89398).
11+
12+
![img](https://github.com/nouvist/wine-breeze/raw/assets/screenshot_1.png)

prototype/breeze_by_zeinok.reg

Lines changed: 0 additions & 34 deletions
This file was deleted.

prototype/theme.reg

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/foundation/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ impl Config {
4646

4747
if line.starts_with("[") {
4848
let cursor_next = line[1..line.len() - 1].trim();
49-
cursor = Some(cursor_next.to_owned());
50-
if !self.inner.contains_key(cursor_next) {
51-
self.inner
52-
.insert(cursor_next.to_owned(), Default::default());
49+
let next = cursor_next.replace("][", "->");
50+
cursor = Some(next.clone());
51+
if !self.inner.contains_key(&next) {
52+
self.inner.insert(next, Default::default());
5353
}
5454
continue;
5555
}

src/foundation/kdeglobals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn get_paths() -> Result<Vec<PathBuf>, io::Error> {
2828
Ok(result)
2929
}
3030

31-
pub fn get_config() -> Result<Config, io::Error> {
31+
pub fn parse_config() -> Result<Config, io::Error> {
3232
let mut config = Config::new();
3333
for path in get_paths()? {
3434
let file = File::open(path)?;

src/foundation/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
use std::fmt::{self, Write};
2+
3+
use thiserror::Error;
4+
15
pub mod config;
26
pub mod kdeglobals;
37
pub mod registry;
8+
9+
pub fn create_temporary_name(ext: &str) -> Result<String, NameError> {
10+
let mut buf = [0u8; 16];
11+
let mut name = String::with_capacity(13 + 16 * 2 + 1 + ext.len());
12+
getrandom::fill(&mut buf)?;
13+
14+
name.push_str("__winebreeze-");
15+
for byte in &buf {
16+
write!(&mut name, "{byte:02x}")?;
17+
}
18+
name.push('.');
19+
name.push_str(ext);
20+
21+
Ok(name)
22+
}
23+
24+
#[derive(Error, Debug)]
25+
pub enum NameError {
26+
#[error("Unable to create random buffer")]
27+
Random(getrandom::Error),
28+
#[error("Unable to format")]
29+
Format(fmt::Error),
30+
}
31+
32+
impl From<getrandom::Error> for NameError {
33+
fn from(value: getrandom::Error) -> Self {
34+
Self::Random(value)
35+
}
36+
}
37+
38+
impl From<fmt::Error> for NameError {
39+
fn from(value: fmt::Error) -> Self {
40+
Self::Format(value)
41+
}
42+
}

src/foundation/registry.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::collections::HashMap;
1+
use std::{borrow::Cow, collections::HashMap};
22

33
const SEPARATOR: [char; 2] = ['/', '\\'];
44

5+
#[repr(transparent)]
56
#[derive(Debug, PartialEq, Eq)]
67
pub struct HkeyPath {
78
inner: String,
@@ -74,10 +75,39 @@ impl AsRef<str> for HkeyPath {
7475
}
7576
}
7677

78+
#[derive(Debug)]
79+
pub enum HkeyData {
80+
Delete,
81+
String(String),
82+
Dword(u32),
83+
}
84+
85+
impl HkeyData {
86+
pub fn to_string(&self) -> String {
87+
match self {
88+
HkeyData::Delete => "-".to_owned(),
89+
HkeyData::String(it) => format!("{it:?}"),
90+
HkeyData::Dword(it) => format!("dword:{it:08x}"),
91+
}
92+
}
93+
}
94+
95+
impl From<String> for HkeyData {
96+
fn from(value: String) -> Self {
97+
Self::String(value)
98+
}
99+
}
100+
101+
impl From<u32> for HkeyData {
102+
fn from(value: u32) -> Self {
103+
Self::Dword(value)
104+
}
105+
}
106+
77107
#[derive(Debug)]
78108
pub struct Hkey {
79109
pub path: HkeyPath,
80-
pub content: HashMap<String, String>,
110+
pub content: HashMap<String, HkeyData>,
81111
}
82112

83113
#[repr(transparent)]
@@ -86,25 +116,28 @@ pub struct HkeyCollection(pub Vec<Hkey>);
86116

87117
impl HkeyCollection {
88118
pub fn to_string(&self) -> String {
89-
let mut vec = Vec::<&str>::new();
119+
let mut vec = Vec::<Cow<str>>::new();
90120

91-
vec.push("Windows Registry Editor Version 5.00\n\n");
92-
vec.push("; Generated by Wine Breeze\n\n");
121+
vec.push(Cow::Borrowed("Windows Registry Editor Version 5.00\n\n"));
122+
vec.push(Cow::Borrowed("; Generated by Wine Breeze\n\n"));
93123

94124
for item in &self.0 {
95125
if item.content.is_empty() {
96126
continue;
97127
}
98-
vec.push("[");
99-
vec.push(item.path.as_str());
100-
vec.push("]\n");
128+
129+
vec.push(Cow::Borrowed("\n["));
130+
vec.push(Cow::Borrowed(item.path.as_str()));
131+
vec.push(Cow::Borrowed("]\n"));
101132

102133
for (key, value) in &item.content {
103-
vec.push("\"");
104-
vec.push(key);
105-
vec.push("\"=");
106-
vec.push(value);
134+
vec.push(Cow::Owned(format!("{:?}", key)));
135+
vec.push(Cow::Borrowed("="));
136+
vec.push(Cow::Owned(value.to_string()));
137+
vec.push(Cow::Borrowed("\n"));
107138
}
139+
140+
vec.push(Cow::Borrowed("\n"));
108141
}
109142

110143
vec.concat()

src/main.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
use clap::Parser;
22

3-
use crate::foundation::{
4-
registry::{Hkey, HkeyCollection, HkeyPath},
3+
use crate::{
4+
foundation::{create_temporary_name, kdeglobals::parse_config, registry::HkeyCollection},
5+
theme::{create_classic_theme_registry, create_colors_registry, create_dark_mode_registry},
56
};
67

78
pub mod foundation;
9+
pub mod theme;
810

911
/// Breezify Wine with ease
1012
#[derive(Parser, Debug)]
1113
#[command(version, about)]
1214
struct App {}
1315

1416
fn main() {
15-
let colors = Hkey {
16-
path: HkeyPath::new("HKEY_CURRENT_USER/Control Panel/Colors"),
17-
content: [("ActiveBorder".to_owned(), "galon wkwkwk".to_owned())].into(),
18-
};
17+
let _name = create_temporary_name("reg").unwrap();
1918

20-
let jar = HkeyCollection(vec![colors]);
19+
let config = parse_config().unwrap();
20+
let jar = HkeyCollection(vec![
21+
create_classic_theme_registry(),
22+
create_dark_mode_registry(
23+
config
24+
.get("General", "ColorScheme")
25+
.map(|it| it.to_lowercase().contains("dark"))
26+
.unwrap_or_default(),
27+
),
28+
create_colors_registry(&config),
29+
]);
2130

2231
println!("{}", jar.to_string());
2332
}

0 commit comments

Comments
 (0)