mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-28 16:42:47 +08:00
:spark: 支持插件自动更新
This commit is contained in:
parent
bfbbf3463e
commit
57781e7b5a
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rubick",
|
||||
"version": "2.1.2",
|
||||
"version": "2.1.3",
|
||||
"author": "muwoo <2424880409@qq.com>",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
@ -21,6 +21,7 @@
|
||||
"dependencies": {
|
||||
"@better-scroll/core": "^2.4.2",
|
||||
"ant-design-vue": "^2.2.8",
|
||||
"axios": "^1.3.4",
|
||||
"core-js": "^3.6.5",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"extract-file-icon": "^0.3.2",
|
||||
|
@ -9,6 +9,7 @@ import fixPath from 'fix-path';
|
||||
|
||||
import spawn from 'cross-spawn';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import axios from 'axios';
|
||||
|
||||
fixPath();
|
||||
|
||||
@ -22,6 +23,8 @@ class AdapterHandler {
|
||||
// 插件源地址
|
||||
readonly registry: string;
|
||||
|
||||
pluginCaches = {};
|
||||
|
||||
/**
|
||||
* Creates an instance of AdapterHandler.
|
||||
* @param {AdapterHandlerOptions} options
|
||||
@ -52,6 +55,29 @@ class AdapterHandler {
|
||||
this.registry = register || 'https://registry.npm.taobao.org';
|
||||
}
|
||||
|
||||
async upgrade(name: string): Promise<void> {
|
||||
// 创建一个npm-registry-client实例
|
||||
const packageJSON = JSON.parse(
|
||||
fs.readFileSync(`${this.baseDir}/package.json`, 'utf-8')
|
||||
);
|
||||
const registryUrl = `https://registry.npm.taobao.org/${name}`;
|
||||
|
||||
// 从npm源中获取依赖包的最新版本
|
||||
try {
|
||||
const installedVersion = packageJSON.dependencies[name].replace('^', '');
|
||||
let latestVersion = this.pluginCaches[name];
|
||||
if (!latestVersion) {
|
||||
const { data } = await axios.get(registryUrl, { timeout: 2000 });
|
||||
latestVersion = data['dist-tags'].latest;
|
||||
this.pluginCaches[name] = latestVersion;
|
||||
}
|
||||
if (latestVersion > installedVersion) {
|
||||
await this.install([name], { isDev: false });
|
||||
}
|
||||
} catch (e) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取插件信息
|
||||
* @param {string} adapter 插件名称
|
||||
|
@ -29,11 +29,12 @@
|
||||
>
|
||||
<template #suffix>
|
||||
<div class="suffix-tool">
|
||||
<MoreOutlined @click="showSeparate()" class="icon-more" />
|
||||
<MoreOutlined v-show="!pluginLoading" @click="showSeparate()" class="icon-more" />
|
||||
<div
|
||||
v-if="currentPlugin && currentPlugin.logo"
|
||||
style="position: relative"
|
||||
>
|
||||
<div v-show="pluginLoading" class="update-tips">检测更新中...</div>
|
||||
<a-spin v-show="pluginLoading" class="loading">
|
||||
<template #indicator>
|
||||
<LoadingOutlined style="font-size: 42px" />
|
||||
@ -309,6 +310,14 @@ window.rubick.hooks.onHide = () => {
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
.update-tips {
|
||||
position: absolute;
|
||||
right: 46px;
|
||||
top: 50%;
|
||||
font-size: 14px;
|
||||
transform: translateY(-50%);
|
||||
color: #aaa;
|
||||
}
|
||||
}
|
||||
.clipboard-tag {
|
||||
white-space: pre;
|
||||
|
@ -28,17 +28,25 @@ const createPluginManager = (): any => {
|
||||
appList.value = await appSearch(nativeImage);
|
||||
};
|
||||
|
||||
const loadPlugin = (plugin) => {
|
||||
const loadPlugin = async (plugin) => {
|
||||
setSearchValue('');
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'setExpendHeight',
|
||||
data: 60,
|
||||
});
|
||||
state.pluginLoading = true;
|
||||
state.currentPlugin = plugin;
|
||||
// 自带的插件不需要检测更新
|
||||
if (plugin.name === 'rubick-system-feature') return;
|
||||
await pluginInstance.upgrade(plugin.name);
|
||||
};
|
||||
|
||||
const openPlugin = (plugin) => {
|
||||
const openPlugin = async (plugin) => {
|
||||
if (plugin.pluginType === 'ui' || plugin.pluginType === 'system') {
|
||||
if (state.currentPlugin && state.currentPlugin.name === plugin.name) {
|
||||
return;
|
||||
}
|
||||
loadPlugin(plugin);
|
||||
await loadPlugin(plugin);
|
||||
ipcRenderer.sendSync('msg-trigger', {
|
||||
type: 'openPlugin',
|
||||
data: JSON.parse(
|
||||
@ -52,7 +60,6 @@ const createPluginManager = (): any => {
|
||||
})
|
||||
),
|
||||
});
|
||||
setSearchValue('');
|
||||
}
|
||||
if (plugin.pluginType === 'app') {
|
||||
execSync(plugin.action);
|
||||
|
19
yarn.lock
19
yarn.lock
@ -2621,6 +2621,15 @@ aws4@^1.8.0:
|
||||
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
|
||||
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
|
||||
|
||||
axios@^1.3.4:
|
||||
version "1.3.4"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.4.tgz#f5760cefd9cfb51fd2481acf88c05f67c4523024"
|
||||
integrity sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==
|
||||
dependencies:
|
||||
follow-redirects "^1.15.0"
|
||||
form-data "^4.0.0"
|
||||
proxy-from-env "^1.1.0"
|
||||
|
||||
babel-code-frame@^6.22.0:
|
||||
version "6.26.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
|
||||
@ -5490,6 +5499,11 @@ follow-redirects@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"
|
||||
integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==
|
||||
|
||||
follow-redirects@^1.15.0:
|
||||
version "1.15.2"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
|
||||
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
|
||||
|
||||
for-in@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
|
||||
@ -9067,6 +9081,11 @@ proxy-addr@~2.0.7:
|
||||
forwarded "0.2.0"
|
||||
ipaddr.js "1.9.1"
|
||||
|
||||
proxy-from-env@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
|
||||
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
|
||||
|
||||
prr@~1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"
|
||||
|
Loading…
x
Reference in New Issue
Block a user