Compare commits
No commits in common. "8693e109793a0f911de0618516fb16fd18e83f63" and "793ed4d730ef33e87810be88d1a79dc6276ca19e" have entirely different histories.
8693e10979
...
793ed4d730
173
Cargo.lock
generated
173
Cargo.lock
generated
|
@ -2,15 +2,6 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
|
@ -186,7 +177,6 @@ dependencies = [
|
|||
"chrono",
|
||||
"dim_sdk",
|
||||
"lazy_static",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -214,17 +204,12 @@ dependencies = [
|
|||
name = "dim"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
"chrono",
|
||||
"clap",
|
||||
"dlopen",
|
||||
"dlopen_derive",
|
||||
"env_logger",
|
||||
"libc",
|
||||
"log",
|
||||
"serde",
|
||||
"toml",
|
||||
"x11",
|
||||
]
|
||||
|
||||
|
@ -261,35 +246,6 @@ dependencies = [
|
|||
"syn 0.15.44",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"humantime",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "example_rust"
|
||||
version = "0.1.0"
|
||||
|
@ -298,24 +254,12 @@ dependencies = [
|
|||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.60"
|
||||
|
@ -339,16 +283,6 @@ dependencies = [
|
|||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.0"
|
||||
|
@ -385,12 +319,6 @@ version = "0.4.21"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
|
@ -448,64 +376,6 @@ dependencies = [
|
|||
"proc-macro2 1.0.85",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.203"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.203"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.85",
|
||||
"quote 1.0.36",
|
||||
"syn 2.0.66",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
|
@ -540,40 +410,6 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
|
@ -750,15 +586,6 @@ version = "0.52.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x11"
|
||||
version = "2.21.0"
|
||||
|
|
|
@ -7,15 +7,10 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.86"
|
||||
camino = "1.1.7"
|
||||
chrono = "0.4.38"
|
||||
clap = { version = "4.5.7", features = ["derive"] }
|
||||
dlopen = "0.1.8"
|
||||
dlopen_derive = "0.1.4"
|
||||
env_logger = "0.11.3"
|
||||
libc = "0.2.155"
|
||||
log = "0.4.21"
|
||||
serde = { version = "1.0.203", features = ["derive"] }
|
||||
toml = "0.8.14"
|
||||
x11 = { version = "2.21.0", features = ["xlib"] }
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
seperator=" | "
|
||||
|
||||
[plugins]
|
||||
blacklist=["example_c", "example_rust"]
|
||||
as_whitelist=false
|
||||
template=["counter", "battery", "clock"]
|
|
@ -1,6 +0,0 @@
|
|||
seperator=" | "
|
||||
|
||||
[plugins]
|
||||
blacklist=["example_c", "example_rust"]
|
||||
as_whitelist=false
|
||||
template=["counter", "battery", "clock"]
|
|
@ -1,17 +1,15 @@
|
|||
# Must match package name in Cargo.toml
|
||||
PLUGIN_NAME=battery
|
||||
# `target` or `debug`
|
||||
TYPE=target
|
||||
|
||||
|
||||
build: $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so
|
||||
@mkdir -p $(dir $@)
|
||||
cp $^ $@
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so
|
||||
cp $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so:
|
||||
@mkdir -p $(dir $@)
|
||||
cargo build --release --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so:
|
||||
mkdir -p $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
cargo build --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
# Must match package name in Cargo.toml
|
||||
PLUGIN_NAME=clock
|
||||
# `target` or `debug`
|
||||
TYPE=target
|
||||
|
||||
|
||||
build: $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so
|
||||
@mkdir -p $(dir $@)
|
||||
cp $^ $@
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so
|
||||
cp $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so:
|
||||
@mkdir -p $(dir $@)
|
||||
cargo build --release --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so:
|
||||
mkdir -p $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
cargo build --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
# Must match package name in Cargo.toml
|
||||
PLUGIN_NAME=counter
|
||||
# `target` or `debug`
|
||||
TYPE=target
|
||||
|
||||
|
||||
build: $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so
|
||||
@mkdir -p $(dir $@)
|
||||
cp $^ $@
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so
|
||||
cp $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so:
|
||||
@mkdir -p $(dir $@)
|
||||
cargo build --release --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so:
|
||||
mkdir -p $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
cargo build --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
# Must match package name in Cargo.toml
|
||||
PLUGIN_NAME=example_rust
|
||||
# `target` or `debug`
|
||||
TYPE=target
|
||||
|
||||
|
||||
build: $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so
|
||||
@mkdir -p $(dir $@)
|
||||
cp $^ $@
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so
|
||||
cp $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/$(TYPE)/lib$(PLUGIN_NAME).so:
|
||||
@mkdir -p $(dir $@)
|
||||
cargo build --release --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so:
|
||||
mkdir -p $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
cargo build --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
nightly
|
|
@ -1,55 +0,0 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
pub seperator: String,
|
||||
pub plugins: ConfigPlugins,
|
||||
|
||||
#[serde(skip)]
|
||||
pub config_dir: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct ConfigPlugins {
|
||||
pub blacklist: Vec<String>,
|
||||
pub as_whitelist: bool,
|
||||
pub template: Vec<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(path: &Path) -> Result<Self, ConfigError> {
|
||||
let path = path.join("main.toml");
|
||||
|
||||
if !path.exists() {
|
||||
println!("ERROR: {:?} doesnt exist", path);
|
||||
}
|
||||
|
||||
let mut cfg: Self = toml::from_str(
|
||||
&std::fs::read_to_string(&path)?
|
||||
)?;
|
||||
|
||||
cfg.config_dir = path.to_path_buf();
|
||||
Ok(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
IoError(std::io::Error),
|
||||
TomlDeserialiseError(toml::de::Error)
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ConfigError {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Self::IoError(e)
|
||||
}
|
||||
}
|
||||
impl From<toml::de::Error> for ConfigError {
|
||||
fn from(e: toml::de::Error) -> Self {
|
||||
Self::TomlDeserialiseError(e)
|
||||
}
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
use std::{collections::HashMap, ffi::{CString, NulError}};
|
||||
use std::ffi::{CString, NulError};
|
||||
|
||||
use x11::xlib;
|
||||
|
||||
use crate::{config::Config, plugman::PolledText};
|
||||
|
||||
|
||||
|
||||
pub struct Display {
|
||||
|
@ -18,7 +16,7 @@ impl Display {
|
|||
let display = xlib::XOpenDisplay(std::ptr::null());
|
||||
|
||||
if display.is_null() {
|
||||
log::error!("Could not open x11 display");
|
||||
eprintln!("ERROR: Could not open x11 display");
|
||||
return Err(());
|
||||
}
|
||||
|
||||
|
@ -43,63 +41,4 @@ impl Display {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_with_vec(&mut self, cfg: &Config, v: HashMap<String, PolledText>) -> Result<(), NulError> {
|
||||
let mut buf = Vec::new();
|
||||
|
||||
let mut v = if cfg.plugins.as_whitelist {
|
||||
let mut vv = HashMap::new();
|
||||
for (n, pt) in v {
|
||||
if cfg.plugins.blacklist.contains(&n) {
|
||||
vv.insert(n, pt);
|
||||
}
|
||||
}
|
||||
vv
|
||||
} else {
|
||||
let mut vv = HashMap::new();
|
||||
for (n, pt) in v {
|
||||
if !cfg.plugins.blacklist.contains(&n) {
|
||||
vv.insert(n, pt);
|
||||
}
|
||||
}
|
||||
vv
|
||||
};
|
||||
|
||||
let mut used_values = Vec::new();
|
||||
for tv in &cfg.plugins.template {
|
||||
let mut found = false;
|
||||
for (pname, pt) in &v {
|
||||
if *pname == *tv {
|
||||
if !pt.disabled() {
|
||||
buf.push(pt.text().clone());
|
||||
}
|
||||
|
||||
used_values.push(pname.clone());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
log::warn!("Plugin '{}' was not found even though it was included in the template", tv);
|
||||
}
|
||||
}
|
||||
|
||||
for val in used_values {
|
||||
v.remove(&val);
|
||||
}
|
||||
|
||||
let mut kv: Vec<(&String, &PolledText)> = v.iter().collect();
|
||||
kv.sort_by(|a, b| a.0.cmp(b.0));
|
||||
|
||||
for (_, pt) in &kv {
|
||||
buf.push(pt.text().clone());
|
||||
}
|
||||
|
||||
let text = buf.join(&cfg.seperator);
|
||||
|
||||
self.write_display_name(&text)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
55
src/main.rs
55
src/main.rs
|
@ -1,69 +1,40 @@
|
|||
#![allow(internal_features)]
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
use std::{process::ExitCode, time::Duration};
|
||||
use std::{path::PathBuf, process::ExitCode, time::Duration};
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
mod display;
|
||||
mod plugman;
|
||||
mod config;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct CliArgs {
|
||||
#[arg(long, short, default_value="./plugins")]
|
||||
pub plugin_dir: camino::Utf8PathBuf,
|
||||
#[arg(long, short, default_value="./config")]
|
||||
pub config_dir: camino::Utf8PathBuf,
|
||||
#[arg(long, short)]
|
||||
pub debug: bool
|
||||
plugin_dir: camino::Utf8PathBuf,
|
||||
}
|
||||
|
||||
|
||||
// TODO: Clean up main function
|
||||
// TODO: Make ffi safe abstraction for logger
|
||||
// TODO: Set up ipc with unix sockets
|
||||
// TODO: Allow sending messages command -> running DIM instance -> plugin with ipc
|
||||
// TODO: Run code through clippy
|
||||
fn main() -> ExitCode {
|
||||
let ca = CliArgs::parse();
|
||||
|
||||
if ca.debug {
|
||||
env_logger::builder()
|
||||
.filter(None, log::LevelFilter::Debug)
|
||||
.init();
|
||||
} else {
|
||||
env_logger::builder()
|
||||
.filter(None, log::LevelFilter::Info)
|
||||
.init();
|
||||
}
|
||||
|
||||
let config;
|
||||
match config::Config::new(ca.config_dir.as_std_path()) {
|
||||
Ok(v) => config = v,
|
||||
Err(e) => {
|
||||
log::error!("Failed to parse config: {e:?}");
|
||||
return ExitCode::from(2);
|
||||
}
|
||||
};
|
||||
// let ca = CliArgs::parse();
|
||||
let Ok(mut disp) = display::Display::new() else {
|
||||
return ExitCode::from(1);
|
||||
};
|
||||
|
||||
|
||||
let mut pm = plugman::PlugMan::new(1024); // idk tbh
|
||||
if let Err(e) = pm.load(ca.plugin_dir.as_std_path().to_path_buf()){
|
||||
log::error!("Failed to load plugins: {e:?}");
|
||||
return ExitCode::from(3);
|
||||
if let Err(e) = pm.load(PathBuf::from("./plugins")
|
||||
//ca.plugin_dir.as_std_path().to_path_buf()
|
||||
){
|
||||
eprintln!("ERROR: Failed to load plugins: {e:?}");
|
||||
}
|
||||
|
||||
pm.init_plugins();
|
||||
|
||||
// TODO: Sort them from a config or something
|
||||
|
||||
loop {
|
||||
let vals = pm.poll_plugins();
|
||||
if let Err(e) = disp.write_with_vec(&config, vals) {
|
||||
log::warn!("Failed to write too bar: {e}");
|
||||
}
|
||||
let vals: Vec<String> = pm.poll_plugins().into_iter().map(|f| f.1).collect();
|
||||
|
||||
|
||||
let _ = disp.write_display_name(&vals.join(" | "));
|
||||
std::thread::sleep(Duration::from_millis(250));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use self::plugin::Plugin;
|
||||
|
||||
|
@ -20,15 +20,13 @@ impl PlugMan {
|
|||
}
|
||||
|
||||
pub fn load(&mut self, dir: PathBuf) -> Result<(), PluginError>{
|
||||
log::debug!("Loading plugins from {:?}", dir);
|
||||
|
||||
let files = std::fs::read_dir(dir)?;
|
||||
|
||||
for file in files {
|
||||
let entry = file?;
|
||||
if entry.file_type()?.is_file() {
|
||||
let plugin = Plugin::load(entry.path().to_path_buf())?;
|
||||
log::info!("Loaded plugin '{}' ({}) licensed with {}",
|
||||
println!("INFO: Loaded plugin {} {} licensed with {}",
|
||||
plugin.name().clone(),
|
||||
plugin.version().clone().unwrap_or("None".to_string()),
|
||||
plugin.license().clone().unwrap_or("None".to_string())
|
||||
|
@ -39,12 +37,7 @@ impl PlugMan {
|
|||
self.load(entry.path().to_path_buf())?;
|
||||
}
|
||||
}
|
||||
if self.plugins.len() == 0 {
|
||||
log::error!("No plugins found");
|
||||
return Err(PluginError::NoPlugins);
|
||||
}
|
||||
|
||||
log::info!("Loaded {} plugins", self.plugins.len());
|
||||
println!("INFO: Loaded {} plugins", self.plugins.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -59,7 +52,7 @@ impl PlugMan {
|
|||
pub fn reload_plugins(&mut self) {
|
||||
for plugin in &mut self.plugins {
|
||||
if let Err(e) = plugin.reload() {
|
||||
log::error!("Failed to reload plugin {:?}: {e}", plugin.name());
|
||||
eprintln!("ERROR: Failed to reload plugin {:?}: {e}", plugin.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +64,8 @@ impl PlugMan {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn poll_plugins(&mut self) -> HashMap<String, PolledText> {
|
||||
let mut answers = HashMap::new();
|
||||
pub fn poll_plugins(&mut self) -> Vec<(String, String)> {
|
||||
let mut answers = Vec::new();
|
||||
let len = self.len_cap / self.plugins.len();
|
||||
for plugin in &self.plugins {
|
||||
if !plugin.enabled() {
|
||||
|
@ -80,15 +73,11 @@ impl PlugMan {
|
|||
}
|
||||
match plugin.poll(len) {
|
||||
Ok(v) => {
|
||||
let mut pth = (plugin.name().clone(), PolledText::new(v));
|
||||
if pth.1.text().is_empty() {
|
||||
pth.1.disable()
|
||||
if !v.is_empty() {
|
||||
answers.push((plugin.name().clone(), v));
|
||||
}
|
||||
|
||||
|
||||
answers.insert(pth.0, pth.1);
|
||||
},
|
||||
Err(e) => log::error!("Failed to poll plugin: {e}"),
|
||||
Err(e) => eprintln!("Failed to poll plugin: {e}"),
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,32 +85,10 @@ impl PlugMan {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PolledText {
|
||||
text: String,
|
||||
disabled: bool
|
||||
}
|
||||
|
||||
impl PolledText {
|
||||
pub fn new(text: String) -> Self {
|
||||
Self { text, disabled: false }
|
||||
}
|
||||
pub fn text(&self) -> &String {
|
||||
&self.text
|
||||
}
|
||||
pub fn disabled(&self) -> bool {
|
||||
self.disabled
|
||||
}
|
||||
pub fn disable(&mut self) {
|
||||
self.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PluginError {
|
||||
DlOpenError,
|
||||
IoError,
|
||||
NoPlugins
|
||||
IoError
|
||||
}
|
||||
|
||||
impl From<dlopen::Error> for PluginError {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{alloc::Layout, ffi::{c_char, CStr}, path::PathBuf};
|
||||
use std::{alloc::Layout, ffi::{c_char, c_uint, CStr, CString}, path::PathBuf};
|
||||
|
||||
use dlopen::raw::Library;
|
||||
|
||||
|
@ -38,7 +38,7 @@ impl Plugin {
|
|||
}
|
||||
|
||||
fn reload_symbols(&mut self) -> Result<(), dlopen::Error> {
|
||||
log::debug!("Loading {:?}", self.path);
|
||||
println!("INFO: Loading {:?}", self.path);
|
||||
let lib = Library::open(&self.path)?;
|
||||
let symbols = PluginSyms {
|
||||
init: unsafe { lib.symbol("plug_init")? },
|
||||
|
@ -51,13 +51,14 @@ impl Plugin {
|
|||
};
|
||||
unsafe {
|
||||
if (symbols.get_info)().is_null() {
|
||||
log::error!("Info fields for plugin {:?} are null", self.path);
|
||||
eprintln!("ERROR: Info fields for plugin {:?} are null", self.path);
|
||||
self.disable();
|
||||
}
|
||||
}
|
||||
|
||||
self.syms = Some(symbols);
|
||||
self.lib = Some(lib);
|
||||
println!("INFO: Loading OK");
|
||||
Ok(())
|
||||
}
|
||||
pub fn syms(&self) -> PluginSyms {
|
||||
|
@ -96,9 +97,7 @@ impl Plugin {
|
|||
String::from_raw_parts(buf, len, cap)
|
||||
};
|
||||
|
||||
if !s.is_empty() {
|
||||
log::debug!("Polled: {}", s);
|
||||
}
|
||||
println!("Polled: {}", s);
|
||||
Ok(s)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user