From 084c083c6d6bbcdb7bdbdec5a5492ea9c8e46376 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Mon, 20 Nov 2023 18:31:05 +0100 Subject: [PATCH] added support for options & patches --- .../src/components/ManifestInfo/index.jsx | 6 +- .../src/components/PackageItem/index.jsx | 23 +- .../src/components/PackageOptions/index.jsx | 201 ++++++++++++++++++ .../src/components/PackageOptions/index.less | 67 ++++++ 4 files changed, 288 insertions(+), 9 deletions(-) create mode 100644 src/renderer/src/components/PackageOptions/index.jsx create mode 100644 src/renderer/src/components/PackageOptions/index.less diff --git a/src/renderer/src/components/ManifestInfo/index.jsx b/src/renderer/src/components/ManifestInfo/index.jsx index 6ab8346..fee65e0 100644 --- a/src/renderer/src/components/ManifestInfo/index.jsx +++ b/src/renderer/src/components/ManifestInfo/index.jsx @@ -10,7 +10,7 @@ const ManifestInfo = (props) => { const [error, setError] = React.useState(null) async function handleInstall() { - await ipc.exec("bundle:install", props.manifest) + await ipc.exec("pkg:install", props.manifest) if (typeof props.close === "function") { props.close() @@ -21,7 +21,7 @@ const ManifestInfo = (props) => { setLoading(true) try { - const result = await ipc.exec("bundle:read", url) + const result = await ipc.exec("pkg:read", url) setManifest(JSON.parse(result)) @@ -58,7 +58,7 @@ const ManifestInfo = (props) => {

- {manifest.pack_name} + {manifest.name}

diff --git a/src/renderer/src/components/PackageItem/index.jsx b/src/renderer/src/components/PackageItem/index.jsx index c15c1e7..d593941 100644 --- a/src/renderer/src/components/PackageItem/index.jsx +++ b/src/renderer/src/components/PackageItem/index.jsx @@ -6,6 +6,8 @@ import BarLoader from "react-spinners/BarLoader" import { MdFolder, MdDelete, MdPlayArrow, MdUpdate, MdOutlineMoreVert, MdSettings, MdInfoOutline } from "react-icons/md" +import PackageOptions from "../PackageOptions" + import "./index.less" const PackageItem = (props) => { @@ -20,17 +22,17 @@ const PackageItem = (props) => { title: "Update", content: `Are you sure you want to update ${manifest.id}?`, onOk: () => { - ipc.exec("bundle:update", manifest.id) + ipc.exec("pkg:update", manifest.id) }, }) } const onClickPlay = () => { - ipc.exec("bundle:exec", manifest.id) + ipc.exec("pkg:exec", manifest.id) } const onClickFolder = () => { - ipc.exec("bundle:open", manifest.id) + ipc.exec("pkg:open", manifest.id) } const onClickDelete = () => { @@ -38,11 +40,20 @@ const PackageItem = (props) => { title: "Uninstall", content: `Are you sure you want to uninstall ${manifest.id}?`, onOk: () => { - ipc.exec("bundle:uninstall", manifest.id) + ipc.exec("pkg:uninstall", manifest.id) }, }) } + const onClickOptions = () => { + app.modal.open(PackageOptions, { + manifest: manifest, + close: () => { + app.modal.close() + } + }) + } + function handleUpdate(event, data) { setManifest({ ...manifest, @@ -76,7 +87,7 @@ const PackageItem = (props) => { key: "options", label: "Options", icon: , - disabled: true + onClick: onClickOptions, }, { type: "divider" @@ -123,7 +134,7 @@ const PackageItem = (props) => {

{ - manifest.pack_name + manifest.name ?? manifest.pack_name }

diff --git a/src/renderer/src/components/PackageOptions/index.jsx b/src/renderer/src/components/PackageOptions/index.jsx new file mode 100644 index 0000000..b5b5d34 --- /dev/null +++ b/src/renderer/src/components/PackageOptions/index.jsx @@ -0,0 +1,201 @@ +import React from "react" +import * as antd from "antd" + +import "./index.less" + +const Options = (props) => { + const { options = {} } = props + + if (Object.keys(options).length === 0) { + return

+ No options available +

+ } + + return Object.keys(options).map((key, index) => { + return
+ { + props.onChange(key, e) + }} + /> + + + {key} + +
+ }) +} + +const Patches = (props) => { + const { patches = [], applied_patches = [] } = props + + if (patches.length === 0) { + return

+ No patches available +

+ } + + return patches.map((patch, index) => { + const isInstalled = applied_patches.includes(patch.id) + + return
+ { + props.onChange(patch.id, e.target.checked) + }} + > + {patch.name} + +
+ }) +} + +const PackageOptions = (props) => { + const { manifest } = props + + const [changes, setChanges] = React.useState({ + options: manifest.options ?? {}, + patches: Object.fromEntries(manifest.patches.map((p) => { + return [p.id, manifest.applied_patches.includes(p.id)] + })) + }) + + function applyChanges() { + if (props.onClose) { + props.onClose() + } + if (props.close) { + props.close() + } + + ipc.exec("pkg:apply_changes", manifest.id, changes) + } + + function handleChanges(field, key, value) { + setChanges((prev) => { + return { + ...prev, + [field]: { + ...prev[field], + [key]: value + } + } + }) + } + + return
+
+
+

Options

+
+ +
+ { + handleChanges("options", key, value) + }} + /> +
+
+ +
+
+

Patches

+
+ +
+ { + handleChanges("patches", key, value) + }} + /> +
+
+ +
+
+
+ Package ID +
+ +
+ + {manifest.id} + +
+
+ +
+
+ Disk Usage +
+ +
+ + {manifest.disk_usage ?? "unknown"} + +
+
+ +
+
+ Install path +
+ +
+ + {manifest.install_path ?? "unknown"} + +
+
+ +
+
+ Manifest URL +
+ +
+

+ {manifest.remote_url ?? "unknown"} +

+
+
+ +
+
+ Version +
+ +
+

+ {manifest.version ?? "unknown"} +

+
+
+
+ +
+ + Apply + +
+
+} + +export default PackageOptions \ No newline at end of file diff --git a/src/renderer/src/components/PackageOptions/index.less b/src/renderer/src/components/PackageOptions/index.less new file mode 100644 index 0000000..850b13b --- /dev/null +++ b/src/renderer/src/components/PackageOptions/index.less @@ -0,0 +1,67 @@ +.package_options { + display: flex; + flex-direction: column; + + gap: 10px; + + font-size: 1rem; + + .package_options-field { + display: flex; + flex-direction: column; + + .package_options-field-header { + display: flex; + flex-direction: row; + + align-items: center; + + justify-content: space-between; + + font-size: 1rem; + } + + .package_options-field-body { + display: flex; + flex-direction: column; + + padding: 10px; + + gap: 5px; + } + } + + .ant-checkbox:not(.ant-checkbox-checked) { + .ant-checkbox-inner { + border-color: #fff; + } + } + + .package_options-info { + display: flex; + flex-direction: column; + + gap: 7px; + + font-size: 0.6rem; + + .package_options-info-item { + display: flex; + flex-direction: column; + + .package_options-info-item-label { + display: flex; + flex-direction: row; + } + + .package_options-info-item-value { + display: inline-flex; + flex-direction: row; + + align-items: center; + + padding-left: 5px; + } + } + } +} \ No newline at end of file