diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 7fa9170..8abb4e1 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -19,6 +19,8 @@ jobs: - run: cargo fmt --check --all clippy: runs-on: ubuntu-latest + env: + AW_WEBUI_DIST: ./src/bundle steps: - uses: actions/checkout@v3 - run: sudo apt-get install -y libdbus-1-dev diff --git a/Cargo.lock b/Cargo.lock index 11baad8..7cfee98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,18 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if 1.0.0", - "cipher", - "cpufeatures", - "opaque-debug", -] - [[package]] name = "ahash" version = "0.7.6" @@ -359,10 +347,10 @@ dependencies = [ [[package]] name = "aw-datastore" version = "0.1.0" -source = "git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026#49b2026b2b61f8d8d017e93dca1d3754dcfef0d5" +source = "git+https://github.com/2e3s/aw-server-rust?rev=b967a56#b967a5643004806b6daaba36e083a504320ad983" dependencies = [ "appdirs", - "aw-models 0.1.0 (git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026)", + "aw-models 0.1.0 (git+https://github.com/2e3s/aw-server-rust?rev=b967a56)", "aw-transform", "chrono", "log", @@ -375,7 +363,7 @@ dependencies = [ [[package]] name = "aw-models" version = "0.1.0" -source = "git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026#49b2026b2b61f8d8d017e93dca1d3754dcfef0d5" +source = "git+https://github.com/2e3s/aw-server-rust?rev=b967a56#b967a5643004806b6daaba36e083a504320ad983" dependencies = [ "chrono", "log", @@ -399,10 +387,10 @@ dependencies = [ [[package]] name = "aw-query" version = "0.1.0" -source = "git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026#49b2026b2b61f8d8d017e93dca1d3754dcfef0d5" +source = "git+https://github.com/2e3s/aw-server-rust?rev=b967a56#b967a5643004806b6daaba36e083a504320ad983" dependencies = [ "aw-datastore", - "aw-models 0.1.0 (git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026)", + "aw-models 0.1.0 (git+https://github.com/2e3s/aw-server-rust?rev=b967a56)", "aw-transform", "chrono", "fancy-regex", @@ -415,12 +403,12 @@ dependencies = [ [[package]] name = "aw-server" version = "0.12.1" -source = "git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026#49b2026b2b61f8d8d017e93dca1d3754dcfef0d5" +source = "git+https://github.com/2e3s/aw-server-rust?rev=b967a56#b967a5643004806b6daaba36e083a504320ad983" dependencies = [ "android_logger", "appdirs", "aw-datastore", - "aw-models 0.1.0 (git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026)", + "aw-models 0.1.0 (git+https://github.com/2e3s/aw-server-rust?rev=b967a56)", "aw-query", "aw-transform", "chrono", @@ -437,6 +425,7 @@ dependencies = [ "openssl-sys", "rocket", "rocket_cors", + "rust-embed", "serde", "serde_json", "toml 0.7.3", @@ -446,9 +435,9 @@ dependencies = [ [[package]] name = "aw-transform" version = "0.1.0" -source = "git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026#49b2026b2b61f8d8d017e93dca1d3754dcfef0d5" +source = "git+https://github.com/2e3s/aw-server-rust?rev=b967a56#b967a5643004806b6daaba36e083a504320ad983" dependencies = [ - "aw-models 0.1.0 (git+https://github.com/ActivityWatch/aw-server-rust.git?rev=49b2026)", + "aw-models 0.1.0 (git+https://github.com/2e3s/aw-server-rust?rev=b967a56)", "chrono", "fancy-regex", "log", @@ -459,7 +448,7 @@ dependencies = [ [[package]] name = "awatcher" -version = "0.0.1" +version = "0.0.4" dependencies = [ "anyhow", "async-compat", @@ -470,12 +459,12 @@ dependencies = [ "fern", "ksni", "log", + "rust-embed", "signal-hook", "smol", "toml 0.7.3", "watchers", "webbrowser", - "zip-extract", ] [[package]] @@ -488,7 +477,7 @@ dependencies = [ "cc", "cfg-if 1.0.0", "libc", - "miniz_oxide 0.6.2", + "miniz_oxide", "object", "rustc-demangle", ] @@ -499,12 +488,6 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "binascii" version = "0.1.4" @@ -604,35 +587,11 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" -[[package]] -name = "bzip2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" -dependencies = [ - "bzip2-sys", - "libc", -] - -[[package]] -name = "bzip2-sys" -version = "0.1.11+1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" -dependencies = [ - "jobserver", -] [[package]] name = "cesu8" @@ -668,15 +627,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "cipher" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" -dependencies = [ - "generic-array", -] - [[package]] name = "clap" version = "2.34.0" @@ -790,12 +740,6 @@ dependencies = [ "crossbeam-utils 0.8.15", ] -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "cookie" version = "0.17.0" @@ -832,15 +776,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "crossbeam-channel" version = "0.4.4" @@ -1043,7 +978,6 @@ checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer", "crypto-common", - "subtle", ] [[package]] @@ -1235,16 +1169,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "flate2" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" -dependencies = [ - "crc32fast", - "miniz_oxide 0.7.1", -] - [[package]] name = "fnv" version = "1.0.7" @@ -1494,15 +1418,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "http" version = "0.2.9" @@ -1730,15 +1645,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" -[[package]] -name = "jobserver" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.61" @@ -1940,15 +1846,6 @@ dependencies = [ "adler", ] -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - [[package]] name = "mio" version = "0.8.6" @@ -2132,12 +2029,6 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl" version = "0.10.48" @@ -2238,29 +2129,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "password-hash" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" -dependencies = [ - "base64ct", - "rand_core", - "subtle", -] - -[[package]] -name = "pbkdf2" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" -dependencies = [ - "digest", - "hmac", - "password-hash", - "sha2", -] - [[package]] name = "pear" version = "0.2.4" @@ -2695,6 +2563,42 @@ dependencies = [ "smallvec", ] +[[package]] +name = "rust-embed" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b68543d5527e158213414a92832d2aab11a84d2571a5eb021ebe22c43aab066" +dependencies = [ + "rocket", + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "6.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4e0f0ced47ded9a68374ac145edd65a6c1fa13a96447b873660b2a568a0fd7" +dependencies = [ + "proc-macro2 1.0.54", + "quote 1.0.26", + "rust-embed-utils", + "shellexpand", + "syn 1.0.109", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "7.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512b0ab6853f7e14e3c8754acb43d6f748bb9ced66aa5915a6553ac8213f7731" +dependencies = [ + "sha2", + "walkdir", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2944,6 +2848,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs 4.0.0", +] + [[package]] name = "signal-hook" version = "0.3.15" @@ -3047,12 +2960,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "subtle" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" - [[package]] name = "syn" version = "0.15.44" @@ -4147,67 +4054,6 @@ dependencies = [ "zvariant", ] -[[package]] -name = "zip" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e92305c174683d78035cbf1b70e18db6329cc0f1b9cae0a52ca90bf5bfe7125" -dependencies = [ - "aes", - "byteorder", - "bzip2", - "constant_time_eq", - "crc32fast", - "crossbeam-utils 0.8.15", - "flate2", - "hmac", - "pbkdf2", - "sha1", - "time 0.3.21", - "zstd", -] - -[[package]] -name = "zip-extract" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb654964c003959ed64cbd0d7b329bcdcbd9690facd50c8617748d3622543972" -dependencies = [ - "log", - "thiserror", - "zip", -] - -[[package]] -name = "zstd" -version = "0.11.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" -dependencies = [ - "zstd-safe", -] - -[[package]] -name = "zstd-safe" -version = "5.0.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" -dependencies = [ - "libc", - "zstd-sys", -] - -[[package]] -name = "zstd-sys" -version = "2.0.8+zstd.1.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "zvariant" version = "3.12.0" diff --git a/Cargo.toml b/Cargo.toml index 56946fb..6136d7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,10 @@ [package] name = "awatcher" -version = "0.0.1" +version = "0.0.4" authors = ["Demmie <2e3s19@gmail.com>"] edition = "2021" +license-file = "LICENSE" +repository = "https://github.com/2e3s/awatcher" [[bin]] name = "awatcher" @@ -26,15 +28,23 @@ anyhow = { workspace = true } signal-hook = "0.3.15" ksni = {version = "0.2.0", optional = true} -aw-server = { git = "https://github.com/ActivityWatch/aw-server-rust.git", optional = true, rev = "49b2026" } -aw-datastore = { git = "https://github.com/ActivityWatch/aw-server-rust.git", optional = true, rev = "49b2026" } +aw-server = { git = "https://github.com/2e3s/aw-server-rust", optional = true, rev = "b967a56" } +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 } -zip-extract = { version = "0.1.2", default-features = false, features = ["deflate"], 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", "zip-extract"] +bundle = ["ksni", "smol", "async-compat", "aw-server", "aw-datastore", "webbrowser"] + +[package.metadata.deb] +features = ["bundle"] +extended-description = """\ +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 by supporting all reportable environments, +to add more flexibility to reports with filters, and to have better UX with the distribution by a single executable. +""" diff --git a/README.md b/README.md index f62e7d4..92fa6a7 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,7 @@ The executable can be bundled with a tray icon, ActivityWatch server and, option 1. Clone and follow the instruction in [ActivityWatch/aw-webui@839366e](https://github.com/ActivityWatch/aw-webui/commit/839366e66f859faadd7f9128de3bea14b25ce4ae) to build the "dist" folder, -1. Then zip it with `zip -r dist.zip ./dist`. -1. Put the zip file to `src/bundle`. -1. Build the executable with `--features=bundle`. +1. Build the executable with `AW_WEBUI_DIST=path/to/dist` and `--features=bundle`. This should be compiled on nightly. The complete bundled version is also built and released. diff --git a/src/bundle.rs b/src/bundle.rs index df2ee46..41c4951 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -1,12 +1,10 @@ mod menu; mod server; -mod site_data; pub use menu::Tray; -use site_data::unpack_data; use watchers::config::Config; -pub fn run(config: &Config, no_tray: bool) -> anyhow::Result<()> { +pub fn run(config: &Config, no_tray: bool) { if !no_tray { let service = ksni::TrayService::new(Tray { server_host: config.host.clone(), @@ -16,8 +14,5 @@ pub fn run(config: &Config, no_tray: bool) -> anyhow::Result<()> { } let port = config.port; - let data_dir = unpack_data()?; - server::run(data_dir, port); - - Ok(()) + server::run(port); } diff --git a/src/bundle/dist.zip b/src/bundle/dist.zip deleted file mode 100644 index 15cb0ec..0000000 Binary files a/src/bundle/dist.zip and /dev/null differ diff --git a/src/bundle/server.rs b/src/bundle/server.rs index 667c432..9d408ea 100644 --- a/src/bundle/server.rs +++ b/src/bundle/server.rs @@ -1,12 +1,12 @@ use anyhow::anyhow; use async_compat::Compat; -use aw_server::endpoints::build_rocket; -use std::{path::PathBuf, sync::Mutex}; +use aw_server::endpoints::{build_rocket, embed_asset_resolver}; +use std::sync::Mutex; -pub fn run(asset_path: PathBuf, port: u32) { +pub fn run(port: u32) { std::thread::spawn(move || { let db_path = aw_server::dirs::db_path(false) - .map_err(|_| anyhow!("DB path is not found: {}", asset_path.display())) + .map_err(|_| anyhow!("DB path is not found")) .unwrap() .to_str() .unwrap() @@ -19,7 +19,7 @@ pub fn run(asset_path: PathBuf, port: u32) { let legacy_import = false; let server_state = aw_server::endpoints::ServerState { datastore: Mutex::new(aw_datastore::Datastore::new(db_path, legacy_import)), - asset_path: asset_path.join("dist"), + asset_resolver: embed_asset_resolver!("$AW_WEBUI_DIST"), device_id, }; diff --git a/src/bundle/site_data.rs b/src/bundle/site_data.rs deleted file mode 100644 index 6357bc7..0000000 --- a/src/bundle/site_data.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::{fs, io::Cursor, path::PathBuf}; - -const SITE_DATA: &[u8] = include_bytes!("./dist.zip"); - -pub fn unpack_data() -> anyhow::Result { - let target_dir = std::env::temp_dir().join("awatcher"); - - if target_dir.exists() { - fs::remove_dir_all(&target_dir)?; - } - zip_extract::extract(Cursor::new(SITE_DATA), &target_dir, false)?; - - Ok(target_dir) -} diff --git a/src/main.rs b/src/main.rs index ebfc357..ecc6550 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ fn main() -> anyhow::Result<()> { ); #[cfg(feature = "bundle")] - bundle::run(&config, no_tray)?; + bundle::run(&config, no_tray); let client = ReportClient::new(config)?; let client = Arc::new(client);