feat(driver): 增加驱动目录直达入口与手动导入提示

Fixes #306
This commit is contained in:
Syngnat
2026-04-11 21:53:51 +08:00
parent f696f52470
commit 8297829be6
5 changed files with 61 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ import {
GetDriverVersionPackageSize,
GetDriverStatusList,
InstallLocalDriverPackage,
OpenDriverDownloadDirectory,
RemoveDriverPackage,
SelectDriverPackageDirectory,
SelectDriverPackageFile,
@@ -948,6 +949,18 @@ const DriverManagerModal: React.FC<{ open: boolean; onClose: () => void; onOpenG
message.error(`目录导入失败${forceTip}:失败 ${failCount}${skipTip}`);
}, [appendOperationLog, downloadDir, forceOverwriteInstalled, installDriverFromLocalPath, refreshStatus, rows]);
const openDriverDirectory = useCallback(async () => {
try {
const res = await OpenDriverDownloadDirectory(downloadDir);
if (!res?.success) {
throw new Error(res?.message || '打开驱动目录失败');
}
} catch (error) {
const errMsg = error instanceof Error ? error.message : String(error || '未知错误');
message.error(`打开驱动目录失败: ${errMsg}`);
}
}, [downloadDir]);
const openDriverLog = useCallback((driverType: string) => {
const normalized = String(driverType || '').trim().toLowerCase();
if (!normalized) {
@@ -1360,10 +1373,14 @@ const DriverManagerModal: React.FC<{ open: boolean; onClose: () => void; onOpenG
children: (
<Space direction="vertical" size={6} style={{ width: '100%' }}>
<Text type="secondary"></Text>
<Text type="secondary">使</Text>
<Text type="secondary">/ `mariadb-driver-agent``mariadb-driver-agent.exe``GoNavi-DriverAgents.zip`使</Text>
<Paragraph copyable={{ text: downloadDir || '-' }} style={{ marginBottom: 0 }}>
{downloadDir || '-'}
</Paragraph>
<Button icon={<FolderOpenOutlined />} onClick={() => void openDriverDirectory()}>
</Button>
{networkStatus?.logPath ? (
<Paragraph copyable={{ text: networkStatus.logPath }} style={{ marginBottom: 0 }}>
{networkStatus.logPath}
@@ -1392,6 +1409,12 @@ const DriverManagerModal: React.FC<{ open: boolean; onClose: () => void; onOpenG
onChange={(checked) => setForceOverwriteInstalled(checked)}
disabled={batchDirectoryImporting}
/>
<Button
icon={<FolderOpenOutlined />}
onClick={() => void openDriverDirectory()}
>
</Button>
<Button
icon={<FolderOpenOutlined />}
loading={batchDirectoryImporting}

View File

@@ -128,6 +128,7 @@ if (typeof window !== 'undefined' && !(window as any).go) {
GetDataRootDirectoryInfo: async () => ({ success: true, data: cloneBrowserMockValue(mockDataRootInfo) }),
CheckForUpdates: async () => ({ success: false }),
OpenDownloadedUpdateDirectory: async () => ({ success: false }),
OpenDriverDownloadDirectory: async (path: string) => ({ success: true, data: { path } }),
OpenDataRootDirectory: async () => ({ success: true }),
InstallUpdateAndRestart: async () => ({ success: false }),
ImportConfigFile: async () => ({ success: false }),

View File

@@ -130,6 +130,8 @@ export function MySQLShowCreateTable(arg1:connection.ConnectionConfig,arg2:strin
export function OpenDownloadedUpdateDirectory():Promise<connection.QueryResult>;
export function OpenDriverDownloadDirectory(arg1:string):Promise<connection.QueryResult>;
export function OpenDataRootDirectory():Promise<connection.QueryResult>;
export function OpenSQLFile():Promise<connection.QueryResult>;

View File

@@ -254,6 +254,10 @@ export function OpenDownloadedUpdateDirectory() {
return window['go']['app']['App']['OpenDownloadedUpdateDirectory']();
}
export function OpenDriverDownloadDirectory(arg1) {
return window['go']['app']['App']['OpenDriverDownloadDirectory'](arg1);
}
export function OpenDataRootDirectory() {
return window['go']['app']['App']['OpenDataRootDirectory']();
}

View File

@@ -512,6 +512,37 @@ func (a *App) SelectDriverPackageDirectory(currentPath string) connection.QueryR
return connection.QueryResult{Success: true, Data: map[string]interface{}{"path": selection}}
}
func (a *App) OpenDriverDownloadDirectory(directory string) connection.QueryResult {
resolved, err := resolveDriverDownloadDirectory(directory)
if err != nil {
return connection.QueryResult{Success: false, Message: err.Error()}
}
if err := os.MkdirAll(resolved, 0o755); err != nil {
return connection.QueryResult{Success: false, Message: fmt.Sprintf("创建驱动目录失败:%v", err)}
}
var cmd *exec.Cmd
switch stdRuntime.GOOS {
case "darwin":
cmd = exec.Command("open", resolved)
case "windows":
cmd = exec.Command("explorer", resolved)
case "linux":
cmd = exec.Command("xdg-open", resolved)
default:
return connection.QueryResult{Success: false, Message: fmt.Sprintf("当前平台暂不支持打开目录:%s", stdRuntime.GOOS)}
}
if err := cmd.Start(); err != nil {
logger.Error(err, "打开驱动目录失败")
return connection.QueryResult{Success: false, Message: fmt.Sprintf("打开驱动目录失败:%v", err)}
}
return connection.QueryResult{
Success: true,
Message: fmt.Sprintf("已打开驱动目录:%s", resolved),
Data: map[string]interface{}{"path": resolved},
}
}
func (a *App) ResolveDriverDownloadDirectory(directory string) connection.QueryResult {
resolved, err := resolveDriverDownloadDirectory(directory)
if err != nil {