Skip to content

Commit

Permalink
plugin manager
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Dec 17, 2024
1 parent 0007420 commit c0c0d85
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
dist
pnpm-lock.yaml
Expand Down
66 changes: 66 additions & 0 deletions src/PluginManager.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script setup lang="ts">
import type { UploadFileInfo } from 'naive-ui'
import { NA, NFlex, NList, NListItem, NUpload, NUploadDragger, useMessage } from 'naive-ui'
import { computed, ref } from 'vue'
const message = useMessage()
function getInstalledPlugins() {
return window.fcitx.getInstalledPlugins().sort()
}
const allPlugins = ['anthy', 'chewing', 'chinese-addons', 'hallelujah', 'hangul', 'lua', 'rime', 'sayura', 'thai', 'unikey']
const installedPlugins = ref<string[]>(getInstalledPlugins())
const availablePlugins = computed(() => allPlugins.filter(plugin => !installedPlugins.value.includes(plugin)))
const fileList = ref<UploadFileInfo[]>([])
async function onUpload(files: UploadFileInfo[]) {
// Must clear the fileList synchronously first as uploading multiple files will trigger multiple times.
fileList.value = []
for (const file of files) {
let name: string
const buffer = await file.file!.arrayBuffer()
try {
name = window.fcitx.installPlugin(buffer)
}
catch (e: any) {
message.error(e.message)
continue
}
window.fcitx.updateStatusArea()
installedPlugins.value = getInstalledPlugins()
message.success(`Installed ${name}`)
}
}
</script>

<template>
<NFlex size="large">
<NUpload v-model:file-list="fileList" style="width: auto" multiple accept=".zip" @update:file-list="onUpload">
<NUploadDragger style="height: 200px">
Download and drag zip to this area
</NUploadDragger>
</NUpload>
<NFlex>
<NList style="min-width: 100px">
<template #header>
Installed
</template>
<NListItem v-for="plugin in installedPlugins" :key="plugin">
{{ plugin }}
</NListItem>
</NList>
<NList style="min-width: 100px">
<template #header>
Available
</template>
<NListItem v-for="plugin in availablePlugins" :key="plugin">
<NA :href="`https://github.com/fcitx-contrib/fcitx5-plugins/releases/download/js/${plugin}.zip`">
{{ plugin }}
</NA>
</NListItem>
</NList>
</NFlex>
</NFlex>
</template>
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default as AdvancedConfig } from './AdvancedConfig.vue'
export { default as GearButton } from './GearButton.vue'
export { default as GlobalConfig } from './GlobalConfig.vue'
export { default as InputMethodConfig } from './InputMethodConfig.vue'
export { default as PluginManager } from './PluginManager.vue'
export { default as ThemeConfig } from './ThemeConfig.vue'

0 comments on commit c0c0d85

Please sign in to comment.