Skip to content

Commit

Permalink
refactor: move stronghold to jarvis plugin
Browse files Browse the repository at this point in the history
because we may use it in JS, it's easier to package everything with jarvis
  • Loading branch information
HuakunShen committed Dec 30, 2024
1 parent f1dd79f commit ed91821
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ openssl = "0.10.68"
tower = { version = "0.4", features = ["util"] }
tower-http = { version = "0.4.0", features = ["fs", "trace", "cors"] }
rayon = "1.10.0"
tauri-plugin-stronghold = "2"
tauri-plugin-upload = { git = "https://github.com/HuakunShen/tauri-plugins-workspace.git", branch = "kunkun", package = "tauri-plugin-upload" }
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ uuid = "1.11.0"
# tauri-plugin-devtools = "2.0.0"
obfstr = { workspace = true }
base64 = { workspace = true }
tauri-plugin-stronghold = "2"
tauri-plugin-stronghold = { workspace = true }

[target."cfg(target_os = \"macos\")".dependencies]
cocoa = "0.24.1"
Expand Down
6 changes: 4 additions & 2 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ pub fn run() {
.setup(move |app| {
setup::window::setup_window(app.handle());
setup::tray::create_tray(app.handle())?;
setup::stronghold::setup_stronghold(app.handle())?;
#[cfg(all(not(target_os = "macos"), debug_assertions))]
{
app.deep_link().register("kunkun")?;
Expand Down Expand Up @@ -245,7 +244,10 @@ pub fn run() {
// setup::db::setup_db(app)?;
let db_key = setup::keyring::setup_keyring(app.handle())?;
let db_path = get_kunkun_db_path(app.app_handle())?;
app.manage(tauri_plugin_jarvis::commands::db::DBState::new(db_path.clone(), db_key.clone())?);
app.manage(tauri_plugin_jarvis::commands::db::DBState::new(
db_path.clone(),
db_key.clone(),
)?);
tauri_plugin_jarvis::setup::db::setup_db(app.app_handle())?;
/* ------------------------- Clipboard History Setup ------------------------ */

Expand Down
1 change: 0 additions & 1 deletion apps/desktop/src-tauri/src/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod clipboard;
pub mod deeplink;
pub mod keyring;
pub mod stronghold;
pub mod tray;
pub mod window;
11 changes: 0 additions & 11 deletions apps/desktop/src-tauri/src/setup/stronghold.rs

This file was deleted.

1 change: 1 addition & 0 deletions packages/tauri-plugins/jarvis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde_json = { workspace = true }
thiserror = "1.0"
applications = { workspace = true }
anyhow = { workspace = true }
tauri-plugin-stronghold = { workspace = true }
tar = "0.4.40"
flate2 = "1.0.30"
window-vibrancy = "0.5.0"
Expand Down
7 changes: 7 additions & 0 deletions packages/tauri-plugins/jarvis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ impl JarvisState {

/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
let salt_path = app
.path()
.app_local_data_dir()
.expect("could not resolve app local data path")
.join("salt.txt");
Builder::new("jarvis")
.plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?
.invoke_handler(tauri::generate_handler![
/* ------------------------------ dev commands ------------------------------ */
commands::dev::open_devtools,
Expand Down Expand Up @@ -180,6 +186,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
.setup(move |app, api| {
utils::setup::setup_app_path(app);
utils::setup::setup_extension_storage(app);
utils::setup::setup_stronghold(app);

// manage state so it is accessible by the commands
app.manage(JarvisState::new());
Expand Down
10 changes: 10 additions & 0 deletions packages/tauri-plugins/jarvis/src/utils/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ pub fn setup_extension_storage<R: Runtime>(handle: &AppHandle<R>) {
std::fs::create_dir_all(&ext_dir).unwrap();
}
}

pub fn setup_stronghold(app: &AppHandle) -> tauri::Result<()> {
let salt_path = app
.path()
.app_local_data_dir()
.expect("could not resolve app local data path")
.join("salt.txt");
app.plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?;
Ok(())
}

0 comments on commit ed91821

Please sign in to comment.