Pi66

Home | Repos | About | Blog | Gaza

walrs
pywal but if its Fast-Minimal-Simple
git clone https://git.pi66.xyz/walrs

About | Files | Commits | Refs | License


fix some fix reload method

Author: pixel
Date: 2025-03-21 00:42
commit: 2329bab3

Stat

M src/create_templates.rs 2 +1 -1
M src/get_colors.rs 2 +1 -1
M src/main.rs 8 +3 -5
M src/reload.rs 15 +10 -5
A src/wallpaper.rs 1 +1 -0

Diff

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) } ...

Show all

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&#95;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&#95;cache&#95;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(&#38;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; }

// Created by Pi66

// Copyright ©Pi66 2026