2021-02-06 13:05:00 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div class="_formRoot">
|
|
|
|
<FormLink to="/settings/plugin/install"
|
|
|
|
><template #icon
|
|
|
|
><i class="ph-download-simple ph-bold ph-lg"></i></template
|
|
|
|
>{{ i18n.ts._plugin.install }}</FormLink
|
|
|
|
>
|
|
|
|
|
|
|
|
<FormSection>
|
|
|
|
<template #label>{{ i18n.ts.manage }}</template>
|
|
|
|
<div
|
|
|
|
v-for="plugin in plugins"
|
|
|
|
:key="plugin.id"
|
|
|
|
class="_formBlock _panel"
|
|
|
|
style="padding: 20px"
|
|
|
|
>
|
|
|
|
<span style="display: flex"
|
|
|
|
><b>{{ plugin.name }}</b
|
|
|
|
><span style="margin-left: auto"
|
|
|
|
>v{{ plugin.version }}</span
|
|
|
|
></span
|
|
|
|
>
|
|
|
|
|
|
|
|
<FormSwitch
|
|
|
|
class="_formBlock"
|
|
|
|
:model-value="plugin.active"
|
|
|
|
@update:modelValue="changeActive(plugin, $event)"
|
|
|
|
>{{ i18n.ts.makeActive }}</FormSwitch
|
|
|
|
>
|
|
|
|
|
|
|
|
<MkKeyValue class="_formBlock">
|
|
|
|
<template #key>{{ i18n.ts.author }}</template>
|
|
|
|
<template #value>{{ plugin.author }}</template>
|
|
|
|
</MkKeyValue>
|
|
|
|
<MkKeyValue class="_formBlock">
|
|
|
|
<template #key>{{ i18n.ts.description }}</template>
|
|
|
|
<template #value>{{ plugin.description }}</template>
|
|
|
|
</MkKeyValue>
|
|
|
|
<MkKeyValue class="_formBlock">
|
|
|
|
<template #key>{{ i18n.ts.permission }}</template>
|
|
|
|
<template #value>{{ plugin.permission }}</template>
|
|
|
|
</MkKeyValue>
|
|
|
|
|
|
|
|
<div style="display: flex; gap: var(--margin); flex-wrap: wrap">
|
|
|
|
<MkButton
|
|
|
|
v-if="plugin.config"
|
|
|
|
inline
|
|
|
|
@click="config(plugin)"
|
|
|
|
><i class="ph-gear-six ph-bold ph-lg"></i>
|
|
|
|
{{ i18n.ts.settings }}</MkButton
|
|
|
|
>
|
|
|
|
<MkButton inline danger @click="uninstall(plugin)"
|
|
|
|
><i class="ph-trash ph-bold ph-lg"></i>
|
|
|
|
{{ i18n.ts.uninstall }}</MkButton
|
|
|
|
>
|
|
|
|
</div>
|
2022-01-04 09:52:44 +01:00
|
|
|
</div>
|
2023-04-08 02:01:42 +02:00
|
|
|
</FormSection>
|
|
|
|
</div>
|
2021-02-06 13:05:00 +01:00
|
|
|
</template>
|
|
|
|
|
2022-05-04 03:11:35 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { nextTick, ref } from "vue";
|
|
|
|
import FormLink from "@/components/form/link.vue";
|
|
|
|
import FormSwitch from "@/components/form/switch.vue";
|
|
|
|
import FormSection from "@/components/form/section.vue";
|
|
|
|
import MkButton from "@/components/MkButton.vue";
|
|
|
|
import MkKeyValue from "@/components/MkKeyValue.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { ColdDeviceStorage } from "@/store";
|
|
|
|
import { unisonReload } from "@/scripts/unison-reload";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
|
|
|
|
|
|
|
const plugins = ref(ColdDeviceStorage.get("plugins"));
|
2022-05-04 03:11:35 +02:00
|
|
|
|
|
|
|
function uninstall(plugin) {
|
2023-04-08 02:01:42 +02:00
|
|
|
ColdDeviceStorage.set(
|
|
|
|
"plugins",
|
|
|
|
plugins.value.filter((x) => x.id !== plugin.id)
|
|
|
|
);
|
2022-05-04 03:11:35 +02:00
|
|
|
os.success();
|
|
|
|
nextTick(() => {
|
|
|
|
unisonReload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: この処理をstore側にactionとして移動し、設定画面を開くAiScriptAPIを実装できるようにする
|
|
|
|
async function config(plugin) {
|
|
|
|
const config = plugin.config;
|
|
|
|
for (const key in plugin.configData) {
|
|
|
|
config[key].default = plugin.configData[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
const { canceled, result } = await os.form(plugin.name, config);
|
|
|
|
if (canceled) return;
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const coldPlugins = ColdDeviceStorage.get("plugins");
|
|
|
|
coldPlugins.find((p) => p.id === plugin.id)!.configData = result;
|
|
|
|
ColdDeviceStorage.set("plugins", coldPlugins);
|
2022-05-04 03:11:35 +02:00
|
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeActive(plugin, active) {
|
2023-04-08 02:01:42 +02:00
|
|
|
const coldPlugins = ColdDeviceStorage.get("plugins");
|
|
|
|
coldPlugins.find((p) => p.id === plugin.id)!.active = active;
|
|
|
|
ColdDeviceStorage.set("plugins", coldPlugins);
|
2022-05-04 03:11:35 +02:00
|
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.plugins,
|
2023-04-08 02:01:42 +02:00
|
|
|
icon: "ph-plug ph-bold ph-lg",
|
2021-02-06 13:05:00 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<style lang="scss" scoped></style>
|