Skip to content

Commit 284eb80

Browse files
committed
feat:auto download essential modules
1 parent 4b65c5a commit 284eb80

File tree

5 files changed

+207
-28
lines changed

5 files changed

+207
-28
lines changed

src-tauri/Cargo.lock

+62-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tauri-build = { version = "2.0.5", features = [] }
2121

2222
[dependencies]
2323
shell-words = "1.1.0"
24-
tauri = { version = "2.2.2", features = ["tray-icon"] }
24+
tauri = { version = "2.2.5", features = ["tray-icon"] }
2525
tauri-plugin-shell = "2.2.0"
2626
tauri-plugin-dialog = "2.2.0"
2727
tauri-plugin-notification = "2.2.1"
@@ -30,16 +30,17 @@ tauri-plugin-single-instance = "2.2.1"
3030
notify = "8.0.0"
3131
directories = "6.0.0"
3232
serde = { version = "1.0.217", features = ["derive"] }
33-
serde_json = "1.0.135"
34-
toml = "0.8.19"
33+
serde_json = "1.0.138"
34+
toml = "0.8.20"
35+
csv="1.3.1"
3536
lazy_static = "1.5.0"
3637
log = "0.4.25"
3738
fern = { version = "0.7.1", features = ["colored"] }
3839
chrono = "0.4.39"
3940
aw-server = { git = "https://github.com/ActivityWatch/aw-server-rust.git", branch = "master" }
4041
aw-datastore = { git = "https://github.com/ActivityWatch/aw-server-rust.git", branch = "master" }
41-
tauri-plugin-opener = "2"
42-
tauri-plugin-http = "2"
42+
tauri-plugin-opener = "2.2.5"
43+
tauri-plugin-http = "2.3.0"
4344
[target.'cfg(unix)'.dependencies]
4445
nix = { version = "0.29.0", features = ["process", "signal"] }
4546
[target.'cfg(windows)'.dependencies]

src-tauri/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use tauri_plugin_opener::OpenerExt;
1818

1919
mod logging;
2020
mod manager;
21+
mod modules_dl;
2122

2223
use log::info;
2324
use tauri::{

src-tauri/src/manager.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/// their state.
88
///
99
/// If a module crashes, the manager will notify the user and ask if they want to restart it.
10-
1110
#[cfg(unix)]
1211
use {
1312
nix::sys::signal::{self, Signal},
@@ -33,6 +32,7 @@ use std::{env, fs, thread};
3332
use tauri::menu::{CheckMenuItem, Menu, MenuItem, SubmenuBuilder};
3433
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
3534

35+
use crate::modules_dl::has_essential_modules;
3636
use crate::{get_app_handle, get_config, get_tray_id, HANDLE_CONDVAR};
3737

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

108+
if !has_essential_modules(self.modules_discovered.keys().cloned().collect()) {
109+
// todo!()
110+
thread::spawn(|| {
111+
tauri::async_runtime::block_on(async {
112+
crate::modules_dl::download_modules().await.unwrap();
113+
});
114+
});
115+
}
116+
106117
let mut modules_submenu_builder = SubmenuBuilder::new(app, "Modules");
107118
for (module, running) in self.modules_running.iter() {
108119
let label = module;

0 commit comments

Comments
 (0)