Skip to content

Commit

Permalink
fix(restart): optional stopping miners for restart application (#1060)
Browse files Browse the repository at this point in the history
Added a flag for terminating processes before restarting the app. We
don't want to kill processes during auto-updates, but in other cases we
want to kill them and prevent from hanging processes and killing them
after the restart.

Co-authored-by: Brian Pearce <[email protected]>
  • Loading branch information
mmrrnn and brianp authored Nov 14, 2024
1 parent 63cb391 commit 57ac88e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,15 @@ async fn set_monerod_config(

#[tauri::command]
async fn restart_application(
should_stop_miners: bool,
_window: tauri::Window,
_state: tauri::State<'_, UniverseAppState>,
state: tauri::State<'_, UniverseAppState>,
app: tauri::AppHandle,
) -> Result<(), String> {
// This restart doesn't need to shutdown all the miners
if should_stop_miners {
stop_all_miners(state.inner().clone(), 5).await?;
}

app.restart();
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/RestartDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function RestartDialog() {
const handleRestart = useCallback(async () => {
try {
console.info('Restarting application.');
await invoke('restart_application');
await invoke('restart_application', { shouldStopMiners: true });
} catch (error) {
Sentry.captureException(error);
console.error('Restart error: ', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ExternalDependenciesDialog = () => {
const handleRestart = useCallback(async () => {
try {
setIsRestarting(true);
await invoke('restart_application');
await invoke('restart_application', { shouldStopMiners: true });
} catch (e) {
Sentry.captureException(e);
console.error('Error restarting application:', e);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useUpdateStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const useHandleUpdate = () => {
console.info('Installing latest version of Tari Universe');
try {
console.info('Restarting application after update');
await invoke('restart_application');
await invoke('restart_application', { shouldStopMiners: false });
} catch (e) {
Sentry.captureException(e);
console.error('Relaunch error', e);
Expand Down
2 changes: 1 addition & 1 deletion src/types/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ declare module '@tauri-apps/api/tauri' {
): Promise<void>;
function invoke(param: 'set_cpu_mining_enabled', payload: { enabled: boolean }): Promise<void>;
function invoke(param: 'exit_application'): Promise<string>;
function invoke(param: 'restart_application'): Promise<string>;
function invoke(param: 'restart_application', payload: { shouldStopMiners: boolean }): Promise<string>;
function invoke(param: 'set_use_tor', payload: { useTor: boolean }): Promise<void>;
function invoke(param: 'get_transaction_history'): Promise<TransactionInfo[]>;
function invoke(param: 'import_seed_words', payload: { seedWords: string[] }): Promise<void>;
Expand Down

0 comments on commit 57ac88e

Please sign in to comment.