enhance(frontend): improve plugin management
This commit is contained in:
@@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
</MkCodeEditor>
|
||||
|
||||
<div>
|
||||
<MkButton :disabled="code == null" primary inline @click="install"><i class="ti ti-check"></i> {{ i18n.ts.install }}</MkButton>
|
||||
<MkButton :disabled="code == null || code.trim() === ''" primary inline @click="install"><i class="ti ti-check"></i> {{ i18n.ts.install }}</MkButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -23,11 +23,12 @@ import MkCodeEditor from '@/components/MkCodeEditor.vue';
|
||||
import MkButton from '@/components/MkButton.vue';
|
||||
import FormInfo from '@/components/MkInfo.vue';
|
||||
import * as os from '@/os.js';
|
||||
import { unisonReload } from '@/utility/unison-reload.js';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import { definePageMetadata } from '@/utility/page-metadata.js';
|
||||
import { installPlugin } from '@/plugin.js';
|
||||
import { useRouter } from '@/router/supplier.js';
|
||||
|
||||
const router = useRouter();
|
||||
const code = ref<string | null>(null);
|
||||
|
||||
async function install() {
|
||||
@@ -36,6 +37,9 @@ async function install() {
|
||||
try {
|
||||
await installPlugin(code.value);
|
||||
os.success();
|
||||
code.value = null;
|
||||
|
||||
router.push('/settings/plugin');
|
||||
} catch (err) {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
|
||||
@@ -14,7 +14,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
<MkFolder v-for="plugin in plugins" :key="plugin.installId">
|
||||
<template #icon><i class="ti ti-plug"></i></template>
|
||||
<template #suffix>
|
||||
<i v-if="plugin.active" class="ti ti-player-play" style="color: var(--MI_THEME-accent);"></i>
|
||||
<i v-if="plugin.active" class="ti ti-player-play" style="color: var(--MI_THEME-success);"></i>
|
||||
<i v-else class="ti ti-player-pause" style="opacity: 0.7;"></i>
|
||||
</template>
|
||||
<template #label>
|
||||
@@ -59,23 +59,27 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
</MkKeyValue>
|
||||
</div>
|
||||
|
||||
<MkFolder>
|
||||
<template #icon><i class="ti ti-terminal-2"></i></template>
|
||||
<template #label>{{ i18n.ts._plugin.viewLog }}</template>
|
||||
<div class="_gaps_s">
|
||||
<MkFolder>
|
||||
<template #icon><i class="ti ti-terminal-2"></i></template>
|
||||
<template #label>{{ i18n.ts.logs }}</template>
|
||||
|
||||
<div class="_gaps_s">
|
||||
<MkCode :code="pluginLogs.get(plugin.installId)?.join('\n') ?? ''"/>
|
||||
</div>
|
||||
</MkFolder>
|
||||
<div>
|
||||
<div v-for="log in pluginLogs.get(plugin.installId)" :class="[$style.log, { [$style.isSystemLog]: log.isSystem }]">
|
||||
<div class="_monospace">{{ timeToHhMmSs(log.at) }} {{ log.message }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</MkFolder>
|
||||
|
||||
<MkFolder>
|
||||
<template #icon><i class="ti ti-code"></i></template>
|
||||
<template #label>{{ i18n.ts._plugin.viewSource }}</template>
|
||||
<MkFolder :withSpacer="false">
|
||||
<template #icon><i class="ti ti-code"></i></template>
|
||||
<template #label>{{ i18n.ts._plugin.viewSource }}</template>
|
||||
|
||||
<div class="_gaps_s">
|
||||
<MkCode :code="plugin.src ?? ''" lang="ais"/>
|
||||
</div>
|
||||
</MkFolder>
|
||||
<div class="_gaps_s">
|
||||
<MkCode :code="plugin.src ?? ''" lang="ais"/>
|
||||
</div>
|
||||
</MkFolder>
|
||||
</div>
|
||||
</div>
|
||||
</MkFolder>
|
||||
</div>
|
||||
@@ -98,11 +102,20 @@ import { i18n } from '@/i18n.js';
|
||||
import { definePageMetadata } from '@/utility/page-metadata.js';
|
||||
import { changePluginActive, configPlugin, pluginLogs, uninstallPlugin, reloadPlugin } from '@/plugin.js';
|
||||
import { prefer } from '@/preferences.js';
|
||||
import * as os from '@/os.js';
|
||||
|
||||
const plugins = prefer.r.plugins;
|
||||
|
||||
async function uninstall(plugin: Plugin) {
|
||||
const { canceled } = await os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.tsx.removeAreYouSure({ x: plugin.name }),
|
||||
});
|
||||
if (canceled) return;
|
||||
|
||||
await uninstallPlugin(plugin);
|
||||
|
||||
os.success();
|
||||
}
|
||||
|
||||
function reload(plugin: Plugin) {
|
||||
@@ -117,6 +130,10 @@ function changeActive(plugin: Plugin, active: boolean) {
|
||||
changePluginActive(plugin, active);
|
||||
}
|
||||
|
||||
function timeToHhMmSs(unixtime: number) {
|
||||
return new Date(unixtime).toTimeString().split(' ')[0];
|
||||
}
|
||||
|
||||
const headerActions = computed(() => []);
|
||||
|
||||
const headerTabs = computed(() => []);
|
||||
@@ -126,3 +143,12 @@ definePageMetadata(() => ({
|
||||
icon: 'ti ti-plug',
|
||||
}));
|
||||
</script>
|
||||
|
||||
<style module>
|
||||
.log {
|
||||
}
|
||||
|
||||
.isSystemLog {
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -10,8 +10,8 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
</MkCodeEditor>
|
||||
|
||||
<div class="_buttons">
|
||||
<MkButton :disabled="installThemeCode == null" inline @click="() => previewTheme(installThemeCode)"><i class="ti ti-eye"></i> {{ i18n.ts.preview }}</MkButton>
|
||||
<MkButton :disabled="installThemeCode == null" primary inline @click="() => install(installThemeCode)"><i class="ti ti-check"></i> {{ i18n.ts.install }}</MkButton>
|
||||
<MkButton :disabled="installThemeCode == null || installThemeCode.trim() === ''" inline @click="() => previewTheme(installThemeCode)"><i class="ti ti-eye"></i> {{ i18n.ts.preview }}</MkButton>
|
||||
<MkButton :disabled="installThemeCode == null || installThemeCode.trim() === ''" primary inline @click="() => install(installThemeCode)"><i class="ti ti-check"></i> {{ i18n.ts.install }}</MkButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -24,7 +24,9 @@ import { parseThemeCode, previewTheme, installTheme } from '@/theme.js';
|
||||
import * as os from '@/os.js';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import { definePageMetadata } from '@/utility/page-metadata.js';
|
||||
import { useRouter } from '@/router/supplier.js';
|
||||
|
||||
const router = useRouter();
|
||||
const installThemeCode = ref<string | null>(null);
|
||||
|
||||
async function install(code: string): Promise<void> {
|
||||
@@ -35,6 +37,8 @@ async function install(code: string): Promise<void> {
|
||||
type: 'success',
|
||||
text: i18n.tsx._theme.installed({ name: theme.name }),
|
||||
});
|
||||
installThemeCode.value = null;
|
||||
router.push('/settings/theme');
|
||||
} catch (err) {
|
||||
switch (err.message.toLowerCase()) {
|
||||
case 'this theme is already installed':
|
||||
|
||||
Reference in New Issue
Block a user