1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-17 16:18:13 +09:00
hotomoe/packages/frontend/src/pages/settings/plugin.vue

99 lines
3.1 KiB
Vue
Raw Normal View History

2021-02-06 21:05:00 +09:00
<template>
2023-01-06 13:40:17 +09:00
<div class="_gaps_m">
<FormLink to="/settings/plugin/install"><template #icon><i class="ti ti-download"></i></template>{{ i18n.ts._plugin.install }}</FormLink>
2022-01-04 17:52:44 +09:00
<FormSection>
<template #label>{{ i18n.ts.manage }}</template>
2023-01-06 13:40:17 +09:00
<div v-for="plugin in plugins" :key="plugin.id" class="_panel _gaps_s" style="padding: 20px;">
2022-01-04 17:52:44 +09:00
<span style="display: flex;"><b>{{ plugin.name }}</b><span style="margin-left: auto;">v{{ plugin.version }}</span></span>
2023-01-05 21:04:56 +09:00
<FormSwitch :model-value="plugin.active" @update:model-value="changeActive(plugin, $event)">{{ i18n.ts.makeActive }}</FormSwitch>
2022-01-04 17:52:44 +09:00
2023-01-05 21:04:56 +09:00
<MkKeyValue>
<template #key>{{ i18n.ts.author }}</template>
2022-01-04 17:52:44 +09:00
<template #value>{{ plugin.author }}</template>
</MkKeyValue>
2023-01-05 21:04:56 +09:00
<MkKeyValue>
<template #key>{{ i18n.ts.description }}</template>
2022-01-04 17:52:44 +09:00
<template #value>{{ plugin.description }}</template>
</MkKeyValue>
2023-01-05 21:04:56 +09:00
<MkKeyValue>
<template #key>{{ i18n.ts.permission }}</template>
2022-01-04 17:52:44 +09:00
<template #value>{{ plugin.permission }}</template>
</MkKeyValue>
2023-01-06 09:41:14 +09:00
<div class="_buttons">
<MkButton v-if="plugin.config" inline @click="config(plugin)"><i class="ti ti-settings"></i> {{ i18n.ts.settings }}</MkButton>
<MkButton inline danger @click="uninstall(plugin)"><i class="ti ti-trash"></i> {{ i18n.ts.uninstall }}</MkButton>
2022-01-04 17:52:44 +09:00
</div>
</div>
</FormSection>
</div>
2021-02-06 21:05:00 +09:00
</template>
<script lang="ts" setup>
import { nextTick, ref } from 'vue';
2022-01-04 17:52:44 +09:00
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';
2021-11-12 02:02:25 +09:00
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'));
function uninstall(plugin) {
ColdDeviceStorage.set('plugins', plugins.value.filter(x => x.id !== plugin.id));
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;
const coldPlugins = ColdDeviceStorage.get('plugins');
coldPlugins.find(p => p.id === plugin.id)!.configData = result;
ColdDeviceStorage.set('plugins', coldPlugins);
nextTick(() => {
location.reload();
});
}
function changeActive(plugin, active) {
const coldPlugins = ColdDeviceStorage.get('plugins');
coldPlugins.find(p => p.id === plugin.id)!.active = active;
ColdDeviceStorage.set('plugins', coldPlugins);
nextTick(() => {
location.reload();
});
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
definePageMetadata({
title: i18n.ts.plugins,
icon: 'ti ti-plug',
2021-02-06 21:05:00 +09:00
});
</script>
<style lang="scss" scoped>
2021-02-06 21:05:00 +09:00
</style>