Skip to content

Commit

Permalink
feat(gui): Kill monero-wallet-rpc if running in background
Browse files Browse the repository at this point in the history
Before we initialize the context, we kill any running monero-wallet-rpc process on the users machine. This is a bit invasive but it's the best we can do for now.
  • Loading branch information
binarybaron committed Nov 14, 2024
1 parent 8860f7c commit 5c6c65e
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 8 deletions.
123 changes: 115 additions & 8 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 src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ once_cell = "1"
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
swap = { path = "../swap", features = [ "tauri" ] }
sysinfo = "=0.32.0"
tauri = { version = "2.0", features = [ "config-json5" ] }
tauri-plugin-clipboard-manager = "2.0"
tauri-plugin-devtools = "2.0"
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ async fn initialize_context(
app_handle: tauri::AppHandle,
state: tauri::State<'_, RwLock<State>>,
) -> Result<(), String> {
// When the app crashes, the monero-wallet-rpc process may not be killed
// This can lead to issues when the app is restarted
// because the monero-wallet-rpc has a lock on the wallet
// this will prevent the newly spawned instance from opening the wallet
// To fix this, we will kill the monero-wallet-rpc process if it is running
let sys = sysinfo::System::new_with_specifics(
sysinfo::RefreshKind::new().with_processes(sysinfo::ProcessRefreshKind::new()),
);
for (_, process) in sys.processes() {
if process.name() == "monero-wallet-rpc" {
process.kill();
}
}

// Acquire a write lock on the state
let mut state_write_lock = state
.try_write()
Expand Down

0 comments on commit 5c6c65e

Please sign in to comment.