feat(plugins): support local JDBC plugin installation

Add a "local install" button that lets users install the JDBC plugin
from a local zip file when online download fails (e.g. draft release).
This commit is contained in:
t8y2 2026-05-14 11:42:21 +08:00
parent 3c0d0fbad9
commit 081a356832
3 changed files with 43 additions and 0 deletions

View File

@ -42,6 +42,17 @@ pub async fn install_jdbc_plugin(state: State<'_, Arc<AppState>>) -> Result<Jdbc
jdbc_plugin_status_from_state(&state)
}
#[tauri::command]
pub async fn install_jdbc_plugin_local(
state: State<'_, Arc<AppState>>,
path: String,
) -> Result<JdbcPluginStatus, String> {
let bytes = std::fs::read(&path).map_err(|e| format!("Failed to read file: {e}"))?;
let plugin_dir = state.plugins.root_dir().join("jdbc");
install_jdbc_plugin_zip(&bytes, &plugin_dir)?;
jdbc_plugin_status_from_state(&state)
}
#[tauri::command]
pub async fn uninstall_jdbc_plugin(state: State<'_, Arc<AppState>>) -> Result<JdbcPluginStatus, String> {
let plugin_dir = state.plugins.root_dir().join("jdbc");

View File

@ -93,6 +93,7 @@ pub fn run() {
commands::plugins::delete_jdbc_driver,
commands::plugins::jdbc_plugin_status,
commands::plugins::install_jdbc_plugin,
commands::plugins::install_jdbc_plugin_local,
commands::plugins::uninstall_jdbc_plugin,
commands::schema::list_databases,
commands::schema::list_tables,

View File

@ -281,6 +281,27 @@ async function installJdbcPlugin() {
}
}
async function installJdbcPluginLocal() {
if (isWeb || isInstallingJdbcPlugin.value) return;
const { open } = await import("@tauri-apps/plugin-dialog");
const selected = await open({
title: "选择 JDBC 插件 zip 文件",
multiple: false,
filters: [{ name: "ZIP", extensions: ["zip"] }],
});
if (typeof selected !== "string") return;
isInstallingJdbcPlugin.value = true;
try {
jdbcPluginStatus.value = await invoke<JdbcPluginStatus>("install_jdbc_plugin_local", { path: selected });
toast(t("settings.jdbcPluginInstallSuccess"));
await loadJdbcDrivers();
} catch (e: any) {
toast(String(e?.message || e), 5000);
} finally {
isInstallingJdbcPlugin.value = false;
}
}
async function uninstallJdbcPlugin() {
if (isWeb || isUninstallingJdbcPlugin.value) return;
isUninstallingJdbcPlugin.value = true;
@ -636,6 +657,16 @@ onUnmounted(() => {
>
{{ isInstallingJdbcPlugin ? t("common.loading") : t("settings.jdbcPluginInstall") }}
</Button>
<Button
v-if="!jdbcPluginStatus?.installed"
type="button"
variant="outline"
:disabled="isInstallingJdbcPlugin"
@click="installJdbcPluginLocal"
>
<FolderOpen class="h-3.5 w-3.5 mr-1" />
本地安装
</Button>
</div>
</div>
</div>