Compare commits
28 Commits
feat/toml_
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b5c4bb351d | |||
| c73b85ed1b | |||
| 7c9ccc2e0f | |||
| e29e83e634 | |||
| 84ba411fbe | |||
| fc091a4870 | |||
| 5ce01ea9bd | |||
| c3ef702ba1 | |||
| 636e336f05 | |||
| 6b6fa96afb | |||
| 3fffee0007 | |||
| 5692ba91ba | |||
| 0b58ed9d22 | |||
| 6ed07fd329 | |||
| 04b46dc9c0 | |||
| 32d1d6ecb2 | |||
| d39dbbbe8b | |||
| 38d6be83dc | |||
| 93d5472dda | |||
| e3992f3bae | |||
| 3ac03329dd | |||
| 90639a9266 | |||
| 31b155f4dd | |||
| 2e4de7e411 | |||
| 244e80faf0 | |||
| 10b1d25316 | |||
| ae543de20c | |||
| 6f1137dc76 |
@ -4,26 +4,40 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- '*'
|
||||||
|
env:
|
||||||
|
CRATE_NAME: mycelium
|
||||||
|
RUST_BACKTRACE: 1
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: release
|
name: release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-24.04
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- os-name: Linux-x86_64
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
target: x86_64-unknown-linux-gnu
|
||||||
|
toolchain:
|
||||||
|
- stable
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@v4
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: apt-get update; apt-get install -y libdbus-1-3 libdbus-1-dev libdbus-1-3 pkg-config
|
run: |
|
||||||
|
apt-get update; apt-get install -y libdbus-1-3 libdbus-1-dev libdbus-1-3 pkg-config
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/inst_rustup.sh
|
||||||
|
bash /tmp/inst_rustup.sh -y
|
||||||
|
source /root/.cargo/env
|
||||||
|
rustup toolchain install stable-x86_64-unknown-linux-gnu
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
uses: houseabsolute/actions-rust-cross@v1
|
run: |
|
||||||
|
/root/.cargo/bin/cargo build --release
|
||||||
|
tar -zcvf x86_64-linux.tgz target/release/mycelium README.md
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
ls -alh target/release/mycelium
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
command: "build"
|
files: x86_64-linux.tgz
|
||||||
target: "x86_64-unknown-linux-gnu"
|
|
||||||
args: "--locked --release"
|
|
||||||
strip: true
|
|
||||||
- name: Publish artifacts and release
|
|
||||||
uses: houseabsolute/actions-rust-release@v0
|
|
||||||
with:
|
|
||||||
executable-name: "mycelium"
|
|
||||||
target: "x86_64-unknown-linux-gnu"
|
|
||||||
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
toml = "0.8"
|
configparser = "3.0.4"
|
||||||
dbus = "0.9.7"
|
dbus = "0.9.7"
|
||||||
glob = "0.3.1"
|
glob = "0.3.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|||||||
120
src/config.rs
120
src/config.rs
@ -1,28 +1,27 @@
|
|||||||
|
use configparser::ini::Ini;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use toml::Value;
|
|
||||||
|
|
||||||
use crate::enums::*;
|
use crate::enums::*;
|
||||||
|
use untildify;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Monitor {
|
pub struct Monitor {
|
||||||
pub monitor_type: MonitorType,
|
pub ratio: MonitorType,
|
||||||
|
pub index: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Monitor {
|
impl Monitor {
|
||||||
pub fn new(monitor_type: MonitorType) -> Monitor {
|
pub fn new(monitor_type: MonitorType, index: i64) -> Monitor {
|
||||||
Monitor {
|
Monitor {
|
||||||
monitor_type,
|
ratio: monitor_type,
|
||||||
|
index: index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display(&self) -> String {
|
|
||||||
format!("Monitor({:?})", self.monitor_type)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Monitor {
|
impl fmt::Display for Monitor {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{}", self.display())
|
write!(f, "{:?}", self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,11 +39,8 @@ impl Monitors {
|
|||||||
impl fmt::Display for Monitors {
|
impl fmt::Display for Monitors {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "[")?;
|
write!(f, "[")?;
|
||||||
for (i, v) in self.monitors.iter().enumerate() {
|
for v in &self.monitors {
|
||||||
if i > 0 {
|
write!(f, "{}, ", v)?;
|
||||||
write!(f, ", ")?;
|
|
||||||
}
|
|
||||||
write!(f, "{}", v.display())?;
|
|
||||||
}
|
}
|
||||||
write!(f, "]")
|
write!(f, "]")
|
||||||
}
|
}
|
||||||
@ -58,7 +54,7 @@ pub struct WallpaperDir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WallpaperDir {
|
impl WallpaperDir {
|
||||||
pub fn get(&self, monitor_type: &MonitorType) -> String {
|
pub fn get(&self, monitor_type: MonitorType) -> String {
|
||||||
match monitor_type {
|
match monitor_type {
|
||||||
MonitorType::Ultrawide => self.ultrawide.to_string(),
|
MonitorType::Ultrawide => self.ultrawide.to_string(),
|
||||||
MonitorType::Horizontal => self.horizontal.to_string(),
|
MonitorType::Horizontal => self.horizontal.to_string(),
|
||||||
@ -72,8 +68,10 @@ impl fmt::Display for WallpaperDir {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"ultrawide: {}, horizontal {}, vertical {}",
|
"ultrawide: {ultrawide}, horizontal {horizontal}, vertical {vertical}",
|
||||||
self.ultrawide, self.horizontal, self.vertical
|
ultrawide = self.ultrawide,
|
||||||
|
horizontal = self.horizontal,
|
||||||
|
vertical = self.vertical
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,84 +86,58 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn from_config(file_path: String) -> Config {
|
pub fn from_config(file_path: String) -> Config {
|
||||||
let toml_str = std::fs::read_to_string(&file_path).expect("Failed to read config file");
|
let mut config = Ini::new();
|
||||||
let value: Value = toml::from_str(&toml_str).expect("Failed to parse TOML config");
|
let map = config.load(file_path).unwrap();
|
||||||
|
|
||||||
// Get the general section
|
// Get the wallpaper engine and parse it
|
||||||
let general = value
|
let wallpaper_engine =
|
||||||
.get("general")
|
WallpaperHandler::new(config.get("general", "wallpaper_engine").unwrap());
|
||||||
.and_then(|g| g.as_table())
|
//
|
||||||
.expect("Missing [general] section in config");
|
|
||||||
|
|
||||||
// Get the wallpaper engine
|
// Get the wallpaper dirs and parse them
|
||||||
let wallpaper_engine_str = general
|
|
||||||
.get("wallpaper_engine")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.expect("Missing wallpaper_engine in [general] section");
|
|
||||||
let wallpaper_engine = WallpaperHandler::new(wallpaper_engine_str.to_string());
|
|
||||||
|
|
||||||
// Get the wallpaper dirs
|
|
||||||
let ultrawide_dir = general
|
|
||||||
.get("ultra_wall_dir")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(|s| untildify::untildify(s))
|
|
||||||
.expect("Missing ultra_wall_dir in [general] section");
|
|
||||||
let horizontal_dir = general
|
|
||||||
.get("hor_wall_dir")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(|s| untildify::untildify(s))
|
|
||||||
.expect("Missing hor_wall_dir in [general] section");
|
|
||||||
let vert_wall_dir = general
|
|
||||||
.get("vert_wall_dir")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(|s| untildify::untildify(s))
|
|
||||||
.expect("Missing vert_wall_dir in [general] section");
|
|
||||||
|
|
||||||
|
let ultrawide_dir =
|
||||||
|
untildify::untildify(config.get("general", "ultra_wall_dir").unwrap().as_ref());
|
||||||
|
let horizontal_dir =
|
||||||
|
untildify::untildify(config.get("general", "hor_wall_dir").unwrap().as_ref());
|
||||||
|
let vert_wall_dir =
|
||||||
|
untildify::untildify(config.get("general", "vert_wall_dir").unwrap().as_ref());
|
||||||
let wallpaper_dir = WallpaperDir {
|
let wallpaper_dir = WallpaperDir {
|
||||||
ultrawide: ultrawide_dir,
|
ultrawide: ultrawide_dir,
|
||||||
horizontal: horizontal_dir,
|
horizontal: horizontal_dir,
|
||||||
vertical: vert_wall_dir,
|
vertical: vert_wall_dir,
|
||||||
};
|
};
|
||||||
|
//
|
||||||
|
|
||||||
// Get the monitors section
|
// Get the Monitors and parse them
|
||||||
let monitors = general
|
|
||||||
.get("monitors")
|
|
||||||
.and_then(|m| m.as_array())
|
|
||||||
.expect("Missing [[monitors]] section in config");
|
|
||||||
|
|
||||||
let mut monitors_vec = Monitors {
|
let mut monitors = Monitors {
|
||||||
monitors: Vec::new(),
|
monitors: Vec::new(),
|
||||||
};
|
};
|
||||||
|
for mon in map.get("monitors").iter() {
|
||||||
for monitor_value in monitors {
|
for key in mon.keys() {
|
||||||
let monitor_type_str = monitor_value
|
let monitor = mon.get(key).unwrap().as_ref().unwrap();
|
||||||
.get("monitor_type")
|
// Add monitor type to Monitors vector
|
||||||
.and_then(|v| v.as_str())
|
monitors.add(Monitor::new(
|
||||||
.expect("Missing monitor_type in monitors array");
|
MonitorType::new(monitor.to_string()),
|
||||||
let monitor_type = MonitorType::new(monitor_type_str.to_string());
|
key.parse::<i64>()
|
||||||
|
.expect("Failed to parse int in motitor config"),
|
||||||
monitors_vec.add(Monitor::new(monitor_type));
|
));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
x_server: general
|
x_server: config.get("general", "x_server").unwrap(),
|
||||||
.get("x_server")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string(),
|
|
||||||
wallpaper_engine,
|
wallpaper_engine,
|
||||||
wallpaper_dir,
|
wallpaper_dir,
|
||||||
monitors: monitors_vec,
|
monitors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Config {
|
impl fmt::Display for Config {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(f, "Mycelium Config: X Server: {xserv}, Wallpaper Engine: {wallpaper_engine}, Wallpaper Directories: {wallpaper_dirs}, Monitors: {monitors}", xserv = self.x_server, wallpaper_engine = self.wallpaper_engine, wallpaper_dirs = self.wallpaper_dir, monitors = self.monitors)
|
||||||
f,
|
|
||||||
"Mycelium Config: X Server: {}, Wallpaper Engine: {}, Wallpaper Directories: {}, Monitors: {}",
|
|
||||||
self.x_server, self.wallpaper_engine, self.wallpaper_dir, self.monitors
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
// This code was autogenerated with `dbus-codegen-rust -g -m None -d org.kde.plasmashell -p /PlasmaShell`, see https://github.com/diwic/dbus-rs
|
// This code was autogenerated with `dbus-codegen-rust -g -m None -d org.kde.plasmashell -p /PlasmaShell`, see https://github.com/diwic/dbus-rs
|
||||||
use dbus;
|
use dbus;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
|
|||||||
@ -7,7 +7,7 @@ pub fn change_wallpapers(wallpapers: &Wallpapers) {
|
|||||||
command.arg("--no-fehbg").arg("--bg-fill");
|
command.arg("--no-fehbg").arg("--bg-fill");
|
||||||
|
|
||||||
for monitor in wallpapers.config.monitors.monitors.iter() {
|
for monitor in wallpapers.config.monitors.monitors.iter() {
|
||||||
command.arg(wallpapers.random_selection(&monitor.monitor_type).to_string());
|
command.arg(wallpapers.random_selection(&monitor.ratio).to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = command.output();
|
let result = command.output();
|
||||||
|
|||||||
@ -30,7 +30,7 @@ pub fn change_wallpapers(wallpapers: &Wallpapers) {
|
|||||||
pub fn generate_js(wallpapers: &Wallpapers) -> String {
|
pub fn generate_js(wallpapers: &Wallpapers) -> String {
|
||||||
let mut javascript = String::new();
|
let mut javascript = String::new();
|
||||||
javascript.push_str("var allDesktops = desktops();\n");
|
javascript.push_str("var allDesktops = desktops();\n");
|
||||||
for (count, monitor) in wallpapers.config.monitors.monitors.iter().enumerate() {
|
for (_count, monitor) in wallpapers.config.monitors.monitors.iter().enumerate() {
|
||||||
let mut boilerplate = String::new();
|
let mut boilerplate = String::new();
|
||||||
let _ = write!(
|
let _ = write!(
|
||||||
&mut boilerplate,
|
&mut boilerplate,
|
||||||
@ -39,8 +39,8 @@ pub fn generate_js(wallpapers: &Wallpapers) -> String {
|
|||||||
allDesktops[{0}].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
|
allDesktops[{0}].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
|
||||||
allDesktops[{0}].writeConfig('Image', 'file://{1}');
|
allDesktops[{0}].writeConfig('Image', 'file://{1}');
|
||||||
",
|
",
|
||||||
count,
|
monitor.index,
|
||||||
wallpapers.random_selection(&monitor.monitor_type)
|
wallpapers.random_selection(&monitor.ratio)
|
||||||
);
|
);
|
||||||
javascript.push_str(&boilerplate);
|
javascript.push_str(&boilerplate);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use untildify::untildify;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Load the config file from the default path
|
// Load the config file from the default path
|
||||||
let path = untildify("~/.config/wallpaperctl/wallpaperctl.toml");
|
let path = untildify("~/.config/wallpaperctl/wallpaperctl.ini");
|
||||||
let config = Config::from_config(path);
|
let config = Config::from_config(path);
|
||||||
|
|
||||||
// Initialise the `Wallpapers` struct with a clone of the config
|
// Initialise the `Wallpapers` struct with a clone of the config
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user