- Replace configparser with toml crate - Refactor Monitor struct to hold MonitorType directly - Fix broken Monitor::Display implementation - Update wallpaper handlers to use new Monitor API - Change default config path to .toml - Suppress dead_code warnings on auto-generated D-Bus code
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
use crate::handlers::dbus_plasma_interface;
|
|
use crate::Wallpapers;
|
|
|
|
use dbus::blocking::Connection;
|
|
use std::fmt::Write as _;
|
|
use std::time::Duration;
|
|
|
|
pub fn change_wallpapers(wallpapers: &Wallpapers) {
|
|
// First open up a connection to the session bus
|
|
let conn = Connection::new_session().unwrap();
|
|
|
|
// Second, create a wrapper struct around the connection that makes it easy
|
|
// to send method calls to a specific destination and path.
|
|
let proxy = conn.with_proxy(
|
|
"org.kde.plasmashell",
|
|
"/PlasmaShell",
|
|
Duration::from_millis(5000),
|
|
);
|
|
|
|
use dbus_plasma_interface::OrgKdePlasmaShell;
|
|
|
|
let javascript = generate_js(wallpapers);
|
|
let resp = proxy.evaluate_script(javascript.as_ref());
|
|
match resp {
|
|
Ok(_str) => {}
|
|
Err(e) => println!("{}", e),
|
|
}
|
|
}
|
|
|
|
pub fn generate_js(wallpapers: &Wallpapers) -> String {
|
|
let mut javascript = String::new();
|
|
javascript.push_str("var allDesktops = desktops();\n");
|
|
for (count, monitor) in wallpapers.config.monitors.monitors.iter().enumerate() {
|
|
let mut boilerplate = String::new();
|
|
let _ = write!(
|
|
&mut boilerplate,
|
|
"
|
|
allDesktops[{0}].wallpaperPlugin = 'org.kde.image';
|
|
allDesktops[{0}].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
|
|
allDesktops[{0}].writeConfig('Image', 'file://{1}');
|
|
",
|
|
count,
|
|
wallpapers.random_selection(&monitor.monitor_type)
|
|
);
|
|
javascript.push_str(&boilerplate);
|
|
}
|
|
javascript
|
|
}
|