Skip to content

Commit

Permalink
Fix cancelling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadwey committed Feb 3, 2024
1 parent 1c10f1e commit eac661b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/installer/Installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class DownloadAction extends Action {
cancel() {
this.abortController.abort();
this.writeStream.close();
this.emit("cancelled");
}

/**
Expand Down Expand Up @@ -264,6 +265,12 @@ export class Installer extends EventEmitter {
resolve();
});

action.on("cancelled", () => {
this.emit("cancelled");
this.failed = true;
resolve();
});

action.execute();
});
this.currentAction++;
Expand Down
5 changes: 5 additions & 0 deletions src/main/renderer_bridge/versionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ ipcMain.handle(IpcMessages.VERSION_MANAGER.INSTALL_VERSION, async (e, id, data)
installerProgress("data", data);
});

versionInstaller.on("cancelled", () => {
installerProgress("cancelled", id);
deleteInstaller(id);
});

versionInstaller.Start();
} catch (err) {
installerProgress("error", err);
Expand Down
5 changes: 4 additions & 1 deletion src/preload/versionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ipcRenderer.on(IpcMessages.VERSION_MANAGER.ON_VERSION_INSTALL_PROGRESS, (event,
switch (type) {
case "data":
installers[id]?.updateData(data);

break;
case "finish":
installers[id]?.finish();
Expand All @@ -44,6 +43,10 @@ ipcRenderer.on(IpcMessages.VERSION_MANAGER.ON_VERSION_INSTALL_PROGRESS, (event,
installers[id]?.error(data);
deleteInstaller(id);
break;
case "cancelled":
installers[id]?.cancelled();
deleteInstaller(id);
break;
default:
break;
}
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/Installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Installer {
Installer.emitter.emit("update");
resolve();
},
cancelled: () => {
this_.removeInstallationInternal(id);
Installer.emitter.emit("update");
},
error: (err) => {
this_.removeInstallationInternal(id);
Installer.emitter.emit("error", err);
Expand All @@ -60,7 +64,6 @@ class Installer {
cancel(id) {
cancelInstall(id);
this.removeInstallationInternal(id);
Installer.emitter.emit("update");
}

/**
Expand Down

0 comments on commit eac661b

Please sign in to comment.