Skip to content

Commit

Permalink
feat:auto download essential modules
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbrayo committed Feb 6, 2025
1 parent 4b65c5a commit 284eb80
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 28 deletions.
84 changes: 62 additions & 22 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tauri-build = { version = "2.0.5", features = [] }

[dependencies]
shell-words = "1.1.0"
tauri = { version = "2.2.2", features = ["tray-icon"] }
tauri = { version = "2.2.5", features = ["tray-icon"] }
tauri-plugin-shell = "2.2.0"
tauri-plugin-dialog = "2.2.0"
tauri-plugin-notification = "2.2.1"
Expand All @@ -30,16 +30,17 @@ tauri-plugin-single-instance = "2.2.1"
notify = "8.0.0"
directories = "6.0.0"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135"
toml = "0.8.19"
serde_json = "1.0.138"
toml = "0.8.20"
csv="1.3.1"
lazy_static = "1.5.0"
log = "0.4.25"
fern = { version = "0.7.1", features = ["colored"] }
chrono = "0.4.39"
aw-server = { git = "https://github.com/ActivityWatch/aw-server-rust.git", branch = "master" }
aw-datastore = { git = "https://github.com/ActivityWatch/aw-server-rust.git", branch = "master" }
tauri-plugin-opener = "2"
tauri-plugin-http = "2"
tauri-plugin-opener = "2.2.5"
tauri-plugin-http = "2.3.0"
[target.'cfg(unix)'.dependencies]
nix = { version = "0.29.0", features = ["process", "signal"] }
[target.'cfg(windows)'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use tauri_plugin_opener::OpenerExt;

mod logging;
mod manager;
mod modules_dl;

use log::info;
use tauri::{
Expand Down
13 changes: 12 additions & 1 deletion src-tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/// their state.
///
/// If a module crashes, the manager will notify the user and ask if they want to restart it.
#[cfg(unix)]
use {
nix::sys::signal::{self, Signal},
Expand All @@ -33,6 +32,7 @@ use std::{env, fs, thread};
use tauri::menu::{CheckMenuItem, Menu, MenuItem, SubmenuBuilder};
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};

use crate::modules_dl::has_essential_modules;
use crate::{get_app_handle, get_config, get_tray_id, HANDLE_CONDVAR};

#[derive(Debug)]
Expand All @@ -53,6 +53,8 @@ pub enum ModuleMessage {
pub struct ManagerState {
tx: Sender<ModuleMessage>,
pub modules_running: BTreeMap<String, bool>,
// TODO: the next four could be merged into one
// modules_metadata hashmap? worse for readability
pub modules_discovered: BTreeMap<String, PathBuf>,
pub modules_pid: HashMap<String, u32>,
pub modules_restart_count: HashMap<String, u32>,
Expand Down Expand Up @@ -103,6 +105,15 @@ impl ManagerState {
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)
.expect("failed to create quit menu item");

if !has_essential_modules(self.modules_discovered.keys().cloned().collect()) {
// todo!()
thread::spawn(|| {
tauri::async_runtime::block_on(async {
crate::modules_dl::download_modules().await.unwrap();
});
});
}

let mut modules_submenu_builder = SubmenuBuilder::new(app, "Modules");
for (module, running) in self.modules_running.iter() {
let label = module;
Expand Down
Loading

0 comments on commit 284eb80

Please sign in to comment.