1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 | diff --git a/src/create_templates.rs b/src/create_templates.rs
index 1b1c475..57255d6 100644
--- a/src/create_templates.rs
+++ b/src/create_templates.rs
@@ -105,7 +105,7 @@ fn fill_template(template_name: &str, template: &str, colors: &(Vec<(u8, u8, u8)
write(output_path, result).expect("Failed to write filled template");
}
-pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: String) {
+pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str) {
let system_template_path = "/etc/walrs/templates/";
let user_template_path = format!("{}/walrs/templates/", get_config_folder().unwrap());
let cache_path = format!("{}/wal/", get_cache_folder().unwrap());
diff --git a/src/get_colors.rs b/src/get_colors.rs
index e67c010..a71b0a3 100644
--- a/src/get_colors.rs
+++ b/src/get_colors.rs
@@ -36,7 +36,7 @@ fn generate_variation(color: (u8, u8, u8), offset: i16) -> (u8, u8, u8) {
adjust_rgb(color.0, color.1, color.2, offset, 50)
}
-pub fn get_colors(image_path: String,send:bool) -> (Vec<(u8,u8,u8)>,u8){
+pub fn get_colors(image_path: &str,send:bool) -> (Vec<(u8,u8,u8)>,u8){
let image = match image::open(image_path){
Ok(v) => v,
Err(_) => {warning("Image", "Unsupported or corrupted image format",send);exit(1)},
diff --git a/src/main.rs b/src/main.rs
index d146778..b8bd192 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,6 @@ mod reload;
mod wallpaper;
mod utils;
-use wallpaper::change_wallpaper;
use reload::reload;
use create_templates::create_template;
use get_colors::get_colors;
@@ -40,6 +39,7 @@ fn main() {
std::process::exit(1);
}
+
if arg.reload {
reload(!arg.quit);
exit(0);
@@ -63,14 +63,12 @@ fn main() {
}
};
- let palette = get_colors(image_path.clone(), !arg.quit);
+ let palette = get_colors(&image_path, !arg.quit);
info("Generate", "generate colors", !arg.quit);
- create_template(palette, image_path.clone());
+ create_template(palette, &image_path);
info("Template", "create templates", !arg.quit);
- change_wallpaper(&image_path.to_string(),!arg.quit);
-
reload(!arg.quit);
print_colors(!arg.quit);
diff --git a/src/reload.rs b/src/reload.rs
index cbcd4e2..e8fd680 100644
--- a/src/reload.rs
+++ b/src/reload.rs
@@ -1,10 +1,11 @@
-use std::fs::{File, read_dir};
-use std::io::{BufRead, BufReader};
+use std::fs::{read_dir, read_to_string};
use std::process::{Command, Stdio};
use std::fs::OpenOptions;
use std::io::Write;
use std::process::exit;
+use crate::wallpaper;
+
use crate::utils::{get_cache_folder,info,warning};
@@ -94,10 +95,11 @@ pub fn reload(send:bool) {
let cache = get_cache_folder().expect("Can't get cache path");
let file_path = format!("{}/wal/colors", cache);
- let lines: Vec<String> = BufReader::new(File::open(&file_path).expect("Can't load colors"))
+ let lines: Vec<String> = std::fs::read_to_string(&file_path)
+ .expect("Can't load colors")
.lines()
- .collect::<Result<_, _>>()
- .expect("Failed to read lines");
+ .map(|line| line.to_string())
+ .collect();
// Spawn threads
let cache = match get_cache_folder() {
@@ -106,6 +108,9 @@ pub fn reload(send:bool) {
};
+ let wallpaper = read_to_string(&format!("{}/wal/wal",cache)).expect("run 'cp /etc/walrs/templates/wal ~/.config/walrs/templates/' and restart app").lines().next().unwrap().trim().to_string();
+ println!("wal: '{}'", wallpaper.as_str());
+ wallpaper::change_wallpaper(wallpaper.as_str(),true);
colors(lines,send);
xrdb(&cache,send);
diff --git a/src/wallpaper.rs b/src/wallpaper.rs
index 26c5d05..64905bd 100644
--- a/src/wallpaper.rs
+++ b/src/wallpaper.rs
@@ -344,6 +344,7 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
pub fn change_wallpaper(img: &str, send: bool) {
if !Path::new(img).is_file() {
+ println!("asdf: {}",img);
warning("Wallpaper", "invalid image path", send);
return;
}
|