mirror of
https://github.com/2e3s/awatcher.git
synced 2025-07-22 01:50:03 +00:00
Add opening config to tray
This commit is contained in:
parent
cbcbfe4760
commit
665924d39e
104
Cargo.lock
generated
104
Cargo.lock
generated
@ -416,7 +416,7 @@ dependencies = [
|
||||
"fern",
|
||||
"gethostname 0.4.1",
|
||||
"jemallocator",
|
||||
"jni 0.20.0",
|
||||
"jni",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
@ -448,7 +448,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "awatcher"
|
||||
version = "0.0.4"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-compat",
|
||||
@ -460,12 +460,12 @@ dependencies = [
|
||||
"image",
|
||||
"ksni",
|
||||
"log",
|
||||
"open",
|
||||
"rust-embed",
|
||||
"signal-hook",
|
||||
"smol",
|
||||
"toml 0.7.3",
|
||||
"watchers",
|
||||
"webbrowser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1727,6 +1727,15 @@ version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
|
||||
|
||||
[[package]]
|
||||
name = "is-docker"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.6"
|
||||
@ -1739,6 +1748,16 @@ dependencies = [
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-wsl"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
|
||||
dependencies = [
|
||||
"is-docker",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.6"
|
||||
@ -1779,22 +1798,6 @@ dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni"
|
||||
version = "0.21.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97"
|
||||
dependencies = [
|
||||
"cesu8",
|
||||
"cfg-if 1.0.0",
|
||||
"combine",
|
||||
"jni-sys",
|
||||
"log",
|
||||
"thiserror",
|
||||
"walkdir",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni-sys"
|
||||
version = "0.3.0"
|
||||
@ -1944,15 +1947,6 @@ dependencies = [
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.1.0"
|
||||
@ -2122,12 +2116,6 @@ dependencies = [
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ndk-context"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.25.1"
|
||||
@ -2205,15 +2193,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
|
||||
dependencies = [
|
||||
"malloc_buf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.30.3"
|
||||
@ -2239,6 +2218,16 @@ version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "open"
|
||||
version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d16814a067484415fda653868c9be0ac5f2abd2ef5d951082a5f2fe1b3662944"
|
||||
dependencies = [
|
||||
"is-wsl",
|
||||
"pathdiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.48"
|
||||
@ -2339,6 +2328,12 @@ dependencies = [
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pathdiff"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
|
||||
|
||||
[[package]]
|
||||
name = "pear"
|
||||
version = "0.2.4"
|
||||
@ -2567,12 +2562,6 @@ dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw-window-handle"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.7.0"
|
||||
@ -3926,23 +3915,6 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webbrowser"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b692165700260bbd40fbc5ff23766c03e339fbaca907aeea5cb77bf0a553ca83"
|
||||
dependencies = [
|
||||
"core-foundation",
|
||||
"dirs 4.0.0",
|
||||
"jni 0.21.1",
|
||||
"log",
|
||||
"ndk-context",
|
||||
"objc",
|
||||
"raw-window-handle",
|
||||
"url",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "weezl"
|
||||
version = "0.1.7"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "awatcher"
|
||||
version = "0.0.4"
|
||||
version = "0.1.0"
|
||||
authors = ["Demmie <2e3s19@gmail.com>"]
|
||||
edition = "2021"
|
||||
license-file = "LICENSE"
|
||||
@ -35,14 +35,14 @@ aw-server = { git = "https://github.com/2e3s/aw-server-rust", optional = true, r
|
||||
aw-datastore = { git = "https://github.com/2e3s/aw-server-rust", optional = true, rev = "b967a56" }
|
||||
smol = {version = "1.3.0", optional = true }
|
||||
async-compat = { version = "0.2.1", optional = true }
|
||||
webbrowser = { version = "0.8.9", optional = true }
|
||||
open = { version = "4.1.0", optional = true }
|
||||
rust-embed = { version = "6.6.1", features = ["interpolate-folder-path"] }
|
||||
|
||||
[features]
|
||||
default = ["gnome", "kwin_window"]
|
||||
gnome = ["watchers/gnome"]
|
||||
kwin_window = ["watchers/kwin_window"]
|
||||
bundle = ["ksni", "smol", "async-compat", "aw-server", "aw-datastore", "webbrowser"]
|
||||
bundle = ["ksni", "smol", "async-compat", "aw-server", "aw-datastore", "open"]
|
||||
|
||||
[package.metadata.deb]
|
||||
features = ["bundle"]
|
||||
|
@ -2,13 +2,15 @@ mod menu;
|
||||
mod server;
|
||||
|
||||
pub use menu::Tray;
|
||||
use std::path::PathBuf;
|
||||
use watchers::config::Config;
|
||||
|
||||
pub fn run(config: &Config, no_tray: bool) {
|
||||
pub fn run(config: &Config, config_file: PathBuf, no_tray: bool) {
|
||||
if !no_tray {
|
||||
let service = ksni::TrayService::new(Tray {
|
||||
server_host: config.host.clone(),
|
||||
server_port: config.port,
|
||||
config_file,
|
||||
});
|
||||
service.spawn();
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Tray {
|
||||
pub server_host: String,
|
||||
pub server_port: u32,
|
||||
pub config_file: PathBuf,
|
||||
}
|
||||
|
||||
impl ksni::Tray for Tray {
|
||||
@ -19,14 +22,27 @@ impl ksni::Tray for Tray {
|
||||
fn menu(&self) -> Vec<ksni::MenuItem<Self>> {
|
||||
vec![
|
||||
ksni::menu::StandardItem {
|
||||
label: "Open".into(),
|
||||
label: "Statistics".into(),
|
||||
// https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
|
||||
icon_name: "document-properties".into(),
|
||||
activate: {
|
||||
let url = format!("http://{}:{}", self.server_host, self.server_port);
|
||||
|
||||
Box::new(move |_| {
|
||||
webbrowser::open(&url).unwrap();
|
||||
open::that(&url).unwrap();
|
||||
})
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
ksni::menu::StandardItem {
|
||||
label: "Configuration".into(),
|
||||
icon_name: "preferences-other".into(),
|
||||
activate: {
|
||||
let config_file = self.config_file.clone().into_os_string();
|
||||
|
||||
Box::new(move |_| {
|
||||
open::that(&config_file).unwrap();
|
||||
})
|
||||
},
|
||||
..Default::default()
|
||||
|
@ -11,6 +11,7 @@ use watchers::config::FileConfig;
|
||||
|
||||
pub struct RunnerConfig {
|
||||
pub watchers_config: Config,
|
||||
pub config_file: PathBuf,
|
||||
pub no_tray: bool,
|
||||
}
|
||||
|
||||
@ -93,6 +94,7 @@ pub fn from_cli() -> anyhow::Result<RunnerConfig> {
|
||||
filters: config.client.filters,
|
||||
no_server: *matches.get_one("no-server").unwrap(),
|
||||
},
|
||||
config_file: config.config_file,
|
||||
#[cfg(feature = "bundle")]
|
||||
no_tray: *matches.get_one("no-tray").unwrap(),
|
||||
#[cfg(not(feature = "bundle"))]
|
||||
|
@ -21,6 +21,8 @@ fn main() -> anyhow::Result<()> {
|
||||
let config = config::from_cli()?;
|
||||
#[cfg(feature = "bundle")]
|
||||
let no_tray = config.no_tray;
|
||||
#[cfg(feature = "bundle")]
|
||||
let config_file = config.config_file;
|
||||
let config = config.watchers_config;
|
||||
|
||||
if config.no_server {
|
||||
@ -39,7 +41,7 @@ fn main() -> anyhow::Result<()> {
|
||||
);
|
||||
|
||||
#[cfg(feature = "bundle")]
|
||||
bundle::run(&config, no_tray);
|
||||
bundle::run(&config, config_file, no_tray);
|
||||
|
||||
let client = ReportClient::new(config)?;
|
||||
let client = Arc::new(client);
|
||||
|
@ -91,19 +91,24 @@ pub struct FileConfig {
|
||||
#[serde(default)]
|
||||
#[serde(rename = "awatcher")]
|
||||
pub client: ClientConfig,
|
||||
#[serde(default)]
|
||||
pub config_file: PathBuf,
|
||||
}
|
||||
|
||||
impl FileConfig {
|
||||
pub fn new(config_override: Option<PathBuf>) -> anyhow::Result<Self> {
|
||||
let mut config_path: PathBuf =
|
||||
dirs::config_dir().ok_or(anyhow!("Config directory is unknown"))?;
|
||||
config_path.push("awatcher");
|
||||
config_path.push("config.toml");
|
||||
if let Some(config_override) = config_override {
|
||||
config_path = config_override;
|
||||
}
|
||||
let config_path = if let Some(config_override) = config_override {
|
||||
config_override
|
||||
} else {
|
||||
let mut system_config_path: PathBuf =
|
||||
dirs::config_dir().ok_or(anyhow!("Config directory is unknown"))?;
|
||||
system_config_path.push("awatcher");
|
||||
system_config_path.push("config.toml");
|
||||
|
||||
let config = if config_path.exists() {
|
||||
system_config_path
|
||||
};
|
||||
|
||||
let mut config = if config_path.exists() {
|
||||
debug!("Reading config at {}", config_path.display());
|
||||
let config_content = std::fs::read_to_string(&config_path).with_context(|| {
|
||||
format!("Impossible to read config file {}", config_path.display())
|
||||
@ -119,10 +124,11 @@ impl FileConfig {
|
||||
}
|
||||
}
|
||||
debug!("Creading config at {}", config_path.display());
|
||||
std::fs::write(config_path, config)?;
|
||||
std::fs::write(&config_path, config)?;
|
||||
|
||||
Self::default()
|
||||
};
|
||||
config.config_file = config_path;
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user