diff --git a/src/commands/addLocalAddon.ts b/src/commands/addAddon.ts similarity index 79% rename from src/commands/addLocalAddon.ts rename to src/commands/addAddon.ts index d06f337..b04247a 100644 --- a/src/commands/addLocalAddon.ts +++ b/src/commands/addAddon.ts @@ -1,9 +1,9 @@ -import type { LocalAddon } from "@/types/addon"; -import { useLocalAddonsStore } from "@/stores/localAddons.store"; +import { useAddonStore } from "@/stores/addonStore"; +import type { Addon } from "@/types/addon"; type Message = { data: { - addons: LocalAddon | LocalAddon[]; + addons: Addon[]; }; }; @@ -13,7 +13,7 @@ type Message = { * @param message The message from VS Code * */ export default (message: Message) => { - const addonStore = useLocalAddonsStore(); + const addonStore = useAddonStore(); const addons = Array.isArray(message.data.addons) ? message.data.addons diff --git a/src/commands/addRemoteAddon.ts b/src/commands/addRemoteAddon.ts deleted file mode 100644 index 6a335e5..0000000 --- a/src/commands/addRemoteAddon.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { useRemoteAddonStore } from "@/stores/remoteAddons"; -import type { RemoteAddon } from "@/types/addon"; - -type Message = { - data: { - addons: RemoteAddon | RemoteAddon[]; - }; -}; - -/** Receives a `RemoteAddon` or array of `RemoteAddon`s. Updates the - * `remoteAddonsStore` state to contain the new addons. If the store already - * contains an addon with the same name, it will be overwritten. - * @param message The message from VS Code - * */ -export default (message: Message) => { - const addonStore = useRemoteAddonStore(); - - const addons = Array.isArray(message.data.addons) - ? message.data.addons - : [message.data.addons]; - - addonStore.$patch((state) => { - for (const newAddon of addons) { - const index = state.addons.findIndex( - (addon) => addon.name === newAddon.name - ); - - if (index > -1) { - Object.assign(state.addons[index], newAddon); - } else { - state.addons.push(newAddon); - } - } - }); -}; diff --git a/src/commands/localAddonStore.ts b/src/commands/addonStore.ts similarity index 70% rename from src/commands/localAddonStore.ts rename to src/commands/addonStore.ts index fd62246..805a9f0 100644 --- a/src/commands/localAddonStore.ts +++ b/src/commands/addonStore.ts @@ -1,4 +1,4 @@ -import { useLocalAddonsStore } from "@/stores/localAddons.store"; +import { useAddonStore } from "@/stores/addonStore"; type Message = { data: { @@ -9,7 +9,7 @@ type Message = { /** Set a value in the `localAddonStore` state */ export default (message: Message) => { - const localAddonStore = useLocalAddonsStore(); + const localAddonStore = useAddonStore(); const { property, value } = message.data; diff --git a/src/commands/index.ts b/src/commands/index.ts index 6e832c5..ab84ff3 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,17 +1,13 @@ -import addLocalAddon from "./addLocalAddon"; -import removeLocalAddon from "./removeLocalAddon"; -import addRemoteAddon from "./addRemoteAddon"; import workspaceOpen from "./workspaceOpen"; -import localAddonStore from "./localAddonStore"; -import remoteAddonStore from "./remoteAddonStore"; +import localAddonStore from "./addonStore"; import appStore from "./appStore"; +import addAddon from "./addAddon"; +import addonStore from "./addonStore"; export const commands: { [index: string]: (data: any) => any } = { - addLocalAddon, - removeLocalAddon, - addRemoteAddon, workspaceOpen, localAddonStore, - remoteAddonStore, appStore, + addAddon, + addonStore, }; diff --git a/src/commands/remoteAddonStore.ts b/src/commands/remoteAddonStore.ts deleted file mode 100644 index 47db061..0000000 --- a/src/commands/remoteAddonStore.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { useRemoteAddonStore } from "@/stores/remoteAddons"; - -type Message = { - data: { - property: string; - value: unknown; - }; -}; - -/** Set a value in the `remoteAddonStore` state */ -export default (message: Message) => { - const remoteAddonStore = useRemoteAddonStore(); - - const { property, value } = message.data; - - //@ts-ignore - remoteAddonStore[property] = value; -}; diff --git a/src/commands/removeLocalAddon.ts b/src/commands/removeLocalAddon.ts deleted file mode 100644 index 1d38d4a..0000000 --- a/src/commands/removeLocalAddon.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { useLocalAddonsStore } from "@/stores/localAddons.store"; - -/** Remove a `LocalAddon` from the `localAddonStore` state. - * - * Used when uninstalling an addon. */ -export default (message: { data: { name: string } }) => { - const addonStore = useLocalAddonsStore(); - - const index = addonStore.addons.findIndex((addon) => { - return addon.name === message.data.name; - }); - - if (index < 0) { - console.warn(`Could not find "${message.data.name}" addon to remove`); - return; - } - - addonStore.$patch((state) => { - state.addons.splice(index, 1); - }); -}; diff --git a/src/components/Addon.vue b/src/components/Addon.vue index f5d9b0c..030b059 100644 --- a/src/components/Addon.vue +++ b/src/components/Addon.vue @@ -6,7 +6,9 @@ {{ addon.displayName ?? addon.name }} - + Has Plugin

@@ -19,7 +21,7 @@

- +
- + + Update + + + Enable + + + Disable + + + Uninstall +
@@ -45,6 +75,16 @@ import CodeIcon from "./CodeIcon.vue"; import { REPOSITORY_OWNER, REPOSITORY_NAME, ADDONS_DIRECTORY } from "@/config"; import { computed } from "vue"; import { formatBytes } from "@/services/format.service"; +import { vscode } from "@/services/vscode.service"; +import { + vsCodeButton, + provideVSCodeDesignSystem, +} from "@vscode/webview-ui-toolkit"; +import { useAddonStore } from "@/stores/addonStore"; + +provideVSCodeDesignSystem().register(vsCodeButton()); + +const addonStore = useAddonStore(); const props = defineProps<{ addon: Addon }>(); @@ -54,6 +94,43 @@ const description = computed(() => props.addon.description ?? "No description"); const size = computed(() => props.addon.size ? formatBytes(props.addon.size) : "? B" ); +const canBeEnabled = computed(() => + props.addon.enabled?.some((v) => v === false) +); +const canBeDisabled = computed(() => + props.addon.enabled?.some((v) => v === true) +); + +const lockAddon = () => { + const addon = addonStore.getAddon(props.addon.name); + + if (!addon) { + console.warn(`Could not lock "${props.addon.name}" addon during operation`); + return; + } + + addon.processing = true; +}; + +const open = () => { + vscode.postMessage("open", { name: props.addon.name }); +}; +const update = () => { + lockAddon(); + vscode.postMessage("update", { name: props.addon.name }); +}; +const enable = () => { + lockAddon(); + vscode.postMessage("enable", { name: props.addon.name }); +}; +const disable = () => { + lockAddon(); + vscode.postMessage("disable", { name: props.addon.name }); +}; +const uninstall = () => { + lockAddon(); + vscode.postMessage("uninstall", { name: props.addon.name }); +};