Skip to content

Commit 659854b

Browse files
committed
feat: basic cli
1 parent 9bcff82 commit 659854b

File tree

5 files changed

+63
-53
lines changed

5 files changed

+63
-53
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ edition = "2024"
77
anyhow = "1.0.99"
88
clap = { version = "4.5.47", features = ["derive"] }
99
getrandom = "0.3.3"
10-
thiserror = "2.0.16"

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
> This project is neither related to nor affiliated with the Wine or KDE
55
> projects.
66
7-
An unnecessarily written in Rust app that changes Wine (classic) theme to match
8-
KDE Breeze colors.
9-
107
Inspired by [Zeinok's Wine Breeze Theme](https://gist.github.com/Zeinok/ceaf6ff204792dde0ae31e0199d89398).
118

129
![img](https://github.com/nouvist/wine-breeze/raw/assets/screenshot_1.png)

src/foundation/mod.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
use std::fmt::{self, Write};
1+
use std::{env, fmt::Write, path::PathBuf};
22

3-
use thiserror::Error;
3+
use anyhow::{Result, anyhow};
44

55
pub mod config;
66
pub mod kdeglobals;
77
pub mod registry;
88

9-
pub fn create_temporary_name(ext: &str) -> Result<String, NameError> {
9+
pub fn get_prefix() -> Result<PathBuf> {
10+
env::var("WINEPREFIX")
11+
.map(|it| PathBuf::from(it))
12+
.or_else(|_| {
13+
env::home_dir()
14+
.ok_or(anyhow!("Home directory not found"))
15+
.map(|home| home.join(".wine"))
16+
})
17+
}
18+
19+
pub fn create_temporary_name(ext: &str) -> Result<String> {
1020
let mut buf = [0u8; 16];
1121
let mut name = String::with_capacity(13 + 16 * 2 + 1 + ext.len());
12-
getrandom::fill(&mut buf)?;
22+
getrandom::fill(&mut buf).map_err(|_| anyhow!("Unable to create random buffer"))?;
1323

1424
name.push_str("__winebreeze-");
1525
for byte in &buf {
@@ -20,23 +30,3 @@ pub fn create_temporary_name(ext: &str) -> Result<String, NameError> {
2030

2131
Ok(name)
2232
}
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/main.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
use std::{
2+
fs,
3+
path::PathBuf,
4+
process::{self, Command, Stdio},
5+
};
6+
7+
use anyhow::{Result, anyhow};
18
use clap::Parser;
29

310
use crate::{
4-
foundation::{create_temporary_name, kdeglobals::parse_config, registry::HkeyCollection},
11+
foundation::{
12+
create_temporary_name, get_prefix, kdeglobals::parse_config, registry::HkeyCollection,
13+
},
514
theme::{create_classic_theme_registry, create_colors_registry, create_dark_mode_registry},
615
};
716

@@ -11,11 +20,37 @@ pub mod theme;
1120
/// Breezify Wine with ease
1221
#[derive(Parser, Debug)]
1322
#[command(version, about)]
14-
struct App {}
23+
struct App {
24+
prefix: Option<PathBuf>,
25+
}
1526

1627
fn main() {
17-
let _name = create_temporary_name("reg").unwrap();
28+
match run(App::parse()) {
29+
Ok(code) => process::exit(code),
30+
Err(err) => {
31+
eprintln!("Error: {err}");
32+
process::exit(1);
33+
}
34+
}
35+
}
1836

37+
fn run(app: App) -> Result<i32> {
38+
let prefix = app
39+
.prefix
40+
.or_else(|| get_prefix().ok())
41+
.ok_or(anyhow!("Prefix can't be specified"))?;
42+
if !fs::exists(&prefix)? {
43+
return Err(anyhow!("Prefix does not exists"));
44+
}
45+
46+
let c = prefix.join("dosdevices/c:");
47+
if !fs::exists(&c)? {
48+
return Err(anyhow!("Wine is not initialized"));
49+
}
50+
51+
let name = c.join(
52+
create_temporary_name("reg").or_else(|_| Err(anyhow!("Can't generate temporary name")))?,
53+
);
1954
let config = parse_config().unwrap();
2055
let jar = HkeyCollection(vec![
2156
create_classic_theme_registry(),
@@ -28,5 +63,15 @@ fn main() {
2863
create_colors_registry(&config),
2964
]);
3065

31-
println!("{}", jar.to_string());
66+
fs::write(&name, jar.to_string())?;
67+
let status = Command::new("wine")
68+
.env("WINEPREFIX", prefix)
69+
.stdin(Stdio::inherit())
70+
.stdout(Stdio::inherit())
71+
.stderr(Stdio::inherit())
72+
.arg("regedit")
73+
.arg(&name)
74+
.status()?;
75+
76+
Ok(status.code().unwrap_or(0))
3277
}

0 commit comments

Comments
 (0)