mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
prevent uninstall multiple click (#567)
This commit is contained in:
parent
c50a0058b3
commit
f0e1af6253
3 changed files with 51 additions and 21 deletions
|
@ -19,16 +19,40 @@
|
|||
|
||||
export let pkg: GUIPackage;
|
||||
let installing = false;
|
||||
let pruning = false;
|
||||
let uninstalling = false;
|
||||
|
||||
const install = async (version: string) => {
|
||||
if (installing) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
installing = true;
|
||||
await packagesStore.installPkg(pkg, version);
|
||||
} finally {
|
||||
installing = false;
|
||||
}
|
||||
};
|
||||
|
||||
const uninstall = async () => {
|
||||
if (uninstalling) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
uninstalling = true;
|
||||
await packagesStore.uninstallPkg(pkg);
|
||||
} finally {
|
||||
uninstalling = false;
|
||||
}
|
||||
};
|
||||
|
||||
const prune = async () => {
|
||||
pruning = true;
|
||||
if (uninstalling) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
uninstalling = true;
|
||||
const versions = (pkg?.installed_versions || []).sort((a, b) => semverCompare(b, a));
|
||||
for (const [i, v] of versions.entries()) {
|
||||
if (i) {
|
||||
|
@ -40,7 +64,9 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
pruning = false;
|
||||
} finally {
|
||||
uninstalling = false;
|
||||
}
|
||||
};
|
||||
|
||||
let copied = false;
|
||||
|
@ -100,10 +126,8 @@
|
|||
class="h-10"
|
||||
type="plain"
|
||||
color="blue"
|
||||
onClick={async () => {
|
||||
packagesStore.uninstallPkg(pkg);
|
||||
}}
|
||||
loading={pruning}
|
||||
onClick={uninstall}
|
||||
loading={uninstalling}
|
||||
>
|
||||
<div class="version-item flex w-full items-center justify-center gap-x-1 text-xs">
|
||||
<div class="icon-trash" />
|
||||
|
@ -125,7 +149,7 @@
|
|||
type="plain"
|
||||
color="blue"
|
||||
onClick={prune}
|
||||
loading={pruning}
|
||||
loading={uninstalling}
|
||||
>
|
||||
<div class="version-item flex w-full items-center justify-center gap-x-1 text-xs">
|
||||
<div class="icon-scissors" />
|
||||
|
|
|
@ -27,6 +27,7 @@ import withRetry from "$libs/utils/retry";
|
|||
|
||||
import log from "$libs/logger";
|
||||
import { isPackageUpToDate } from "../packages/pkg-utils";
|
||||
import withDelay from "$libs/utils/delay";
|
||||
|
||||
const packageRefreshInterval = 1000 * 60 * 60; // 1 hour
|
||||
|
||||
|
@ -254,11 +255,11 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
await deletePkg(pkg, v);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
await withDelay(() => {
|
||||
updatePackage(pkg.full_name, {
|
||||
installed_versions: []
|
||||
});
|
||||
}, 3000);
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
notificationStore.add({
|
||||
|
|
5
modules/desktop/src/libs/utils/delay.ts
Normal file
5
modules/desktop/src/libs/utils/delay.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
// withDelay adds a delay before calling the provided function.
|
||||
export default async function withDelay<T>(f: () => T, delayMs: number) {
|
||||
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||
return f();
|
||||
}
|
Loading…
Reference in a new issue