diff --git a/nix/internal/linux-self-extracting-archive.sh b/nix/internal/linux-self-extracting-archive.sh index e092ddff5b..3fd4b7489d 100644 --- a/nix/internal/linux-self-extracting-archive.sh +++ b/nix/internal/linux-self-extracting-archive.sh @@ -24,11 +24,11 @@ if [ "$our_checksum" != 00000000000000000000000000000000000000000000000000000000 exit 1 fi -echo STATUS "Cleaning up the older version..." +echo STATUS "Cleaning up already installed version(s)..." echo PROG 2/$num_steps target="$HOME"/.daedalus/@CLUSTER@ if [ -e "$target" ] ; then - echo "Found an older version of Daedalus "@CLUSTER@", removing it..." + echo "Found another version of Daedalus "@CLUSTER@", removing it..." chmod -R +w "$target" rm -rf "$target" fi diff --git a/source/main/cardano/setup.ts b/source/main/cardano/setup.ts index f56f496ad2..43a0126030 100644 --- a/source/main/cardano/setup.ts +++ b/source/main/cardano/setup.ts @@ -170,6 +170,7 @@ export const setupCardanoNode = ( logger.info( 'CardanoNode applied an update. Exiting Daedalus with code 20.' ); + // FIXME: Dead code? This channel doesn’t seem used. The node doesn’t apply its own updates…? safeExitWithCode(20); }); return Promise.resolve(); diff --git a/source/main/index.ts b/source/main/index.ts index 20d22cca4c..0c48a42eb2 100644 --- a/source/main/index.ts +++ b/source/main/index.ts @@ -85,12 +85,17 @@ EventEmitter.defaultMaxListeners = 100; // Default: 10 const safeExit = async () => { pauseActiveDownloads(); + const exitCode = + (mainWindow as any).daedalusExitCode !== undefined + ? (mainWindow as any).daedalusExitCode + : 0; + if (!cardanoNode || cardanoNode.state === CardanoNodeStates.STOPPED) { // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.info('Daedalus:safeExit: exiting Daedalus with code 0', { - code: 0, + logger.info(`Daedalus:safeExit: exiting Daedalus with code ${exitCode}`, { + code: exitCode, }); - return safeExitWithCode(0); + return safeExitWithCode(exitCode); } if (cardanoNode.state === CardanoNodeStates.STOPPING) { @@ -108,16 +113,16 @@ const safeExit = async () => { }); await cardanoNode.stop(); // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.info('Daedalus:safeExit: exiting Daedalus with code 0', { - code: 0, + logger.info(`Daedalus:safeExit: exiting Daedalus with code ${code}`, { + code: exitCode, }); - safeExitWithCode(0); + safeExitWithCode(exitCode); } catch (error) { // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.error('Daedalus:safeExit: cardano-node did not exit correctly', { error, }); - safeExitWithCode(0); + safeExitWithCode(exitCode); } }; diff --git a/source/main/ipc/manageAppUpdateChannel.ts b/source/main/ipc/manageAppUpdateChannel.ts index 80e43d3915..5be4be18d7 100644 --- a/source/main/ipc/manageAppUpdateChannel.ts +++ b/source/main/ipc/manageAppUpdateChannel.ts @@ -11,7 +11,6 @@ import type { } from '../../common/ipc/api'; import { UPDATE_INSTALLATION_STATUSES as statuses } from '../../common/config/appUpdateConfig'; import { environment } from '../environment'; -import { safeExitWithCode } from '../utils/safeExitWithCode'; import { logger } from '../utils/logging'; import { launcherConfig } from '../config'; // IpcChannel @@ -169,7 +168,11 @@ export const handleManageAppUpdateRequests = (window: BrowserWindow) => { return reject(); } - safeExitWithCode(20); + // We need to also wait for `cardano-node` to exit cleanly, otherwise the new auto-updated version + // is showing the new node crashing, because the old one is still running for around 30 seconds: + // WRONG: safeExitWithCode(20); + (window as any).daedalusExitCode = 20; + window.close(); return resolve(response(true, functionPrefix)); }); }); diff --git a/source/main/utils/buildAppMenus.ts b/source/main/utils/buildAppMenus.ts index 31ee34b3d7..66be625f1f 100644 --- a/source/main/utils/buildAppMenus.ts +++ b/source/main/utils/buildAppMenus.ts @@ -4,7 +4,6 @@ import { environment } from '../environment'; import { winLinuxMenu } from '../menus/win-linux'; import { osxMenu } from '../menus/osx'; import { logger } from './logging'; -import { safeExitWithCode } from './safeExitWithCode'; import { CardanoNode } from '../cardano/CardanoNode'; import { DIALOGS, PAGES } from '../../common/ipc/constants'; import { showUiPartChannel } from '../ipc/control-ui-parts'; @@ -64,7 +63,10 @@ export const buildAppMenus = async ( logger.info('Exiting Daedalus with code 21', { code: 21, }); - safeExitWithCode(21); + // We have to make sure that cardano-node exits, otherwise we get DB locked errors at startup: + // WRONG: safeExitWithCode(21); + (mainWindow as any).daedalusExitCode = 21; + mainWindow.close(); }; const restartWithoutBlankScreenFix = async () => { @@ -75,7 +77,10 @@ export const buildAppMenus = async ( logger.info('Exiting Daedalus with code 22', { code: 22, }); - safeExitWithCode(22); + // We have to make sure that cardano-node exits, otherwise we get DB locked errors at startup: + // WRONG: safeExitWithCode(22); + (mainWindow as any).daedalusExitCode = 22; + mainWindow.close(); }; const toggleBlankScreenFix = async (item) => {