mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
prune package (#419)
* #417 prune init * #417 prune package: delete pkg version * bump v0.0.26 --------- Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
parent
07ad1321e5
commit
0246c2577a
15 changed files with 105 additions and 8 deletions
|
@ -5,7 +5,7 @@ import { readSessionData, writeSessionData } from "./auth";
|
|||
import type { Session } from "../../src/libs/types";
|
||||
import * as log from "electron-log";
|
||||
import { post } from "./v1-client";
|
||||
import { deepReadDir } from "./tea-dir";
|
||||
import { deepReadDir, deletePackageFolder } from "./tea-dir";
|
||||
import path from "path";
|
||||
|
||||
import { installPackage, openTerminal } from "./cli";
|
||||
|
@ -141,4 +141,19 @@ export default function initializeHandlers() {
|
|||
app.dock.setBadge("");
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle(
|
||||
"delete-package",
|
||||
async (_, { fullName, version }: { fullName: string; version: string }) => {
|
||||
let error = "";
|
||||
try {
|
||||
log.info("deleting package:", fullName);
|
||||
await deletePackageFolder(fullName, version);
|
||||
} catch (e) {
|
||||
log.error(e);
|
||||
error = e.message;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -160,3 +160,12 @@ export async function updatePackageInstalledList(list: InstalledPackage[]) {
|
|||
log.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePackageFolder(fullName, version) {
|
||||
try {
|
||||
const foldPath = path.join(getTeaPath(), fullName, version);
|
||||
await fs.rmSync(foldPath, { recursive: true, force: true });
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "tea",
|
||||
"version": "0.0.25",
|
||||
"version": "0.0.26",
|
||||
"private": true,
|
||||
"description": "tea gui app",
|
||||
"author": "tea.xyz",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import "@tea/ui/icons/icons.css";
|
||||
import { t } from '$libs/translations';
|
||||
import Button from "@tea/ui/button/button.svelte";
|
||||
import semverCompare from "semver/functions/compare";
|
||||
|
||||
import { installPackage } from "@native";
|
||||
import { PackageStates, type GUIPackage } from "$libs/types";
|
||||
|
@ -10,9 +11,11 @@
|
|||
import { shellOpenExternal } from "@native";
|
||||
import InstallButton from "$components/install-button/install-button.svelte";
|
||||
import { findAvailableVersions } from "$libs/packages/pkg-utils";
|
||||
|
||||
|
||||
export let pkg: GUIPackage;
|
||||
let installing = false;
|
||||
let pruning = false
|
||||
|
||||
const install = async () => {
|
||||
installing = true;
|
||||
|
@ -22,6 +25,17 @@
|
|||
state: PackageStates.INSTALLED
|
||||
});
|
||||
};
|
||||
|
||||
const prune = async () => {
|
||||
pruning = true;
|
||||
const versions = (pkg?.installed_versions || []).sort((a, b) => semverCompare(b, a));
|
||||
for(const [i,v] of versions.entries()) {
|
||||
if (i) { // skip the latest version = 0
|
||||
await packagesStore.deletePkg(pkg, v);
|
||||
}
|
||||
}
|
||||
pruning = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="mt-4 bg-black">
|
||||
|
@ -37,13 +51,27 @@
|
|||
</a>
|
||||
{/if}
|
||||
<p class="mt-4 text-sm">{pkg.desc}</p>
|
||||
<menu class="mt-4 grid h-10 grid-cols-2 gap-4 text-xs">
|
||||
<menu class="mt-4 grid h-10 grid-cols-3 gap-4 text-xs">
|
||||
<InstallButton
|
||||
buttonSize="large"
|
||||
{pkg}
|
||||
availableVersions={findAvailableVersions(pkg)}
|
||||
onClick={install}
|
||||
/>
|
||||
{#if (pkg?.installed_versions?.length || 0) > 1}
|
||||
<Button
|
||||
class="h-10"
|
||||
type="plain"
|
||||
color="blue"
|
||||
onClick={prune}
|
||||
loading={pruning}
|
||||
>
|
||||
<div class="w-full version-item flex items-center justify-center gap-x-1 text-xs" >
|
||||
<div class="icon-scissors"/>
|
||||
<div>{$t("package.cta-PRUNE")}</div>
|
||||
</div>
|
||||
</Button>
|
||||
{/if}
|
||||
{#if pkg.github}
|
||||
<Button
|
||||
class="h-10"
|
||||
|
|
|
@ -227,3 +227,11 @@ export const setBadgeCount = async (count: number) => {
|
|||
log.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const deletePackage = async (args: { fullName: string; version: string }) => {
|
||||
try {
|
||||
await ipcRenderer.invoke("delete-package", args);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -348,3 +348,7 @@ export const isPackageInstalled = async (_v?: string): Promise<boolean> => {
|
|||
export const setBadgeCount = async (count: number) => {
|
||||
console.log("set badge count", count);
|
||||
};
|
||||
|
||||
export const deletePackage = async (args: { fullName: string; version: string }) => {
|
||||
console.log("delete package", args);
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
getDistPackages,
|
||||
getInstalledPackages,
|
||||
installPackage,
|
||||
deletePackage,
|
||||
getPackageBottles,
|
||||
setBadgeCount
|
||||
} from "@native";
|
||||
|
@ -166,6 +167,18 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
updatePackage(pkgName, { bottles });
|
||||
};
|
||||
|
||||
const deletePkg = async (pkg: GUIPackage, version: string) => {
|
||||
try {
|
||||
log.info("deleting package: ", pkg.full_name, " version: ", version);
|
||||
await deletePackage({ fullName: pkg.full_name, version });
|
||||
updatePackage(pkg.full_name, {
|
||||
installed_versions: pkg.installed_versions?.filter((v) => v !== version)
|
||||
});
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
packages,
|
||||
syncProgress,
|
||||
|
@ -191,7 +204,8 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
updatePackage,
|
||||
init,
|
||||
installPkg,
|
||||
syncPackageData
|
||||
syncPackageData,
|
||||
deletePkg
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
"cta-INSTALLING": "INSTALLING",
|
||||
"cta-UNINSTALLED": "RE-INSTALL",
|
||||
"cta-NEEDS_UPDATE": "UPDATE",
|
||||
"cta-UPDATING": "UPDATING"
|
||||
"cta-UPDATING": "UPDATING",
|
||||
"cta-PRUNE": "PRUNE",
|
||||
"cta-PRUNING": "PRUNING"
|
||||
},
|
||||
"footer": {
|
||||
"quick-links-title": "quick links",
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
export let active = false;
|
||||
|
||||
export let type: "outline" | "ghost" | "plain" = "ghost";
|
||||
export let color: "primary" | "secondary" | "green" | "black" = "primary";
|
||||
export let color: "primary" | "secondary" | "green" | "black" | "blue" = "primary";
|
||||
|
||||
export let loading = false;
|
||||
</script>
|
||||
|
@ -16,8 +16,9 @@
|
|||
<div class="button-container">
|
||||
<button
|
||||
type="button"
|
||||
class={`w-full p-2 text-gray ${clazz} ${active ? "active" : ""} ${type} ${color}`}
|
||||
class:animate-puls={loading}
|
||||
class={`w-full p-2 text-gray ${clazz} ${type} ${color}`}
|
||||
class:active
|
||||
class:animate-pulse={loading}
|
||||
on:click={() => onClick && onClick()}
|
||||
>
|
||||
<slot />
|
||||
|
@ -115,4 +116,14 @@
|
|||
color: #1a1a1a;
|
||||
background: #e1e1e1;
|
||||
}
|
||||
|
||||
/* green */
|
||||
button.plain.blue {
|
||||
background: #013b99;
|
||||
color: white;
|
||||
}
|
||||
|
||||
button.blue::before {
|
||||
background: #2675f5;
|
||||
}
|
||||
</style>
|
||||
|
|
Binary file not shown.
|
@ -55,4 +55,5 @@
|
|||
<glyph glyph-name="latest-version" unicode="T" d="M412 509l-312 0c-42 0-77-35-77-77l0-312c0-42 35-77 77-77l180 0 0-40 110 64-110 64 0-41-180 0c-16 0-30 14-30 30l0 312c0 17 14 30 30 30l305 0-189-221-66 57-30-35 100-89 222 260c0 0 0-2 0-2l0-365 46 0 0 365c0 42-34 77-77 77z"/>
|
||||
<glyph glyph-name="arrow-left" unicode="U" d="M512 288l-389 0 178 179-45 45-256-256 256-256 45 45-178 179 389 0z"/>
|
||||
<glyph glyph-name="arrow-right" unicode="V" d="M0 224l389 0-178-179 45-45 256 256-256 256-45-45 178-179-389 0z"/>
|
||||
<glyph glyph-name="scissors" unicode="X" d="M274 256c5 0 10-2 13-5 4-4 6-8 6-13 0-5-2-10-6-13-3-4-8-6-13-6-5 0-9 2-13 6-3 3-5 8-5 13 0 5 2 9 5 13 4 3 8 5 13 5z m86-18l145-114c5-4 8-9 7-16-1-7-4-12-10-15l-37-18c-2-1-5-2-8-2-3 0-6 1-9 2l-197 111-31-19c-2-1-3-1-4-1 3-10 4-19 3-28-1-15-7-29-16-42-9-14-22-25-38-35-25-16-51-24-79-24-26 0-47 7-63 22-17 16-25 36-23 59 2 14 7 28 16 42 10 14 22 25 38 35 25 16 51 24 79 24 16 0 30-3 43-8 2 2 4 4 7 6l34 21-34 21c-3 1-5 3-7 6-13-6-27-9-43-9-28 0-54 8-79 24-16 10-28 22-38 35-9 14-14 28-16 42-1 12 1 22 5 33 4 10 10 19 18 26 16 15 37 23 63 23 28 0 54-8 79-24 16-10 29-22 38-35 9-14 15-28 16-43 1-9 0-18-3-27 1 0 2-1 4-2l31-19 197 111c3 2 6 2 9 2 3 0 6 0 8-2l37-18c6-3 9-8 10-15 1-6-2-12-7-16z m-195 74c9 8 11 18 6 31-4 12-14 24-30 33-17 12-36 17-55 17-14 0-25-3-32-10-9-8-11-18-6-31 5-13 15-24 30-33 18-12 36-17 55-17 14 0 25 3 32 10z m-24-213c16 10 26 21 30 34 5 12 3 22-6 30-7 7-18 11-32 11-19 0-37-6-55-17-15-10-25-21-30-34-5-12-3-22 6-30 7-7 18-11 32-11 19 0 38 6 55 17z m51 175l27-16 0 3c0 7 4 12 10 16l4 2-23 14-7-8c-1 0-2-1-3-3-1-2-2-3-3-3-1-1-1-1-2-1 0-1 0-1 0-1z m64-64l27-9 211 165-37 18-219-123 0-32-46-28 3-2c0-1 1-1 2-2 0-1 1-2 3-3 1-2 2-3 3-4l7-7z m201-119l37 19-149 116-50-39c-1-1-2-1-4-2z"/>
|
||||
</font></defs></svg>
|
||||
|
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 25 KiB |
Binary file not shown.
Binary file not shown.
|
@ -181,3 +181,6 @@
|
|||
.icon-arrow-right:before {
|
||||
content: "\56";
|
||||
}
|
||||
.icon-scissors:before {
|
||||
content: "\58";
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ const white = "#fff";
|
|||
const gray = "#949494";
|
||||
const purple = "#8000FF";
|
||||
const green = "#00A517";
|
||||
const blue = "#013B99";
|
||||
|
||||
module.exports = {
|
||||
content: ["./src/**/*.{html,js,svelte,ts}"],
|
||||
|
@ -15,6 +16,7 @@ module.exports = {
|
|||
accent: purple,
|
||||
green,
|
||||
teal,
|
||||
blue,
|
||||
purple: {
|
||||
700: purple,
|
||||
900: "#B076EC"
|
||||
|
|
Loading…
Reference in a new issue