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,28 +19,54 @@
|
||||||
|
|
||||||
export let pkg: GUIPackage;
|
export let pkg: GUIPackage;
|
||||||
let installing = false;
|
let installing = false;
|
||||||
let pruning = false;
|
let uninstalling = false;
|
||||||
|
|
||||||
const install = async (version: string) => {
|
const install = async (version: string) => {
|
||||||
installing = true;
|
if (installing) {
|
||||||
await packagesStore.installPkg(pkg, version);
|
return;
|
||||||
installing = false;
|
}
|
||||||
|
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 () => {
|
const prune = async () => {
|
||||||
pruning = true;
|
if (uninstalling) {
|
||||||
const versions = (pkg?.installed_versions || []).sort((a, b) => semverCompare(b, a));
|
return;
|
||||||
for (const [i, v] of versions.entries()) {
|
}
|
||||||
if (i) {
|
|
||||||
// skip the latest version = 0
|
try {
|
||||||
try {
|
uninstalling = true;
|
||||||
await packagesStore.deletePkg(pkg, v);
|
const versions = (pkg?.installed_versions || []).sort((a, b) => semverCompare(b, a));
|
||||||
} catch (e) {
|
for (const [i, v] of versions.entries()) {
|
||||||
console.error(e);
|
if (i) {
|
||||||
|
// skip the latest version = 0
|
||||||
|
try {
|
||||||
|
await packagesStore.deletePkg(pkg, v);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
uninstalling = false;
|
||||||
}
|
}
|
||||||
pruning = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let copied = false;
|
let copied = false;
|
||||||
|
@ -100,10 +126,8 @@
|
||||||
class="h-10"
|
class="h-10"
|
||||||
type="plain"
|
type="plain"
|
||||||
color="blue"
|
color="blue"
|
||||||
onClick={async () => {
|
onClick={uninstall}
|
||||||
packagesStore.uninstallPkg(pkg);
|
loading={uninstalling}
|
||||||
}}
|
|
||||||
loading={pruning}
|
|
||||||
>
|
>
|
||||||
<div class="version-item flex w-full items-center justify-center gap-x-1 text-xs">
|
<div class="version-item flex w-full items-center justify-center gap-x-1 text-xs">
|
||||||
<div class="icon-trash" />
|
<div class="icon-trash" />
|
||||||
|
@ -125,7 +149,7 @@
|
||||||
type="plain"
|
type="plain"
|
||||||
color="blue"
|
color="blue"
|
||||||
onClick={prune}
|
onClick={prune}
|
||||||
loading={pruning}
|
loading={uninstalling}
|
||||||
>
|
>
|
||||||
<div class="version-item flex w-full items-center justify-center gap-x-1 text-xs">
|
<div class="version-item flex w-full items-center justify-center gap-x-1 text-xs">
|
||||||
<div class="icon-scissors" />
|
<div class="icon-scissors" />
|
||||||
|
|
|
@ -27,6 +27,7 @@ import withRetry from "$libs/utils/retry";
|
||||||
|
|
||||||
import log from "$libs/logger";
|
import log from "$libs/logger";
|
||||||
import { isPackageUpToDate } from "../packages/pkg-utils";
|
import { isPackageUpToDate } from "../packages/pkg-utils";
|
||||||
|
import withDelay from "$libs/utils/delay";
|
||||||
|
|
||||||
const packageRefreshInterval = 1000 * 60 * 60; // 1 hour
|
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);
|
await deletePkg(pkg, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
await withDelay(() => {
|
||||||
updatePackage(pkg.full_name, {
|
updatePackage(pkg.full_name, {
|
||||||
installed_versions: []
|
installed_versions: []
|
||||||
});
|
});
|
||||||
}, 3000);
|
}, 1000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(error);
|
log.error(error);
|
||||||
notificationStore.add({
|
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