mirror of
https://github.com/2e3s/awatcher.git
synced 2025-06-07 12:05:49 +00:00
Add --no-tray bundle option
This commit is contained in:
parent
216b2a1334
commit
c8ca1debab
@ -1,10 +1,14 @@
|
|||||||
# Awatcher
|
# Awatcher
|
||||||
[](https://github.com/2e3s/awatcher/actions?query=branch%3Amain) [](https://deps.rs/repo/github/2e3s/awatcher)
|
[](https://github.com/2e3s/awatcher/actions?query=branch%3Amain) [](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,
|
The goal is to compensate the fragmentation of desktop environments on Linux,
|
||||||
and to add more flexibility to reports.
|
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
|
## Build
|
||||||
|
|
||||||
### Prerequisites
|
### 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.
|
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
|
## Supported environments
|
||||||
|
|
||||||
ActivityWatch server should be run before `awatcher` is running.
|
ActivityWatch server should be run before `awatcher` is running.
|
||||||
|
@ -6,12 +6,14 @@ pub use menu::Tray;
|
|||||||
use site_data::unpack_data;
|
use site_data::unpack_data;
|
||||||
use watchers::config::Config;
|
use watchers::config::Config;
|
||||||
|
|
||||||
pub fn run(config: &Config) -> anyhow::Result<()> {
|
pub fn run(config: &Config, no_tray: bool) -> anyhow::Result<()> {
|
||||||
|
if !no_tray {
|
||||||
let service = ksni::TrayService::new(Tray {
|
let service = ksni::TrayService::new(Tray {
|
||||||
server_host: config.host.clone(),
|
server_host: config.host.clone(),
|
||||||
server_port: config.port,
|
server_port: config.port,
|
||||||
});
|
});
|
||||||
service.spawn();
|
service.spawn();
|
||||||
|
}
|
||||||
|
|
||||||
let port = config.port;
|
let port = config.port;
|
||||||
let data_dir = unpack_data()?;
|
let data_dir = unpack_data()?;
|
||||||
|
@ -9,6 +9,11 @@ use watchers::config::defaults;
|
|||||||
use watchers::config::Config;
|
use watchers::config::Config;
|
||||||
use watchers::config::FileConfig;
|
use watchers::config::FileConfig;
|
||||||
|
|
||||||
|
pub struct RunnerConfig {
|
||||||
|
pub watchers_config: Config,
|
||||||
|
pub no_tray: bool,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setup_logger(verbosity: LevelFilter) -> Result<(), fern::InitError> {
|
pub fn setup_logger(verbosity: LevelFilter) -> Result<(), fern::InitError> {
|
||||||
fern::Dispatch::new()
|
fern::Dispatch::new()
|
||||||
.format(|out, message, record| {
|
.format(|out, message, record| {
|
||||||
@ -32,7 +37,7 @@ pub fn setup_logger(verbosity: LevelFilter) -> Result<(), fern::InitError> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_cli() -> anyhow::Result<Config> {
|
pub fn from_cli() -> anyhow::Result<RunnerConfig> {
|
||||||
let matches = Command::new("Activity Watcher")
|
let matches = Command::new("Activity Watcher")
|
||||||
.version("0.0.1")
|
.version("0.0.1")
|
||||||
.about("A set of ActivityWatch desktop watchers")
|
.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")
|
arg!(--"no-server" "Don't communicate to the ActivityWatch server")
|
||||||
.value_parser(value_parser!(bool))
|
.value_parser(value_parser!(bool))
|
||||||
.action(ArgAction::SetTrue),
|
.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")
|
Arg::new("verbosity")
|
||||||
.short('v')
|
.short('v')
|
||||||
.help("Verbosity level: -v for warnings, -vv for info, -vvv for debug, -vvvv for trace")
|
.help("Verbosity level: -v for warnings, -vv for info, -vvv for debug, -vvvv for trace")
|
||||||
@ -74,7 +83,8 @@ pub fn from_cli() -> anyhow::Result<Config> {
|
|||||||
};
|
};
|
||||||
setup_logger(verbosity)?;
|
setup_logger(verbosity)?;
|
||||||
|
|
||||||
Ok(Config {
|
Ok(RunnerConfig {
|
||||||
|
watchers_config: Config {
|
||||||
port: config.server.port,
|
port: config.server.port,
|
||||||
host: config.server.host,
|
host: config.server.host,
|
||||||
idle_timeout: config.client.get_idle_timeout(),
|
idle_timeout: config.client.get_idle_timeout(),
|
||||||
@ -82,6 +92,11 @@ pub fn from_cli() -> anyhow::Result<Config> {
|
|||||||
poll_time_window: config.client.get_poll_time_window(),
|
poll_time_window: config.client.get_poll_time_window(),
|
||||||
filters: config.client.filters,
|
filters: config.client.filters,
|
||||||
no_server: *matches.get_one("no-server").unwrap(),
|
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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![warn(clippy::pedantic)]
|
#![warn(clippy::pedantic)]
|
||||||
|
#![allow(clippy::module_name_repetitions)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
@ -13,6 +14,8 @@ use watchers::ReportClient;
|
|||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let config = config::from_cli()?;
|
let config = config::from_cli()?;
|
||||||
|
let no_tray = config.no_tray;
|
||||||
|
let config = config.watchers_config;
|
||||||
|
|
||||||
if config.no_server {
|
if config.no_server {
|
||||||
warn!("Not sending to server {}:{}", config.host, config.port);
|
warn!("Not sending to server {}:{}", config.host, config.port);
|
||||||
@ -30,7 +33,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "bundle")]
|
#[cfg(feature = "bundle")]
|
||||||
bundle::run(&config)?;
|
bundle::run(&config, no_tray)?;
|
||||||
|
|
||||||
let client = ReportClient::new(config)?;
|
let client = ReportClient::new(config)?;
|
||||||
let client = Arc::new(client);
|
let client = Arc::new(client);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user