@huyooo/file-explorer-bridge-electron 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/index.cjs +235 -0
- package/dist/main/index.d.cts +27 -0
- package/dist/main/index.d.ts +27 -0
- package/dist/main/index.js +220 -0
- package/dist/preload/index.cjs +71 -0
- package/dist/preload/index.d.cts +145 -0
- package/dist/preload/index.d.ts +145 -0
- package/dist/preload/index.js +45 -0
- package/dist/renderer/index.cjs +57 -0
- package/dist/renderer/index.d.cts +150 -0
- package/dist/renderer/index.d.ts +150 -0
- package/dist/renderer/index.js +36 -0
- package/package.json +63 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Explorer Electron Bridge - Preload Script
|
|
3
|
+
*
|
|
4
|
+
* 在 preload 脚本中调用此函数,暴露文件操作 API 给渲染进程
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 文件操作 API 类型
|
|
8
|
+
*/
|
|
9
|
+
interface FileExplorerAPI {
|
|
10
|
+
/** 读取目录 */
|
|
11
|
+
readDirectory: (dirPath: string) => Promise<unknown[]>;
|
|
12
|
+
/** 读取系统路径目录 */
|
|
13
|
+
readSystemPath: (pathId: string) => Promise<unknown[]>;
|
|
14
|
+
/** 获取系统路径 */
|
|
15
|
+
getSystemPath: (pathId: string) => Promise<string | null>;
|
|
16
|
+
/** 读取文件内容 */
|
|
17
|
+
readFileContent: (filePath: string) => Promise<string>;
|
|
18
|
+
/** 写入文件内容 */
|
|
19
|
+
writeFileContent: (filePath: string, content: string) => Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
error?: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** 创建文件夹 */
|
|
24
|
+
createFolder: (parentDir: string, folderName: string) => Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
data?: {
|
|
27
|
+
finalPath: string;
|
|
28
|
+
};
|
|
29
|
+
error?: string;
|
|
30
|
+
}>;
|
|
31
|
+
/** 创建文件 */
|
|
32
|
+
createFile: (parentDir: string, fileName: string, content?: string) => Promise<{
|
|
33
|
+
success: boolean;
|
|
34
|
+
data?: {
|
|
35
|
+
finalPath: string;
|
|
36
|
+
};
|
|
37
|
+
error?: string;
|
|
38
|
+
}>;
|
|
39
|
+
/** 删除文件 */
|
|
40
|
+
deleteFiles: (paths: string[]) => Promise<{
|
|
41
|
+
success: boolean;
|
|
42
|
+
error?: string;
|
|
43
|
+
message?: string;
|
|
44
|
+
}>;
|
|
45
|
+
/** 重命名文件 */
|
|
46
|
+
renameFile: (oldPath: string, newPath: string) => Promise<{
|
|
47
|
+
success: boolean;
|
|
48
|
+
error?: string;
|
|
49
|
+
}>;
|
|
50
|
+
/** 复制文件 */
|
|
51
|
+
copyFiles: (sourcePaths: string[], targetDir: string) => Promise<{
|
|
52
|
+
success: boolean;
|
|
53
|
+
data?: {
|
|
54
|
+
copiedPaths: string[];
|
|
55
|
+
};
|
|
56
|
+
error?: string;
|
|
57
|
+
}>;
|
|
58
|
+
/** 移动文件 */
|
|
59
|
+
moveFiles: (sourcePaths: string[], targetDir: string) => Promise<{
|
|
60
|
+
success: boolean;
|
|
61
|
+
data?: {
|
|
62
|
+
movedPaths: string[];
|
|
63
|
+
};
|
|
64
|
+
error?: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** 获取文件信息 */
|
|
67
|
+
getFileInfo: (filePath: string) => Promise<{
|
|
68
|
+
success: boolean;
|
|
69
|
+
data?: unknown;
|
|
70
|
+
error?: string;
|
|
71
|
+
}>;
|
|
72
|
+
/** 读取图片为 Base64 */
|
|
73
|
+
readImageAsBase64: (imagePath: string) => Promise<{
|
|
74
|
+
success: boolean;
|
|
75
|
+
base64?: string;
|
|
76
|
+
mimeType?: string;
|
|
77
|
+
error?: string;
|
|
78
|
+
}>;
|
|
79
|
+
/** 使用系统默认应用打开 */
|
|
80
|
+
openPath: (filePath: string) => Promise<{
|
|
81
|
+
success: boolean;
|
|
82
|
+
error?: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** 获取应用程序图标 */
|
|
85
|
+
getApplicationIcon: (appPath: string) => Promise<string | null>;
|
|
86
|
+
/** 获取缩略图 URL */
|
|
87
|
+
getThumbnailUrl: (filePath: string) => Promise<string | null>;
|
|
88
|
+
/** 复制文件到剪贴板 */
|
|
89
|
+
copyFilesToClipboard: (filePaths: string[]) => Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
error?: string;
|
|
92
|
+
}>;
|
|
93
|
+
/** 从剪贴板获取文件 */
|
|
94
|
+
getClipboardFiles: () => Promise<{
|
|
95
|
+
success: boolean;
|
|
96
|
+
data?: {
|
|
97
|
+
files: string[];
|
|
98
|
+
};
|
|
99
|
+
error?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/** 粘贴文件 */
|
|
102
|
+
pasteFiles: (targetDir: string, sourcePaths: string[]) => Promise<{
|
|
103
|
+
success: boolean;
|
|
104
|
+
data?: {
|
|
105
|
+
pastedPaths: string[];
|
|
106
|
+
};
|
|
107
|
+
error?: string;
|
|
108
|
+
}>;
|
|
109
|
+
/** 搜索文件 */
|
|
110
|
+
searchFiles: (searchPath: string, pattern: string, maxDepth?: number) => Promise<{
|
|
111
|
+
success: boolean;
|
|
112
|
+
data?: {
|
|
113
|
+
items: unknown[];
|
|
114
|
+
total: number;
|
|
115
|
+
};
|
|
116
|
+
error?: string;
|
|
117
|
+
}>;
|
|
118
|
+
/** 流式搜索文件 */
|
|
119
|
+
searchFilesStream: (searchPath: string, pattern: string, searchId: string) => Promise<{
|
|
120
|
+
success: boolean;
|
|
121
|
+
error?: string;
|
|
122
|
+
}>;
|
|
123
|
+
/** 监听搜索结果 */
|
|
124
|
+
onSearchResults: (callback: (data: {
|
|
125
|
+
searchId: string;
|
|
126
|
+
items: unknown[];
|
|
127
|
+
done: boolean;
|
|
128
|
+
}) => void) => () => void;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 创建文件操作 API
|
|
132
|
+
*/
|
|
133
|
+
declare function createFileExplorerAPI(): FileExplorerAPI;
|
|
134
|
+
/**
|
|
135
|
+
* 暴露文件操作 API 到渲染进程
|
|
136
|
+
*
|
|
137
|
+
* 在 preload.ts 中调用:
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { exposeFileExplorerAPI } from '@aspect/file-explorer-bridge-electron/preload';
|
|
140
|
+
* exposeFileExplorerAPI();
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function exposeFileExplorerAPI(apiName?: string): void;
|
|
144
|
+
|
|
145
|
+
export { type FileExplorerAPI, createFileExplorerAPI, exposeFileExplorerAPI };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Explorer Electron Bridge - Preload Script
|
|
3
|
+
*
|
|
4
|
+
* 在 preload 脚本中调用此函数,暴露文件操作 API 给渲染进程
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 文件操作 API 类型
|
|
8
|
+
*/
|
|
9
|
+
interface FileExplorerAPI {
|
|
10
|
+
/** 读取目录 */
|
|
11
|
+
readDirectory: (dirPath: string) => Promise<unknown[]>;
|
|
12
|
+
/** 读取系统路径目录 */
|
|
13
|
+
readSystemPath: (pathId: string) => Promise<unknown[]>;
|
|
14
|
+
/** 获取系统路径 */
|
|
15
|
+
getSystemPath: (pathId: string) => Promise<string | null>;
|
|
16
|
+
/** 读取文件内容 */
|
|
17
|
+
readFileContent: (filePath: string) => Promise<string>;
|
|
18
|
+
/** 写入文件内容 */
|
|
19
|
+
writeFileContent: (filePath: string, content: string) => Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
error?: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** 创建文件夹 */
|
|
24
|
+
createFolder: (parentDir: string, folderName: string) => Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
data?: {
|
|
27
|
+
finalPath: string;
|
|
28
|
+
};
|
|
29
|
+
error?: string;
|
|
30
|
+
}>;
|
|
31
|
+
/** 创建文件 */
|
|
32
|
+
createFile: (parentDir: string, fileName: string, content?: string) => Promise<{
|
|
33
|
+
success: boolean;
|
|
34
|
+
data?: {
|
|
35
|
+
finalPath: string;
|
|
36
|
+
};
|
|
37
|
+
error?: string;
|
|
38
|
+
}>;
|
|
39
|
+
/** 删除文件 */
|
|
40
|
+
deleteFiles: (paths: string[]) => Promise<{
|
|
41
|
+
success: boolean;
|
|
42
|
+
error?: string;
|
|
43
|
+
message?: string;
|
|
44
|
+
}>;
|
|
45
|
+
/** 重命名文件 */
|
|
46
|
+
renameFile: (oldPath: string, newPath: string) => Promise<{
|
|
47
|
+
success: boolean;
|
|
48
|
+
error?: string;
|
|
49
|
+
}>;
|
|
50
|
+
/** 复制文件 */
|
|
51
|
+
copyFiles: (sourcePaths: string[], targetDir: string) => Promise<{
|
|
52
|
+
success: boolean;
|
|
53
|
+
data?: {
|
|
54
|
+
copiedPaths: string[];
|
|
55
|
+
};
|
|
56
|
+
error?: string;
|
|
57
|
+
}>;
|
|
58
|
+
/** 移动文件 */
|
|
59
|
+
moveFiles: (sourcePaths: string[], targetDir: string) => Promise<{
|
|
60
|
+
success: boolean;
|
|
61
|
+
data?: {
|
|
62
|
+
movedPaths: string[];
|
|
63
|
+
};
|
|
64
|
+
error?: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** 获取文件信息 */
|
|
67
|
+
getFileInfo: (filePath: string) => Promise<{
|
|
68
|
+
success: boolean;
|
|
69
|
+
data?: unknown;
|
|
70
|
+
error?: string;
|
|
71
|
+
}>;
|
|
72
|
+
/** 读取图片为 Base64 */
|
|
73
|
+
readImageAsBase64: (imagePath: string) => Promise<{
|
|
74
|
+
success: boolean;
|
|
75
|
+
base64?: string;
|
|
76
|
+
mimeType?: string;
|
|
77
|
+
error?: string;
|
|
78
|
+
}>;
|
|
79
|
+
/** 使用系统默认应用打开 */
|
|
80
|
+
openPath: (filePath: string) => Promise<{
|
|
81
|
+
success: boolean;
|
|
82
|
+
error?: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** 获取应用程序图标 */
|
|
85
|
+
getApplicationIcon: (appPath: string) => Promise<string | null>;
|
|
86
|
+
/** 获取缩略图 URL */
|
|
87
|
+
getThumbnailUrl: (filePath: string) => Promise<string | null>;
|
|
88
|
+
/** 复制文件到剪贴板 */
|
|
89
|
+
copyFilesToClipboard: (filePaths: string[]) => Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
error?: string;
|
|
92
|
+
}>;
|
|
93
|
+
/** 从剪贴板获取文件 */
|
|
94
|
+
getClipboardFiles: () => Promise<{
|
|
95
|
+
success: boolean;
|
|
96
|
+
data?: {
|
|
97
|
+
files: string[];
|
|
98
|
+
};
|
|
99
|
+
error?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/** 粘贴文件 */
|
|
102
|
+
pasteFiles: (targetDir: string, sourcePaths: string[]) => Promise<{
|
|
103
|
+
success: boolean;
|
|
104
|
+
data?: {
|
|
105
|
+
pastedPaths: string[];
|
|
106
|
+
};
|
|
107
|
+
error?: string;
|
|
108
|
+
}>;
|
|
109
|
+
/** 搜索文件 */
|
|
110
|
+
searchFiles: (searchPath: string, pattern: string, maxDepth?: number) => Promise<{
|
|
111
|
+
success: boolean;
|
|
112
|
+
data?: {
|
|
113
|
+
items: unknown[];
|
|
114
|
+
total: number;
|
|
115
|
+
};
|
|
116
|
+
error?: string;
|
|
117
|
+
}>;
|
|
118
|
+
/** 流式搜索文件 */
|
|
119
|
+
searchFilesStream: (searchPath: string, pattern: string, searchId: string) => Promise<{
|
|
120
|
+
success: boolean;
|
|
121
|
+
error?: string;
|
|
122
|
+
}>;
|
|
123
|
+
/** 监听搜索结果 */
|
|
124
|
+
onSearchResults: (callback: (data: {
|
|
125
|
+
searchId: string;
|
|
126
|
+
items: unknown[];
|
|
127
|
+
done: boolean;
|
|
128
|
+
}) => void) => () => void;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 创建文件操作 API
|
|
132
|
+
*/
|
|
133
|
+
declare function createFileExplorerAPI(): FileExplorerAPI;
|
|
134
|
+
/**
|
|
135
|
+
* 暴露文件操作 API 到渲染进程
|
|
136
|
+
*
|
|
137
|
+
* 在 preload.ts 中调用:
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { exposeFileExplorerAPI } from '@aspect/file-explorer-bridge-electron/preload';
|
|
140
|
+
* exposeFileExplorerAPI();
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function exposeFileExplorerAPI(apiName?: string): void;
|
|
144
|
+
|
|
145
|
+
export { type FileExplorerAPI, createFileExplorerAPI, exposeFileExplorerAPI };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/preload/index.ts
|
|
2
|
+
import { contextBridge, ipcRenderer } from "electron";
|
|
3
|
+
var CHANNEL_PREFIX = "file-explorer";
|
|
4
|
+
var channel = (name) => `${CHANNEL_PREFIX}:${name}`;
|
|
5
|
+
function createFileExplorerAPI() {
|
|
6
|
+
return {
|
|
7
|
+
readDirectory: (dirPath) => ipcRenderer.invoke(channel("readDirectory"), dirPath),
|
|
8
|
+
readSystemPath: (pathId) => ipcRenderer.invoke(channel("readSystemPath"), pathId),
|
|
9
|
+
getSystemPath: (pathId) => ipcRenderer.invoke(channel("getSystemPath"), pathId),
|
|
10
|
+
readFileContent: (filePath) => ipcRenderer.invoke(channel("readFileContent"), filePath),
|
|
11
|
+
writeFileContent: (filePath, content) => ipcRenderer.invoke(channel("writeFileContent"), filePath, content),
|
|
12
|
+
createFolder: (parentDir, folderName) => ipcRenderer.invoke(channel("createFolder"), parentDir, folderName),
|
|
13
|
+
createFile: (parentDir, fileName, content) => ipcRenderer.invoke(channel("createFile"), parentDir, fileName, content),
|
|
14
|
+
deleteFiles: (paths) => ipcRenderer.invoke(channel("deleteFiles"), paths),
|
|
15
|
+
renameFile: (oldPath, newPath) => ipcRenderer.invoke(channel("renameFile"), oldPath, newPath),
|
|
16
|
+
copyFiles: (sourcePaths, targetDir) => ipcRenderer.invoke(channel("copyFiles"), sourcePaths, targetDir),
|
|
17
|
+
moveFiles: (sourcePaths, targetDir) => ipcRenderer.invoke(channel("moveFiles"), sourcePaths, targetDir),
|
|
18
|
+
getFileInfo: (filePath) => ipcRenderer.invoke(channel("getFileInfo"), filePath),
|
|
19
|
+
readImageAsBase64: (imagePath) => ipcRenderer.invoke(channel("readImageAsBase64"), imagePath),
|
|
20
|
+
openPath: (filePath) => ipcRenderer.invoke(channel("openPath"), filePath),
|
|
21
|
+
getApplicationIcon: (appPath) => ipcRenderer.invoke(channel("getApplicationIcon"), appPath),
|
|
22
|
+
getThumbnailUrl: (filePath) => ipcRenderer.invoke(channel("getThumbnailUrl"), filePath),
|
|
23
|
+
copyFilesToClipboard: (filePaths) => ipcRenderer.invoke(channel("copyFilesToClipboard"), filePaths),
|
|
24
|
+
getClipboardFiles: () => ipcRenderer.invoke(channel("getClipboardFiles")),
|
|
25
|
+
pasteFiles: (targetDir, sourcePaths) => ipcRenderer.invoke(channel("pasteFiles"), targetDir, sourcePaths),
|
|
26
|
+
searchFiles: (searchPath, pattern, maxDepth) => ipcRenderer.invoke(channel("searchFiles"), searchPath, pattern, maxDepth),
|
|
27
|
+
searchFilesStream: (searchPath, pattern, searchId) => ipcRenderer.invoke(channel("searchFilesStream"), searchPath, pattern, searchId),
|
|
28
|
+
onSearchResults: (callback) => {
|
|
29
|
+
const handler = (_event, data) => {
|
|
30
|
+
callback(data);
|
|
31
|
+
};
|
|
32
|
+
ipcRenderer.on(channel("searchResults"), handler);
|
|
33
|
+
return () => ipcRenderer.removeListener(channel("searchResults"), handler);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function exposeFileExplorerAPI(apiName = "fileExplorerAPI") {
|
|
38
|
+
const api = createFileExplorerAPI();
|
|
39
|
+
contextBridge.exposeInMainWorld(apiName, api);
|
|
40
|
+
console.log(`\u2705 File Explorer API exposed as window.${apiName}`);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
createFileExplorerAPI,
|
|
44
|
+
exposeFileExplorerAPI
|
|
45
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/renderer/index.ts
|
|
21
|
+
var renderer_exports = {};
|
|
22
|
+
__export(renderer_exports, {
|
|
23
|
+
createElectronAdapter: () => createElectronAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(renderer_exports);
|
|
26
|
+
function createElectronAdapter() {
|
|
27
|
+
const api = window.fileExplorerAPI;
|
|
28
|
+
if (!api) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"window.fileExplorerAPI not found. Make sure to call exposeFileExplorerAPI() in your preload script."
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
readDirectory: (dirPath) => api.readDirectory(dirPath),
|
|
35
|
+
readSystemPath: (pathId) => api.readSystemPath(pathId),
|
|
36
|
+
getSystemPath: (pathId) => api.getSystemPath(pathId),
|
|
37
|
+
readFileContent: (filePath) => api.readFileContent(filePath),
|
|
38
|
+
writeFileContent: (filePath, content) => api.writeFileContent(filePath, content),
|
|
39
|
+
createFolder: (parentDir, folderName) => api.createFolder(parentDir, folderName),
|
|
40
|
+
createFile: (parentDir, fileName, content) => api.createFile(parentDir, fileName, content),
|
|
41
|
+
deleteFiles: (paths) => api.deleteFiles(paths),
|
|
42
|
+
renameFile: (oldPath, newPath) => api.renameFile(oldPath, newPath),
|
|
43
|
+
copyFiles: (sourcePaths, targetDir) => api.copyFiles(sourcePaths, targetDir),
|
|
44
|
+
moveFiles: (sourcePaths, targetDir) => api.moveFiles(sourcePaths, targetDir),
|
|
45
|
+
getFileInfo: (filePath) => api.getFileInfo(filePath),
|
|
46
|
+
readImageAsBase64: (imagePath) => api.readImageAsBase64(imagePath),
|
|
47
|
+
openPath: (filePath) => api.openPath(filePath),
|
|
48
|
+
getApplicationIcon: (appPath) => api.getApplicationIcon(appPath),
|
|
49
|
+
getThumbnailUrl: (filePath) => api.getThumbnailUrl(filePath),
|
|
50
|
+
copyFilesToClipboard: (filePaths) => api.copyFilesToClipboard(filePaths),
|
|
51
|
+
getClipboardFiles: () => api.getClipboardFiles(),
|
|
52
|
+
pasteFiles: (targetDir, sourcePaths) => api.pasteFiles(targetDir, sourcePaths),
|
|
53
|
+
searchFiles: (searchPath, pattern, maxDepth) => api.searchFiles(searchPath, pattern, maxDepth),
|
|
54
|
+
searchFilesStream: (searchPath, pattern, searchId) => api.searchFilesStream(searchPath, pattern, searchId),
|
|
55
|
+
onSearchResults: (callback) => api.onSearchResults(callback)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { FileItem, OperationResult, FileInfo } from '@huyooo/file-explorer-core';
|
|
2
|
+
export { FileInfo, FileItem, OperationResult, SystemPathId } from '@huyooo/file-explorer-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* File Explorer Electron Bridge - Renderer Process
|
|
6
|
+
*
|
|
7
|
+
* 提供渲染进程使用的适配器
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 文件操作适配器接口
|
|
12
|
+
*/
|
|
13
|
+
interface FileExplorerAdapter {
|
|
14
|
+
/** 读取目录 */
|
|
15
|
+
readDirectory(dirPath: string): Promise<FileItem[]>;
|
|
16
|
+
/** 读取系统路径目录 */
|
|
17
|
+
readSystemPath(pathId: string): Promise<FileItem[]>;
|
|
18
|
+
/** 获取系统路径 */
|
|
19
|
+
getSystemPath(pathId: string): Promise<string | null>;
|
|
20
|
+
/** 读取文件内容 */
|
|
21
|
+
readFileContent(filePath: string): Promise<string>;
|
|
22
|
+
/** 写入文件内容 */
|
|
23
|
+
writeFileContent(filePath: string, content: string): Promise<OperationResult>;
|
|
24
|
+
/** 创建文件夹 */
|
|
25
|
+
createFolder(parentDir: string, folderName: string): Promise<OperationResult<{
|
|
26
|
+
finalPath: string;
|
|
27
|
+
}>>;
|
|
28
|
+
/** 创建文件 */
|
|
29
|
+
createFile(parentDir: string, fileName: string, content?: string): Promise<OperationResult<{
|
|
30
|
+
finalPath: string;
|
|
31
|
+
}>>;
|
|
32
|
+
/** 删除文件 */
|
|
33
|
+
deleteFiles(paths: string[]): Promise<OperationResult>;
|
|
34
|
+
/** 重命名文件 */
|
|
35
|
+
renameFile(oldPath: string, newPath: string): Promise<OperationResult>;
|
|
36
|
+
/** 复制文件 */
|
|
37
|
+
copyFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
|
|
38
|
+
copiedPaths: string[];
|
|
39
|
+
}>>;
|
|
40
|
+
/** 移动文件 */
|
|
41
|
+
moveFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
|
|
42
|
+
movedPaths: string[];
|
|
43
|
+
}>>;
|
|
44
|
+
/** 获取文件信息 */
|
|
45
|
+
getFileInfo(filePath: string): Promise<OperationResult<FileInfo>>;
|
|
46
|
+
/** 读取图片为 Base64 */
|
|
47
|
+
readImageAsBase64(imagePath: string): Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
base64?: string;
|
|
50
|
+
mimeType?: string;
|
|
51
|
+
error?: string;
|
|
52
|
+
}>;
|
|
53
|
+
/** 使用系统默认应用打开 */
|
|
54
|
+
openPath(filePath: string): Promise<OperationResult>;
|
|
55
|
+
/** 获取应用程序图标 */
|
|
56
|
+
getApplicationIcon(appPath: string): Promise<string | null>;
|
|
57
|
+
/** 获取缩略图 URL */
|
|
58
|
+
getThumbnailUrl(filePath: string): Promise<string | null>;
|
|
59
|
+
/** 复制文件到剪贴板 */
|
|
60
|
+
copyFilesToClipboard(filePaths: string[]): Promise<OperationResult>;
|
|
61
|
+
/** 从剪贴板获取文件 */
|
|
62
|
+
getClipboardFiles(): Promise<OperationResult<{
|
|
63
|
+
files: string[];
|
|
64
|
+
}>>;
|
|
65
|
+
/** 粘贴文件 */
|
|
66
|
+
pasteFiles(targetDir: string, sourcePaths: string[]): Promise<OperationResult<{
|
|
67
|
+
pastedPaths: string[];
|
|
68
|
+
}>>;
|
|
69
|
+
/** 搜索文件 */
|
|
70
|
+
searchFiles(searchPath: string, pattern: string, maxDepth?: number): Promise<OperationResult<{
|
|
71
|
+
items: FileItem[];
|
|
72
|
+
total: number;
|
|
73
|
+
}>>;
|
|
74
|
+
/** 流式搜索文件 */
|
|
75
|
+
searchFilesStream(searchPath: string, pattern: string, searchId: string): Promise<OperationResult>;
|
|
76
|
+
/** 监听搜索结果 */
|
|
77
|
+
onSearchResults(callback: (data: {
|
|
78
|
+
searchId: string;
|
|
79
|
+
items: FileItem[];
|
|
80
|
+
done: boolean;
|
|
81
|
+
}) => void): () => void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Window 扩展类型
|
|
85
|
+
*/
|
|
86
|
+
declare global {
|
|
87
|
+
interface Window {
|
|
88
|
+
fileExplorerAPI?: {
|
|
89
|
+
readDirectory: (dirPath: string) => Promise<FileItem[]>;
|
|
90
|
+
readSystemPath: (pathId: string) => Promise<FileItem[]>;
|
|
91
|
+
getSystemPath: (pathId: string) => Promise<string | null>;
|
|
92
|
+
readFileContent: (filePath: string) => Promise<string>;
|
|
93
|
+
writeFileContent: (filePath: string, content: string) => Promise<OperationResult>;
|
|
94
|
+
createFolder: (parentDir: string, folderName: string) => Promise<OperationResult<{
|
|
95
|
+
finalPath: string;
|
|
96
|
+
}>>;
|
|
97
|
+
createFile: (parentDir: string, fileName: string, content?: string) => Promise<OperationResult<{
|
|
98
|
+
finalPath: string;
|
|
99
|
+
}>>;
|
|
100
|
+
deleteFiles: (paths: string[]) => Promise<OperationResult>;
|
|
101
|
+
renameFile: (oldPath: string, newPath: string) => Promise<OperationResult>;
|
|
102
|
+
copyFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
|
|
103
|
+
copiedPaths: string[];
|
|
104
|
+
}>>;
|
|
105
|
+
moveFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
|
|
106
|
+
movedPaths: string[];
|
|
107
|
+
}>>;
|
|
108
|
+
getFileInfo: (filePath: string) => Promise<OperationResult<FileInfo>>;
|
|
109
|
+
readImageAsBase64: (imagePath: string) => Promise<{
|
|
110
|
+
success: boolean;
|
|
111
|
+
base64?: string;
|
|
112
|
+
mimeType?: string;
|
|
113
|
+
error?: string;
|
|
114
|
+
}>;
|
|
115
|
+
openPath: (filePath: string) => Promise<OperationResult>;
|
|
116
|
+
getApplicationIcon: (appPath: string) => Promise<string | null>;
|
|
117
|
+
getThumbnailUrl: (filePath: string) => Promise<string | null>;
|
|
118
|
+
copyFilesToClipboard: (filePaths: string[]) => Promise<OperationResult>;
|
|
119
|
+
getClipboardFiles: () => Promise<OperationResult<{
|
|
120
|
+
files: string[];
|
|
121
|
+
}>>;
|
|
122
|
+
pasteFiles: (targetDir: string, sourcePaths: string[]) => Promise<OperationResult<{
|
|
123
|
+
pastedPaths: string[];
|
|
124
|
+
}>>;
|
|
125
|
+
searchFiles: (searchPath: string, pattern: string, maxDepth?: number) => Promise<OperationResult<{
|
|
126
|
+
items: FileItem[];
|
|
127
|
+
total: number;
|
|
128
|
+
}>>;
|
|
129
|
+
searchFilesStream: (searchPath: string, pattern: string, searchId: string) => Promise<OperationResult>;
|
|
130
|
+
onSearchResults: (callback: (data: {
|
|
131
|
+
searchId: string;
|
|
132
|
+
items: FileItem[];
|
|
133
|
+
done: boolean;
|
|
134
|
+
}) => void) => () => void;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 创建 Electron 适配器
|
|
140
|
+
*
|
|
141
|
+
* 在渲染进程中使用:
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { createElectronAdapter } from '@aspect/file-explorer-bridge-electron/renderer';
|
|
144
|
+
* const adapter = createElectronAdapter();
|
|
145
|
+
* const files = await adapter.readDirectory('/path/to/dir');
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
declare function createElectronAdapter(): FileExplorerAdapter;
|
|
149
|
+
|
|
150
|
+
export { type FileExplorerAdapter, createElectronAdapter };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { FileItem, OperationResult, FileInfo } from '@huyooo/file-explorer-core';
|
|
2
|
+
export { FileInfo, FileItem, OperationResult, SystemPathId } from '@huyooo/file-explorer-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* File Explorer Electron Bridge - Renderer Process
|
|
6
|
+
*
|
|
7
|
+
* 提供渲染进程使用的适配器
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 文件操作适配器接口
|
|
12
|
+
*/
|
|
13
|
+
interface FileExplorerAdapter {
|
|
14
|
+
/** 读取目录 */
|
|
15
|
+
readDirectory(dirPath: string): Promise<FileItem[]>;
|
|
16
|
+
/** 读取系统路径目录 */
|
|
17
|
+
readSystemPath(pathId: string): Promise<FileItem[]>;
|
|
18
|
+
/** 获取系统路径 */
|
|
19
|
+
getSystemPath(pathId: string): Promise<string | null>;
|
|
20
|
+
/** 读取文件内容 */
|
|
21
|
+
readFileContent(filePath: string): Promise<string>;
|
|
22
|
+
/** 写入文件内容 */
|
|
23
|
+
writeFileContent(filePath: string, content: string): Promise<OperationResult>;
|
|
24
|
+
/** 创建文件夹 */
|
|
25
|
+
createFolder(parentDir: string, folderName: string): Promise<OperationResult<{
|
|
26
|
+
finalPath: string;
|
|
27
|
+
}>>;
|
|
28
|
+
/** 创建文件 */
|
|
29
|
+
createFile(parentDir: string, fileName: string, content?: string): Promise<OperationResult<{
|
|
30
|
+
finalPath: string;
|
|
31
|
+
}>>;
|
|
32
|
+
/** 删除文件 */
|
|
33
|
+
deleteFiles(paths: string[]): Promise<OperationResult>;
|
|
34
|
+
/** 重命名文件 */
|
|
35
|
+
renameFile(oldPath: string, newPath: string): Promise<OperationResult>;
|
|
36
|
+
/** 复制文件 */
|
|
37
|
+
copyFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
|
|
38
|
+
copiedPaths: string[];
|
|
39
|
+
}>>;
|
|
40
|
+
/** 移动文件 */
|
|
41
|
+
moveFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
|
|
42
|
+
movedPaths: string[];
|
|
43
|
+
}>>;
|
|
44
|
+
/** 获取文件信息 */
|
|
45
|
+
getFileInfo(filePath: string): Promise<OperationResult<FileInfo>>;
|
|
46
|
+
/** 读取图片为 Base64 */
|
|
47
|
+
readImageAsBase64(imagePath: string): Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
base64?: string;
|
|
50
|
+
mimeType?: string;
|
|
51
|
+
error?: string;
|
|
52
|
+
}>;
|
|
53
|
+
/** 使用系统默认应用打开 */
|
|
54
|
+
openPath(filePath: string): Promise<OperationResult>;
|
|
55
|
+
/** 获取应用程序图标 */
|
|
56
|
+
getApplicationIcon(appPath: string): Promise<string | null>;
|
|
57
|
+
/** 获取缩略图 URL */
|
|
58
|
+
getThumbnailUrl(filePath: string): Promise<string | null>;
|
|
59
|
+
/** 复制文件到剪贴板 */
|
|
60
|
+
copyFilesToClipboard(filePaths: string[]): Promise<OperationResult>;
|
|
61
|
+
/** 从剪贴板获取文件 */
|
|
62
|
+
getClipboardFiles(): Promise<OperationResult<{
|
|
63
|
+
files: string[];
|
|
64
|
+
}>>;
|
|
65
|
+
/** 粘贴文件 */
|
|
66
|
+
pasteFiles(targetDir: string, sourcePaths: string[]): Promise<OperationResult<{
|
|
67
|
+
pastedPaths: string[];
|
|
68
|
+
}>>;
|
|
69
|
+
/** 搜索文件 */
|
|
70
|
+
searchFiles(searchPath: string, pattern: string, maxDepth?: number): Promise<OperationResult<{
|
|
71
|
+
items: FileItem[];
|
|
72
|
+
total: number;
|
|
73
|
+
}>>;
|
|
74
|
+
/** 流式搜索文件 */
|
|
75
|
+
searchFilesStream(searchPath: string, pattern: string, searchId: string): Promise<OperationResult>;
|
|
76
|
+
/** 监听搜索结果 */
|
|
77
|
+
onSearchResults(callback: (data: {
|
|
78
|
+
searchId: string;
|
|
79
|
+
items: FileItem[];
|
|
80
|
+
done: boolean;
|
|
81
|
+
}) => void): () => void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Window 扩展类型
|
|
85
|
+
*/
|
|
86
|
+
declare global {
|
|
87
|
+
interface Window {
|
|
88
|
+
fileExplorerAPI?: {
|
|
89
|
+
readDirectory: (dirPath: string) => Promise<FileItem[]>;
|
|
90
|
+
readSystemPath: (pathId: string) => Promise<FileItem[]>;
|
|
91
|
+
getSystemPath: (pathId: string) => Promise<string | null>;
|
|
92
|
+
readFileContent: (filePath: string) => Promise<string>;
|
|
93
|
+
writeFileContent: (filePath: string, content: string) => Promise<OperationResult>;
|
|
94
|
+
createFolder: (parentDir: string, folderName: string) => Promise<OperationResult<{
|
|
95
|
+
finalPath: string;
|
|
96
|
+
}>>;
|
|
97
|
+
createFile: (parentDir: string, fileName: string, content?: string) => Promise<OperationResult<{
|
|
98
|
+
finalPath: string;
|
|
99
|
+
}>>;
|
|
100
|
+
deleteFiles: (paths: string[]) => Promise<OperationResult>;
|
|
101
|
+
renameFile: (oldPath: string, newPath: string) => Promise<OperationResult>;
|
|
102
|
+
copyFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
|
|
103
|
+
copiedPaths: string[];
|
|
104
|
+
}>>;
|
|
105
|
+
moveFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
|
|
106
|
+
movedPaths: string[];
|
|
107
|
+
}>>;
|
|
108
|
+
getFileInfo: (filePath: string) => Promise<OperationResult<FileInfo>>;
|
|
109
|
+
readImageAsBase64: (imagePath: string) => Promise<{
|
|
110
|
+
success: boolean;
|
|
111
|
+
base64?: string;
|
|
112
|
+
mimeType?: string;
|
|
113
|
+
error?: string;
|
|
114
|
+
}>;
|
|
115
|
+
openPath: (filePath: string) => Promise<OperationResult>;
|
|
116
|
+
getApplicationIcon: (appPath: string) => Promise<string | null>;
|
|
117
|
+
getThumbnailUrl: (filePath: string) => Promise<string | null>;
|
|
118
|
+
copyFilesToClipboard: (filePaths: string[]) => Promise<OperationResult>;
|
|
119
|
+
getClipboardFiles: () => Promise<OperationResult<{
|
|
120
|
+
files: string[];
|
|
121
|
+
}>>;
|
|
122
|
+
pasteFiles: (targetDir: string, sourcePaths: string[]) => Promise<OperationResult<{
|
|
123
|
+
pastedPaths: string[];
|
|
124
|
+
}>>;
|
|
125
|
+
searchFiles: (searchPath: string, pattern: string, maxDepth?: number) => Promise<OperationResult<{
|
|
126
|
+
items: FileItem[];
|
|
127
|
+
total: number;
|
|
128
|
+
}>>;
|
|
129
|
+
searchFilesStream: (searchPath: string, pattern: string, searchId: string) => Promise<OperationResult>;
|
|
130
|
+
onSearchResults: (callback: (data: {
|
|
131
|
+
searchId: string;
|
|
132
|
+
items: FileItem[];
|
|
133
|
+
done: boolean;
|
|
134
|
+
}) => void) => () => void;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 创建 Electron 适配器
|
|
140
|
+
*
|
|
141
|
+
* 在渲染进程中使用:
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { createElectronAdapter } from '@aspect/file-explorer-bridge-electron/renderer';
|
|
144
|
+
* const adapter = createElectronAdapter();
|
|
145
|
+
* const files = await adapter.readDirectory('/path/to/dir');
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
declare function createElectronAdapter(): FileExplorerAdapter;
|
|
149
|
+
|
|
150
|
+
export { type FileExplorerAdapter, createElectronAdapter };
|