Add --no-tray bundle option

This commit is contained in:
Demmie 2023-05-08 21:40:05 -04:00
parent 216b2a1334
commit c8ca1debab
No known key found for this signature in database
GPG Key ID: B06DAA3D432C6E9A
4 changed files with 43 additions and 17 deletions

View File

@ -1,10 +1,14 @@
# Awatcher
[![Build Status](https://github.com/2e3s/awatcher/workflows/check/badge.svg?branch=main)](https://github.com/2e3s/awatcher/actions?query=branch%3Amain) [![Dependency Status](https://deps.rs/repo/github/2e3s/awatcher/status.svg)](https://deps.rs/repo/github/2e3s/awatcher)
Awatcher is a window activity and idle watcher for [ActivityWatch](https://github.com/ActivityWatch) server.
Awatcher is a window activity and idle watcher with an optional tray and UI for statistics.
The goal is to compensate the fragmentation of desktop environments on Linux,
and to add more flexibility to reports.
The server and web UI are taken from [ActivityWatch](https://github.com/ActivityWatch) project,
which has a worse support of Linux environment, with a pretty bulky distribution.
The crate also provides a library with watchers which can send statistics to the server.
## Build
### Prerequisites
@ -37,6 +41,8 @@ This should be compiled on nightly. The complete bundled version is also built a
Gnome needs [the extension](https://extensions.gnome.org/extension/615/appindicator-support/) to support StatusNotifierItem specification.
The tray can be disabled with `--no-tray` option in the bundled version.
## Supported environments
ActivityWatch server should be run before `awatcher` is running.

View File

@ -6,12 +6,14 @@ pub use menu::Tray;
use site_data::unpack_data;
use watchers::config::Config;
pub fn run(config: &Config) -> anyhow::Result<()> {
let service = ksni::TrayService::new(Tray {
server_host: config.host.clone(),
server_port: config.port,
});
service.spawn();
pub fn run(config: &Config, no_tray: bool) -> anyhow::Result<()> {
if !no_tray {
let service = ksni::TrayService::new(Tray {
server_host: config.host.clone(),
server_port: config.port,
});
service.spawn();
}
let port = config.port;
let data_dir = unpack_data()?;

View File

@ -9,6 +9,11 @@ use watchers::config::defaults;
use watchers::config::Config;
use watchers::config::FileConfig;
pub struct RunnerConfig {
pub watchers_config: Config,
pub no_tray: bool,
}
pub fn setup_logger(verbosity: LevelFilter) -> Result<(), fern::InitError> {
fern::Dispatch::new()
.format(|out, message, record| {
@ -32,7 +37,7 @@ pub fn setup_logger(verbosity: LevelFilter) -> Result<(), fern::InitError> {
Ok(())
}
pub fn from_cli() -> anyhow::Result<Config> {
pub fn from_cli() -> anyhow::Result<RunnerConfig> {
let matches = Command::new("Activity Watcher")
.version("0.0.1")
.about("A set of ActivityWatch desktop watchers")
@ -56,6 +61,10 @@ pub fn from_cli() -> anyhow::Result<Config> {
arg!(--"no-server" "Don't communicate to the ActivityWatch server")
.value_parser(value_parser!(bool))
.action(ArgAction::SetTrue),
#[cfg(feature = "bundle")]
arg!(--"no-tray" "Don't use the bundled tray, run only server and watchers in the background")
.value_parser(value_parser!(bool))
.action(ArgAction::SetTrue),
Arg::new("verbosity")
.short('v')
.help("Verbosity level: -v for warnings, -vv for info, -vvv for debug, -vvvv for trace")
@ -74,14 +83,20 @@ pub fn from_cli() -> anyhow::Result<Config> {
};
setup_logger(verbosity)?;
Ok(Config {
port: config.server.port,
host: config.server.host,
idle_timeout: config.client.get_idle_timeout(),
poll_time_idle: config.client.get_poll_time_idle(),
poll_time_window: config.client.get_poll_time_window(),
filters: config.client.filters,
no_server: *matches.get_one("no-server").unwrap(),
Ok(RunnerConfig {
watchers_config: Config {
port: config.server.port,
host: config.server.host,
idle_timeout: config.client.get_idle_timeout(),
poll_time_idle: config.client.get_poll_time_idle(),
poll_time_window: config.client.get_poll_time_window(),
filters: config.client.filters,
no_server: *matches.get_one("no-server").unwrap(),
},
#[cfg(feature = "bundle")]
no_tray: *matches.get_one("no-tray").unwrap(),
#[cfg(not(feature = "bundle"))]
no_tray: true,
})
}

View File

@ -1,4 +1,5 @@
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
#[macro_use]
extern crate log;
@ -13,6 +14,8 @@ use watchers::ReportClient;
fn main() -> anyhow::Result<()> {
let config = config::from_cli()?;
let no_tray = config.no_tray;
let config = config.watchers_config;
if config.no_server {
warn!("Not sending to server {}:{}", config.host, config.port);
@ -30,7 +33,7 @@ fn main() -> anyhow::Result<()> {
);
#[cfg(feature = "bundle")]
bundle::run(&config)?;
bundle::run(&config, no_tray)?;
let client = ReportClient::new(config)?;
let client = Arc::new(client);