Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(plugin): 本地目录选择器补上 Linux/macOS 支持 (#907)

iuuuuuuuud365cfc1106b
diff --git a/src-tauri/src/bridge/plugin.rs b/src-tauri/src/bridge/plugin.rs
index 0f146d30..c2559d50 100644
--- a/src-tauri/src/bridge/plugin.rs
+++ b/src-tauri/src/bridge/plugin.rs
@@ -351,7 +351,10 @@ pub async fn restore_plugin(app_handle: AppHandle, id: String) -> Result<(), Str
/// Windows 的文件夹选择器是 COM 组件(`CoInitializeEx` 要求 STA 单元),而异步命令体跑在
/// 线程池上、线程的 COM 单元不确定;因此把对话框搬到主线程(tao 建窗时已初始化 STA),
/// 再同步等它关闭:阻塞的是原生对话框自身,异步运行时不阻塞。
-/// 其余平台没有可用的原生选择器,直接拒绝,由前端隐藏入口。
+/// 其余平台走 `rfd` 的异步对话框(与 `pick_data_dir` 同一条路):macOS 后端自己把面板
+/// 派发到主线程、不设父窗也会挂到主窗,Linux 用 xdg-desktop-portal,没有 portal 的会话会
+/// 回退 zenity。这两条路都拿不到用户选择时同样返回 `None`,与「用户取消」无法区分,
+/// 前端按取消处理(不弹错)。
#[tauri::command]
pub async fn pick_local_plugin_dir(app_handle: AppHandle) -> Result<Option<String>, String> {
#[cfg(windows)]
@@ -379,7 +382,11 @@ pub async fn pick_local_plugin_dir(app_handle: AppHandle) -> Result<Option<Strin
#[cfg(not(windows))]
{
let _ = app_handle;
- Err("PLUGIN_PICK_FOLDER_UNSUPPORTED: native folder picker is Windows-only".to_string())
+ let picked = rfd::AsyncFileDialog::new()
+ .set_title("选择本地插件目录")
+ .pick_folder()
+ .await;
+ Ok(picked.map(|handle| plugin::local_spec_from_path(handle.path())))
}
}
diff --git a/src/ui/config/plugin.test.tsx b/src/ui/config/plugin.test.tsx
index 6236e16f..66bad8e3 100644
--- a/src/ui/config/plugin.test.tsx
+++ b/src/ui/config/plugin.test.tsx
@@ -38,7 +38,6 @@ vi.mock('@tanstack/react-query', () => ({
vi.mock('@/store', () => ({ store: { preinstall: { open: vi.fn(), installing: false }, harness: { restart: mocks.restart } } }))
vi.mock('@/utils/toast', () => ({ toast: mocks.toast }))
vi.mock('@tauri-apps/api/core', () => ({ invoke: mocks.invoke }))
-vi.mock('@tauri-apps/plugin-os', () => ({ type: () => 'windows' }))
vi.mock('@/components/modal', () => ({ Modal: () => null }))
vi.mock('@/components/item', () => ({ Item: ({ left, right }: { left: ReactNode, right: ReactNode }) => (
<div>
@@ -176,7 +175,7 @@ describe('built-in plugin toggles', () => {
})
describe('local plugin folder picking', () => {
- /** 目录选择器只在 Windows 构建上存在,这里让 get_local_plugin_hmr 与 pick 各自返回固定值。 */
+ /** 目录选择器由宿主在三平台各用原生实现,这里让 get_local_plugin_hmr 与 pick 各自返回固定值。 */
function mockLocalCommands(picked: string | null) {
mocks.invoke.mockImplementation(async (command: string) => {
if (command === 'get_local_plugin_hmr')
@@ -187,6 +186,11 @@ describe('local plugin folder picking', () => {
})
}
+ it('offers the folder picker on every platform', () => {
+ render(<ConfigPlugin />)
+ expect(screen.getByRole('button', { name: 'plugins.local_dir' })).toBeTruthy()
+ })
+
it('installs the picked folder as a link spec through the normal install chain', async () => {
mockLocalCommands('link:D:/plugins/mine')
render(<ConfigPlugin />)
diff --git a/src/ui/config/plugin.tsx b/src/ui/config/plugin.tsx
index e690a622..99a68e33 100644
--- a/src/ui/config/plugin.tsx
+++ b/src/ui/config/plugin.tsx
@@ -5,7 +5,6 @@ import { useOverlay } from '@overlastic/react'
import { useToggle } from '@reause/core'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { invoke } from '@tauri-apps/api/core'
-import { type } from '@tauri-apps/plugin-os'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { If } from 'react-if-lite'
@@ -61,19 +60,6 @@ interface LocalHmrStatus {
roots: string[]
}
-/** 原生文件夹选择器只有 Windows 构建提供,其它平台宿主直接拒绝;据此隐藏入口。 */
-function pickFolderSupported(): boolean {
- try {
- return type() === 'windows'
- }
- catch (error) {
- console.warn('[ConfigPlugin] failed to read the OS type, hiding the folder picker:', error)
- return false
- }
-}
-
-const PICK_FOLDER_SUPPORTED = pickFolderSupported()
-
/**
* 「插件」面板:已安装插件的安装/升级/卸载/禁用/启用全部经 `useDshPluginsManager` 收口
* (队列、授权、Toast、组结算重启由管理器统一负责),面板只保留确认对话框与行内 busy。
@@ -696,24 +682,22 @@ export function ConfigPlugin() {
{t('plugins.install')}
</span>
</Button>
- <If cond={PICK_FOLDER_SUPPORTED}>
- <Tooltip delay={0}>
- <Button
- isIconOnly
- size="sm"
- variant="tertiary"
- className="size-8 shrink-0"
- isDisabled={installing}
- aria-label={t('plugins.local_dir')}
- onPress={() => void onPickLocalDir()}
- >
- <FolderOpen />
- </Button>
- <Tooltip.Content className="max-w-[320px]">
- <p>{t('plugins.local_dir')}</p>
- </Tooltip.Content>
- </Tooltip>
- </If>
+ <Tooltip delay={0}>
+ <Button
+ isIconOnly
+ size="sm"
+ variant="tertiary"
+ className="size-8 shrink-0"
+ isDisabled={installing}
+ aria-label={t('plugins.local_dir')}
+ onPress={() => void onPickLocalDir()}
+ >
+ <FolderOpen />
+ </Button>
+ <Tooltip.Content className="max-w-[320px]">
+ <p>{t('plugins.local_dir')}</p>
+ </Tooltip.Content>
+ </Tooltip>
</div>
<If cond={searchResults != null}>
<div className="flex flex-col gap-1 px-1">