Skip to content

Commit c0c0d85

Browse files
committed
plugin manager
1 parent 0007420 commit c0c0d85

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
node_modules
23
dist
34
pnpm-lock.yaml

src/PluginManager.vue

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<script setup lang="ts">
2+
import type { UploadFileInfo } from 'naive-ui'
3+
import { NA, NFlex, NList, NListItem, NUpload, NUploadDragger, useMessage } from 'naive-ui'
4+
import { computed, ref } from 'vue'
5+
6+
const message = useMessage()
7+
8+
function getInstalledPlugins() {
9+
return window.fcitx.getInstalledPlugins().sort()
10+
}
11+
12+
const allPlugins = ['anthy', 'chewing', 'chinese-addons', 'hallelujah', 'hangul', 'lua', 'rime', 'sayura', 'thai', 'unikey']
13+
const installedPlugins = ref<string[]>(getInstalledPlugins())
14+
const availablePlugins = computed(() => allPlugins.filter(plugin => !installedPlugins.value.includes(plugin)))
15+
16+
const fileList = ref<UploadFileInfo[]>([])
17+
18+
async function onUpload(files: UploadFileInfo[]) {
19+
// Must clear the fileList synchronously first as uploading multiple files will trigger multiple times.
20+
fileList.value = []
21+
for (const file of files) {
22+
let name: string
23+
const buffer = await file.file!.arrayBuffer()
24+
try {
25+
name = window.fcitx.installPlugin(buffer)
26+
}
27+
catch (e: any) {
28+
message.error(e.message)
29+
continue
30+
}
31+
window.fcitx.updateStatusArea()
32+
installedPlugins.value = getInstalledPlugins()
33+
message.success(`Installed ${name}`)
34+
}
35+
}
36+
</script>
37+
38+
<template>
39+
<NFlex size="large">
40+
<NUpload v-model:file-list="fileList" style="width: auto" multiple accept=".zip" @update:file-list="onUpload">
41+
<NUploadDragger style="height: 200px">
42+
Download and drag zip to this area
43+
</NUploadDragger>
44+
</NUpload>
45+
<NFlex>
46+
<NList style="min-width: 100px">
47+
<template #header>
48+
Installed
49+
</template>
50+
<NListItem v-for="plugin in installedPlugins" :key="plugin">
51+
{{ plugin }}
52+
</NListItem>
53+
</NList>
54+
<NList style="min-width: 100px">
55+
<template #header>
56+
Available
57+
</template>
58+
<NListItem v-for="plugin in availablePlugins" :key="plugin">
59+
<NA :href="`https://github.com/fcitx-contrib/fcitx5-plugins/releases/download/js/${plugin}.zip`">
60+
{{ plugin }}
61+
</NA>
62+
</NListItem>
63+
</NList>
64+
</NFlex>
65+
</NFlex>
66+
</template>

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export { default as AdvancedConfig } from './AdvancedConfig.vue'
22
export { default as GearButton } from './GearButton.vue'
33
export { default as GlobalConfig } from './GlobalConfig.vue'
44
export { default as InputMethodConfig } from './InputMethodConfig.vue'
5+
export { default as PluginManager } from './PluginManager.vue'
56
export { default as ThemeConfig } from './ThemeConfig.vue'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy