Skip to content

Commit

Permalink
feat(market): quick install for missing deps
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 17, 2023
1 parent 8d1957b commit f20e843
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
20 changes: 7 additions & 13 deletions plugins/market/client/components/install.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,24 @@
<script lang="ts" setup>
import { computed, ref, watch } from 'vue'
import { global, router, send, store, useContext } from '@koishijs/client'
import { global, send, store, useContext } from '@koishijs/client'
import { analyzeVersions, install } from './utils'
import { active, config } from '../utils'
import { parse } from 'semver'
const ctx = useContext()
function installDep(version: string) {
const target = shortname.value
const target = active.value
if (!target) return
if (config.value.bulk) {
config.value.override[active.value] = version
config.value.override[target] = version
active.value = ''
return
}
install({ [active.value]: version }, async () => {
if (!version || !target || !store.config || getPaths(target).length) return
const key = Math.random().toString(36).slice(2, 8)
await send('manager/unload', '', target + ':' + key, {})
await router.push('/plugins/' + key)
install({ [target]: version }, async () => {
if (!version) return
ctx.emit('config/dialog-fork', target)
})
}
Expand Down Expand Up @@ -190,11 +189,6 @@ const shortname = computed(() => {
return active.value.replace(pluginRegExp, '')
})
function getPaths(target: string) {
if (!target || !store.config) return []
return [...find(target, store.config.plugins, '')]
}
function configure() {
ctx.emit('config/dialog-fork', active.value)
active.value = null
Expand Down
19 changes: 17 additions & 2 deletions plugins/market/client/extensions/missing.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
<template>
<k-comment type="danger">
<p>此插件尚未安装,<span class="k-link" @click="gotoMarket">点击前往插件市场</span>。</p>
<p>
<span>此插件尚未安装,</span>
<span v-if="fullname" class="k-link" @click="active = fullname">点击快速安装</span>
<span v-else class="k-link" @click="gotoMarket">点击前往插件市场</span>
<span>。</span>
</p>
</k-comment>
</template>

<script setup lang="ts">
import { inject, WritableComputedRef } from 'vue'
import { computed, inject, WritableComputedRef } from 'vue'
import { useRouter } from 'vue-router'
import { store } from '@koishijs/client'
import { active } from '../utils'
const router = useRouter()
const current = inject<WritableComputedRef<any>>('manager.settings.current')
const fullname = computed(() => {
const { name } = current.value
const candidates = name.startsWith('@')
? [name.replace(/\//, '/koishi-plugin-')]
: [`@koishijs/plugin-${name}`, `koishi-plugin-${name}`]
return candidates.find(name => name in store.market.data)
})
function gotoMarket() {
router.push('/market?keyword=' + current.value.name)
}
Expand Down

0 comments on commit f20e843

Please sign in to comment.