@huyooo/file-explorer-bridge-electron 0.4.3 → 0.4.6

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.
@@ -30,10 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/main/index.ts
31
31
  var main_exports = {};
32
32
  __export(main_exports, {
33
- createElectronAdapter: () => createElectronAdapter,
34
- electronUrlEncoder: () => electronUrlEncoder,
35
- registerFileExplorerHandlers: () => registerFileExplorerHandlers,
36
- setClipboardAdapter: () => setClipboardAdapter
33
+ registerFileExplorer: () => registerFileExplorer
37
34
  });
38
35
  module.exports = __toCommonJS(main_exports);
39
36
  var import_electron = require("electron");
@@ -41,10 +38,8 @@ var import_node_path = __toESM(require("path"), 1);
41
38
  var import_file_explorer_core = require("@huyooo/file-explorer-core");
42
39
  var import_node_fs = require("fs");
43
40
  var import_path = require("@huyooo/file-explorer-preview/path");
44
- var CHANNEL_PREFIX = "file-explorer";
45
- var PREVIEW_CHANNEL_PREFIX = "file-explorer-preview";
46
- var channel = (name) => `${CHANNEL_PREFIX}:${name}`;
47
- var previewChannel = (name) => `${PREVIEW_CHANNEL_PREFIX}:${name}`;
41
+ var DEFAULT_CHANNEL_PREFIX = "file-explorer";
42
+ var DEFAULT_PREVIEW_CHANNEL_PREFIX = "file-explorer-preview";
48
43
  var clipboardAdapter = null;
49
44
  function setClipboardAdapter(adapter) {
50
45
  clipboardAdapter = adapter;
@@ -64,6 +59,10 @@ var explorerOptions = {};
64
59
  var mediaPreviewWindows = /* @__PURE__ */ new Map();
65
60
  function registerFileExplorerHandlers(options = {}) {
66
61
  explorerOptions = options;
62
+ const channelPrefix = options.channelPrefix || DEFAULT_CHANNEL_PREFIX;
63
+ const previewChannelPrefix = options.previewChannelPrefix || DEFAULT_PREVIEW_CHANNEL_PREFIX;
64
+ const channel = (name) => `${channelPrefix}:${name}`;
65
+ const previewChannel = (name) => `${previewChannelPrefix}:${name}`;
67
66
  const adapter = createElectronAdapter();
68
67
  import_electron.ipcMain.handle(channel("readDirectory"), async (_event, dirPath) => {
69
68
  const thumbnailService = (0, import_file_explorer_core.getThumbnailService)();
@@ -505,10 +504,13 @@ function registerFileExplorerHandlers(options = {}) {
505
504
  });
506
505
  console.log("\u2705 File Explorer IPC handlers registered");
507
506
  }
507
+ function registerFileExplorer(options = {}) {
508
+ if (options.clipboardAdapter) {
509
+ setClipboardAdapter(options.clipboardAdapter);
510
+ }
511
+ registerFileExplorerHandlers(options);
512
+ }
508
513
  // Annotate the CommonJS export names for ESM import in node:
509
514
  0 && (module.exports = {
510
- createElectronAdapter,
511
- electronUrlEncoder,
512
- registerFileExplorerHandlers,
513
- setClipboardAdapter
515
+ registerFileExplorer
514
516
  });
@@ -1,4 +1,4 @@
1
- import { PlatformAdapter, encodeFileUrl, ClipboardAdapter } from '@huyooo/file-explorer-core';
1
+ import { ClipboardAdapter } from '@huyooo/file-explorer-core';
2
2
 
3
3
  /**
4
4
  * File Explorer Electron Bridge - Main Process
@@ -6,26 +6,25 @@ import { PlatformAdapter, encodeFileUrl, ClipboardAdapter } from '@huyooo/file-e
6
6
  * 只负责 IPC 通信,具体实现在 @huyooo/file-explorer-core 中
7
7
  */
8
8
 
9
- /**
10
- * 设置剪贴板适配器
11
- * 在主进程中调用,注入 clipboard-files 模块
12
- */
13
- declare function setClipboardAdapter(adapter: ClipboardAdapter): void;
14
- /**
15
- * 创建 Electron 平台适配器
16
- */
17
- declare function createElectronAdapter(): PlatformAdapter;
18
- /** URL 编码器(使用 core 中的协议工具) */
19
- declare const electronUrlEncoder: typeof encodeFileUrl;
20
9
  /** 文件管理器配置选项 */
21
10
  interface FileExplorerOptions {
22
11
  /** 在新窗口中打开文件夹的回调 */
23
12
  onOpenInNewWindow?: (folderPath: string) => void;
13
+ /** IPC 通道名称前缀(允许宿主自定义,避免冲突) */
14
+ channelPrefix?: string;
15
+ /** 预览窗口 IPC 通道前缀(一般不需要改) */
16
+ previewChannelPrefix?: string;
17
+ }
18
+ interface RegisterFileExplorerOptions extends FileExplorerOptions {
19
+ /** 注入剪贴板适配器(例如 clipboard-files) */
20
+ clipboardAdapter?: ClipboardAdapter;
24
21
  }
25
22
  /**
26
- * 注册文件系统 IPC handlers
27
- * @param options 可选配置
23
+ * 高层入口:注册 File Explorer(主进程)
24
+ *
25
+ * - 可选注入 `clipboardAdapter`
26
+ * - 可选自定义 `channelPrefix` 避免多实例冲突
28
27
  */
29
- declare function registerFileExplorerHandlers(options?: FileExplorerOptions): void;
28
+ declare function registerFileExplorer(options?: RegisterFileExplorerOptions): void;
30
29
 
31
- export { type FileExplorerOptions, createElectronAdapter, electronUrlEncoder, registerFileExplorerHandlers, setClipboardAdapter };
30
+ export { type FileExplorerOptions, type RegisterFileExplorerOptions, registerFileExplorer };
@@ -1,4 +1,4 @@
1
- import { PlatformAdapter, encodeFileUrl, ClipboardAdapter } from '@huyooo/file-explorer-core';
1
+ import { ClipboardAdapter } from '@huyooo/file-explorer-core';
2
2
 
3
3
  /**
4
4
  * File Explorer Electron Bridge - Main Process
@@ -6,26 +6,25 @@ import { PlatformAdapter, encodeFileUrl, ClipboardAdapter } from '@huyooo/file-e
6
6
  * 只负责 IPC 通信,具体实现在 @huyooo/file-explorer-core 中
7
7
  */
8
8
 
9
- /**
10
- * 设置剪贴板适配器
11
- * 在主进程中调用,注入 clipboard-files 模块
12
- */
13
- declare function setClipboardAdapter(adapter: ClipboardAdapter): void;
14
- /**
15
- * 创建 Electron 平台适配器
16
- */
17
- declare function createElectronAdapter(): PlatformAdapter;
18
- /** URL 编码器(使用 core 中的协议工具) */
19
- declare const electronUrlEncoder: typeof encodeFileUrl;
20
9
  /** 文件管理器配置选项 */
21
10
  interface FileExplorerOptions {
22
11
  /** 在新窗口中打开文件夹的回调 */
23
12
  onOpenInNewWindow?: (folderPath: string) => void;
13
+ /** IPC 通道名称前缀(允许宿主自定义,避免冲突) */
14
+ channelPrefix?: string;
15
+ /** 预览窗口 IPC 通道前缀(一般不需要改) */
16
+ previewChannelPrefix?: string;
17
+ }
18
+ interface RegisterFileExplorerOptions extends FileExplorerOptions {
19
+ /** 注入剪贴板适配器(例如 clipboard-files) */
20
+ clipboardAdapter?: ClipboardAdapter;
24
21
  }
25
22
  /**
26
- * 注册文件系统 IPC handlers
27
- * @param options 可选配置
23
+ * 高层入口:注册 File Explorer(主进程)
24
+ *
25
+ * - 可选注入 `clipboardAdapter`
26
+ * - 可选自定义 `channelPrefix` 避免多实例冲突
28
27
  */
29
- declare function registerFileExplorerHandlers(options?: FileExplorerOptions): void;
28
+ declare function registerFileExplorer(options?: RegisterFileExplorerOptions): void;
30
29
 
31
- export { type FileExplorerOptions, createElectronAdapter, electronUrlEncoder, registerFileExplorerHandlers, setClipboardAdapter };
30
+ export { type FileExplorerOptions, type RegisterFileExplorerOptions, registerFileExplorer };
@@ -36,10 +36,8 @@ import {
36
36
  } from "@huyooo/file-explorer-core";
37
37
  import { promises as fs } from "fs";
38
38
  import { getPreviewHtmlPath } from "@huyooo/file-explorer-preview/path";
39
- var CHANNEL_PREFIX = "file-explorer";
40
- var PREVIEW_CHANNEL_PREFIX = "file-explorer-preview";
41
- var channel = (name) => `${CHANNEL_PREFIX}:${name}`;
42
- var previewChannel = (name) => `${PREVIEW_CHANNEL_PREFIX}:${name}`;
39
+ var DEFAULT_CHANNEL_PREFIX = "file-explorer";
40
+ var DEFAULT_PREVIEW_CHANNEL_PREFIX = "file-explorer-preview";
43
41
  var clipboardAdapter = null;
44
42
  function setClipboardAdapter(adapter) {
45
43
  clipboardAdapter = adapter;
@@ -59,6 +57,10 @@ var explorerOptions = {};
59
57
  var mediaPreviewWindows = /* @__PURE__ */ new Map();
60
58
  function registerFileExplorerHandlers(options = {}) {
61
59
  explorerOptions = options;
60
+ const channelPrefix = options.channelPrefix || DEFAULT_CHANNEL_PREFIX;
61
+ const previewChannelPrefix = options.previewChannelPrefix || DEFAULT_PREVIEW_CHANNEL_PREFIX;
62
+ const channel = (name) => `${channelPrefix}:${name}`;
63
+ const previewChannel = (name) => `${previewChannelPrefix}:${name}`;
62
64
  const adapter = createElectronAdapter();
63
65
  ipcMain.handle(channel("readDirectory"), async (_event, dirPath) => {
64
66
  const thumbnailService = getThumbnailService();
@@ -500,9 +502,12 @@ function registerFileExplorerHandlers(options = {}) {
500
502
  });
501
503
  console.log("\u2705 File Explorer IPC handlers registered");
502
504
  }
505
+ function registerFileExplorer(options = {}) {
506
+ if (options.clipboardAdapter) {
507
+ setClipboardAdapter(options.clipboardAdapter);
508
+ }
509
+ registerFileExplorerHandlers(options);
510
+ }
503
511
  export {
504
- createElectronAdapter,
505
- electronUrlEncoder,
506
- registerFileExplorerHandlers,
507
- setClipboardAdapter
512
+ registerFileExplorer
508
513
  };
@@ -20,14 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/preload/index.ts
21
21
  var preload_exports = {};
22
22
  __export(preload_exports, {
23
- createFileExplorerAPI: () => createFileExplorerAPI,
24
23
  exposeFileExplorerAPI: () => exposeFileExplorerAPI
25
24
  });
26
25
  module.exports = __toCommonJS(preload_exports);
27
26
  var import_electron = require("electron");
28
- var CHANNEL_PREFIX = "file-explorer";
29
- var channel = (name) => `${CHANNEL_PREFIX}:${name}`;
30
- function createFileExplorerAPI() {
27
+ var DEFAULT_CHANNEL_PREFIX = "file-explorer";
28
+ function createFileExplorerAPI(options = {}) {
29
+ const channelPrefix = options.channelPrefix || DEFAULT_CHANNEL_PREFIX;
30
+ const channel = (name) => `${channelPrefix}:${name}`;
31
31
  return {
32
32
  readDirectory: (dirPath) => import_electron.ipcRenderer.invoke(channel("readDirectory"), dirPath),
33
33
  readSystemPath: (pathId) => import_electron.ipcRenderer.invoke(channel("readSystemPath"), pathId),
@@ -57,8 +57,8 @@ function createFileExplorerAPI() {
57
57
  import_electron.ipcRenderer.on(channel("searchResults"), handler);
58
58
  return () => import_electron.ipcRenderer.removeListener(channel("searchResults"), handler);
59
59
  },
60
- compressFiles: (sources, options) => import_electron.ipcRenderer.invoke(channel("compressFiles"), sources, options),
61
- extractArchive: (archivePath, options) => import_electron.ipcRenderer.invoke(channel("extractArchive"), archivePath, options),
60
+ compressFiles: (sources, options2) => import_electron.ipcRenderer.invoke(channel("compressFiles"), sources, options2),
61
+ extractArchive: (archivePath, options2) => import_electron.ipcRenderer.invoke(channel("extractArchive"), archivePath, options2),
62
62
  isArchiveFile: (filePath) => import_electron.ipcRenderer.invoke(channel("isArchiveFile"), filePath),
63
63
  onCompressProgress: (callback) => {
64
64
  const handler = (_event, data) => {
@@ -105,13 +105,13 @@ function createFileExplorerAPI() {
105
105
  closeMediaPreviewWindow: (filePath) => import_electron.ipcRenderer.invoke(channel("closeMediaPreviewWindow"), filePath)
106
106
  };
107
107
  }
108
- function exposeFileExplorerAPI(apiName = "fileExplorerAPI") {
109
- const api = createFileExplorerAPI();
108
+ function exposeFileExplorerAPI(options = {}) {
109
+ const apiName = options.apiName || "fileExplorerAPI";
110
+ const api = createFileExplorerAPI({ channelPrefix: options.channelPrefix });
110
111
  import_electron.contextBridge.exposeInMainWorld(apiName, api);
111
112
  console.log(`\u2705 File Explorer API exposed as window.${apiName}`);
112
113
  }
113
114
  // Annotate the CommonJS export names for ESM import in node:
114
115
  0 && (module.exports = {
115
- createFileExplorerAPI,
116
116
  exposeFileExplorerAPI
117
117
  });
@@ -260,19 +260,19 @@ interface FileExplorerAPI {
260
260
  error?: string;
261
261
  }>;
262
262
  }
263
- /**
264
- * 创建文件操作 API
265
- */
266
- declare function createFileExplorerAPI(): FileExplorerAPI;
267
263
  /**
268
264
  * 暴露文件操作 API 到渲染进程
269
265
  *
270
266
  * 在 preload.ts 中调用:
271
267
  * ```ts
272
- * import { exposeFileExplorerAPI } from '@aspect/file-explorer-bridge-electron/preload';
273
- * exposeFileExplorerAPI();
268
+ * import { exposeFileExplorerAPI } from '@huyooo/file-explorer-bridge-electron/preload';
269
+ * exposeFileExplorerAPI({});
274
270
  * ```
275
271
  */
276
- declare function exposeFileExplorerAPI(apiName?: string): void;
272
+ interface ExposeFileExplorerAPIOptions {
273
+ apiName?: string;
274
+ channelPrefix?: string;
275
+ }
276
+ declare function exposeFileExplorerAPI(options?: ExposeFileExplorerAPIOptions): void;
277
277
 
278
- export { type FileExplorerAPI, createFileExplorerAPI, exposeFileExplorerAPI };
278
+ export { type ExposeFileExplorerAPIOptions, type FileExplorerAPI, exposeFileExplorerAPI };
@@ -260,19 +260,19 @@ interface FileExplorerAPI {
260
260
  error?: string;
261
261
  }>;
262
262
  }
263
- /**
264
- * 创建文件操作 API
265
- */
266
- declare function createFileExplorerAPI(): FileExplorerAPI;
267
263
  /**
268
264
  * 暴露文件操作 API 到渲染进程
269
265
  *
270
266
  * 在 preload.ts 中调用:
271
267
  * ```ts
272
- * import { exposeFileExplorerAPI } from '@aspect/file-explorer-bridge-electron/preload';
273
- * exposeFileExplorerAPI();
268
+ * import { exposeFileExplorerAPI } from '@huyooo/file-explorer-bridge-electron/preload';
269
+ * exposeFileExplorerAPI({});
274
270
  * ```
275
271
  */
276
- declare function exposeFileExplorerAPI(apiName?: string): void;
272
+ interface ExposeFileExplorerAPIOptions {
273
+ apiName?: string;
274
+ channelPrefix?: string;
275
+ }
276
+ declare function exposeFileExplorerAPI(options?: ExposeFileExplorerAPIOptions): void;
277
277
 
278
- export { type FileExplorerAPI, createFileExplorerAPI, exposeFileExplorerAPI };
278
+ export { type ExposeFileExplorerAPIOptions, type FileExplorerAPI, exposeFileExplorerAPI };
@@ -1,8 +1,9 @@
1
1
  // src/preload/index.ts
2
2
  import { contextBridge, ipcRenderer } from "electron";
3
- var CHANNEL_PREFIX = "file-explorer";
4
- var channel = (name) => `${CHANNEL_PREFIX}:${name}`;
5
- function createFileExplorerAPI() {
3
+ var DEFAULT_CHANNEL_PREFIX = "file-explorer";
4
+ function createFileExplorerAPI(options = {}) {
5
+ const channelPrefix = options.channelPrefix || DEFAULT_CHANNEL_PREFIX;
6
+ const channel = (name) => `${channelPrefix}:${name}`;
6
7
  return {
7
8
  readDirectory: (dirPath) => ipcRenderer.invoke(channel("readDirectory"), dirPath),
8
9
  readSystemPath: (pathId) => ipcRenderer.invoke(channel("readSystemPath"), pathId),
@@ -32,8 +33,8 @@ function createFileExplorerAPI() {
32
33
  ipcRenderer.on(channel("searchResults"), handler);
33
34
  return () => ipcRenderer.removeListener(channel("searchResults"), handler);
34
35
  },
35
- compressFiles: (sources, options) => ipcRenderer.invoke(channel("compressFiles"), sources, options),
36
- extractArchive: (archivePath, options) => ipcRenderer.invoke(channel("extractArchive"), archivePath, options),
36
+ compressFiles: (sources, options2) => ipcRenderer.invoke(channel("compressFiles"), sources, options2),
37
+ extractArchive: (archivePath, options2) => ipcRenderer.invoke(channel("extractArchive"), archivePath, options2),
37
38
  isArchiveFile: (filePath) => ipcRenderer.invoke(channel("isArchiveFile"), filePath),
38
39
  onCompressProgress: (callback) => {
39
40
  const handler = (_event, data) => {
@@ -80,12 +81,12 @@ function createFileExplorerAPI() {
80
81
  closeMediaPreviewWindow: (filePath) => ipcRenderer.invoke(channel("closeMediaPreviewWindow"), filePath)
81
82
  };
82
83
  }
83
- function exposeFileExplorerAPI(apiName = "fileExplorerAPI") {
84
- const api = createFileExplorerAPI();
84
+ function exposeFileExplorerAPI(options = {}) {
85
+ const apiName = options.apiName || "fileExplorerAPI";
86
+ const api = createFileExplorerAPI({ channelPrefix: options.channelPrefix });
85
87
  contextBridge.exposeInMainWorld(apiName, api);
86
88
  console.log(`\u2705 File Explorer API exposed as window.${apiName}`);
87
89
  }
88
90
  export {
89
- createFileExplorerAPI,
90
91
  exposeFileExplorerAPI
91
92
  };
@@ -20,60 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/renderer/index.ts
21
21
  var renderer_exports = {};
22
22
  __export(renderer_exports, {
23
- createElectronAdapter: () => createElectronAdapter
23
+ createFileExplorerClient: () => createFileExplorerClient
24
24
  });
25
25
  module.exports = __toCommonJS(renderer_exports);
26
- function createElectronAdapter() {
27
- const api = window.fileExplorerAPI;
26
+ function createFileExplorerClient(apiName = "fileExplorerAPI") {
27
+ const api = apiName === "fileExplorerAPI" ? window.fileExplorerAPI : window[apiName];
28
28
  if (!api) {
29
29
  throw new Error(
30
- "window.fileExplorerAPI not found. Make sure to call exposeFileExplorerAPI() in your preload script."
30
+ `window.${apiName} not found. Make sure to call exposeFileExplorerAPI({ apiName }) in your preload script.`
31
31
  );
32
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
- compressFiles: (sources, options) => api.compressFiles(sources, options),
57
- extractArchive: (archivePath, options) => api.extractArchive(archivePath, options),
58
- isArchiveFile: (filePath) => api.isArchiveFile(filePath),
59
- onCompressProgress: (callback) => api.onCompressProgress(callback),
60
- onExtractProgress: (callback) => api.onExtractProgress(callback),
61
- watchDirectory: (dirPath, watchId) => api.watchDirectory(dirPath, watchId),
62
- unwatchDirectory: (watchId) => api.unwatchDirectory(watchId),
63
- onWatchEvent: (callback) => api.onWatchEvent(callback),
64
- showFileInfo: (filePath) => api.showFileInfo(filePath),
65
- openInTerminal: (dirPath) => api.openInTerminal(dirPath),
66
- openInEditor: (targetPath) => api.openInEditor(targetPath),
67
- openInNewWindow: (folderPath) => api.openInNewWindow(folderPath),
68
- requestWindowFocus: () => api.requestWindowFocus(),
69
- // 媒体服务
70
- mediaNeedsTranscode: (filePath) => api.mediaNeedsTranscode(filePath),
71
- mediaGetPlayableUrl: (filePath) => api.mediaGetPlayableUrl(filePath),
72
- mediaGetMetadata: (filePath) => api.mediaGetMetadata(filePath),
73
- onMediaTranscodeProgress: (callback) => api.onMediaTranscodeProgress(callback),
74
- mediaCleanupFile: (filePath) => api.mediaCleanupFile(filePath),
75
- // 媒体预览窗口
76
- openMediaPreviewWindow: (filePath, mediaType) => api.openMediaPreviewWindow(filePath, mediaType),
77
- closeMediaPreviewWindow: (filePath) => api.closeMediaPreviewWindow(filePath)
78
- };
33
+ const typedApi = api;
34
+ return typedApi;
79
35
  }
@@ -1,193 +1,11 @@
1
- import { FileItem, OperationResult, FileInfo, CompressFormat, CompressLevel } from '@huyooo/file-explorer-core';
2
- export { CompressFormat, CompressLevel, FileInfo, FileItem, OperationResult, SystemPathId } from '@huyooo/file-explorer-core';
1
+ import { FileItem, OperationResult, FileInfo, CompressOptions, CompressResult, ExtractOptions, CompressProgress, WatchEvent, TranscodeInfo, MediaMetadata, TranscodeProgress } from '@huyooo/file-explorer-core';
3
2
 
4
3
  /**
5
4
  * File Explorer Electron Bridge - Renderer Process
6
5
  *
7
- * 提供渲染进程使用的适配器
6
+ * 提供渲染进程使用的 client(仅保留 runtime 入口)
8
7
  */
9
8
 
10
- /** 压缩选项 */
11
- interface CompressOptions {
12
- format: CompressFormat;
13
- level?: CompressLevel;
14
- outputName: string;
15
- outputDir: string;
16
- deleteSource?: boolean;
17
- }
18
- /** 解压选项 */
19
- interface ExtractOptions {
20
- targetDir: string;
21
- deleteArchive?: boolean;
22
- }
23
- /** 压缩进度 */
24
- interface CompressProgress {
25
- currentFile: string;
26
- processedCount: number;
27
- totalCount: number;
28
- percent: number;
29
- }
30
- /** 压缩结果 */
31
- interface CompressResult {
32
- success: boolean;
33
- outputPath?: string;
34
- error?: string;
35
- }
36
- /** 文件变化事件类型 */
37
- type WatchEventType = 'add' | 'change' | 'remove' | 'rename';
38
- /** 文件变化事件 */
39
- interface WatchEvent {
40
- type: WatchEventType;
41
- path: string;
42
- filename: string;
43
- }
44
- /** 媒体转码信息 */
45
- interface TranscodeInfo {
46
- type: 'video' | 'audio';
47
- needsTranscode: boolean;
48
- method: 'direct' | 'remux' | 'transcode';
49
- estimatedTime?: number;
50
- targetFormat?: string;
51
- }
52
- /** 媒体转码进度 */
53
- interface MediaTranscodeProgress {
54
- percent: number;
55
- time?: number;
56
- duration?: number;
57
- speed?: string;
58
- }
59
- /** 媒体元数据 */
60
- interface MediaMetadata {
61
- filePath: string;
62
- type: 'video' | 'audio';
63
- duration: number;
64
- title?: string;
65
- artist?: string;
66
- album?: string;
67
- }
68
- /**
69
- * 文件操作适配器接口
70
- */
71
- interface FileExplorerAdapter {
72
- /** 读取目录 */
73
- readDirectory(dirPath: string): Promise<FileItem[]>;
74
- /** 读取系统路径目录 */
75
- readSystemPath(pathId: string): Promise<FileItem[]>;
76
- /** 获取系统路径 */
77
- getSystemPath(pathId: string): Promise<string | null>;
78
- /** 读取文件内容 */
79
- readFileContent(filePath: string): Promise<string>;
80
- /** 写入文件内容 */
81
- writeFileContent(filePath: string, content: string): Promise<OperationResult>;
82
- /** 创建文件夹 */
83
- createFolder(parentDir: string, folderName: string): Promise<OperationResult<{
84
- finalPath: string;
85
- }>>;
86
- /** 创建文件 */
87
- createFile(parentDir: string, fileName: string, content?: string): Promise<OperationResult<{
88
- finalPath: string;
89
- }>>;
90
- /** 删除文件 */
91
- deleteFiles(paths: string[]): Promise<OperationResult>;
92
- /** 重命名文件 */
93
- renameFile(oldPath: string, newPath: string): Promise<OperationResult>;
94
- /** 复制文件 */
95
- copyFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
96
- copiedPaths: string[];
97
- }>>;
98
- /** 移动文件 */
99
- moveFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
100
- movedPaths: string[];
101
- }>>;
102
- /** 获取文件信息 */
103
- getFileInfo(filePath: string): Promise<OperationResult<FileInfo>>;
104
- /** 读取图片为 Base64 */
105
- readImageAsBase64(imagePath: string): Promise<{
106
- success: boolean;
107
- base64?: string;
108
- mimeType?: string;
109
- error?: string;
110
- }>;
111
- /** 使用系统默认应用打开 */
112
- openPath(filePath: string): Promise<OperationResult>;
113
- /** 获取应用程序图标 */
114
- getApplicationIcon(appPath: string): Promise<string | null>;
115
- /** 获取缩略图 URL */
116
- getThumbnailUrl(filePath: string): Promise<string | null>;
117
- /** 复制文件到剪贴板 */
118
- copyFilesToClipboard(filePaths: string[]): Promise<OperationResult>;
119
- /** 从剪贴板获取文件 */
120
- getClipboardFiles(): Promise<OperationResult<{
121
- files: string[];
122
- }>>;
123
- /** 粘贴文件 */
124
- pasteFiles(targetDir: string, sourcePaths: string[]): Promise<OperationResult<{
125
- pastedPaths: string[];
126
- }>>;
127
- /** 搜索文件 */
128
- searchFiles(searchPath: string, pattern: string, maxDepth?: number): Promise<OperationResult<{
129
- items: FileItem[];
130
- total: number;
131
- }>>;
132
- /** 流式搜索文件 */
133
- searchFilesStream(searchPath: string, pattern: string, searchId: string): Promise<OperationResult>;
134
- /** 监听搜索结果 */
135
- onSearchResults(callback: (data: {
136
- searchId: string;
137
- items: FileItem[];
138
- done: boolean;
139
- }) => void): () => void;
140
- /** 压缩文件 */
141
- compressFiles(sources: string[], options: CompressOptions): Promise<CompressResult>;
142
- /** 解压文件 */
143
- extractArchive(archivePath: string, options: ExtractOptions): Promise<CompressResult>;
144
- /** 判断是否为压缩文件 */
145
- isArchiveFile(filePath: string): Promise<boolean>;
146
- /** 监听压缩进度 */
147
- onCompressProgress(callback: (data: CompressProgress) => void): () => void;
148
- /** 监听解压进度 */
149
- onExtractProgress(callback: (data: CompressProgress) => void): () => void;
150
- /** 监听目录变化 */
151
- watchDirectory(dirPath: string, watchId: string): Promise<OperationResult>;
152
- /** 停止监听目录 */
153
- unwatchDirectory(watchId: string): Promise<OperationResult>;
154
- /** 监听文件变化事件 */
155
- onWatchEvent(callback: (data: {
156
- watchId: string;
157
- event: WatchEvent;
158
- }) => void): () => void;
159
- /** 显示文件/文件夹的系统属性窗口 */
160
- showFileInfo(filePath: string): Promise<OperationResult>;
161
- /** 在终端中打开目录 */
162
- openInTerminal(dirPath: string): Promise<OperationResult>;
163
- /** 通过 Cursor 打开 */
164
- openInEditor(targetPath: string): Promise<OperationResult>;
165
- /** 在新窗口中打开文件夹(使用系统文件管理器) */
166
- openInNewWindow(folderPath: string): Promise<OperationResult>;
167
- /** 请求窗口聚焦(用于右键打开菜单前激活窗口) */
168
- requestWindowFocus(): void;
169
- /** 检测媒体文件是否需要转码 */
170
- mediaNeedsTranscode(filePath: string): Promise<OperationResult<TranscodeInfo>>;
171
- /** 获取可播放的媒体 URL(自动转码) */
172
- mediaGetPlayableUrl(filePath: string): Promise<{
173
- success: boolean;
174
- url?: string;
175
- error?: string;
176
- }>;
177
- /** 获取媒体元数据 */
178
- mediaGetMetadata(filePath: string): Promise<OperationResult<MediaMetadata>>;
179
- /** 监听转码进度 */
180
- onMediaTranscodeProgress(callback: (data: {
181
- filePath: string;
182
- progress: MediaTranscodeProgress;
183
- }) => void): () => void;
184
- /** 清理指定文件的转码缓存 */
185
- mediaCleanupFile(filePath: string): Promise<OperationResult>;
186
- /** 打开媒体预览窗口(原生窗口) */
187
- openMediaPreviewWindow(filePath: string, mediaType: 'image' | 'video' | 'audio'): Promise<OperationResult>;
188
- /** 关闭媒体预览窗口 */
189
- closeMediaPreviewWindow(filePath: string): Promise<OperationResult>;
190
- }
191
9
  /**
192
10
  * Window 扩展类型
193
11
  */
@@ -265,7 +83,7 @@ declare global {
265
83
  mediaGetMetadata: (filePath: string) => Promise<OperationResult<MediaMetadata>>;
266
84
  onMediaTranscodeProgress: (callback: (data: {
267
85
  filePath: string;
268
- progress: MediaTranscodeProgress;
86
+ progress: TranscodeProgress;
269
87
  }) => void) => () => void;
270
88
  mediaCleanupFile: (filePath: string) => Promise<OperationResult>;
271
89
  openMediaPreviewWindow: (filePath: string, mediaType: 'image' | 'video' | 'audio') => Promise<OperationResult>;
@@ -274,15 +92,92 @@ declare global {
274
92
  }
275
93
  }
276
94
  /**
277
- * 创建 Electron 适配器
95
+ * 创建 File Explorer Client(渲染进程唯一入口)
278
96
  *
279
97
  * 在渲染进程中使用:
280
98
  * ```ts
281
- * import { createElectronAdapter } from '@aspect/file-explorer-bridge-electron/renderer';
282
- * const adapter = createElectronAdapter();
283
- * const files = await adapter.readDirectory('/path/to/dir');
99
+ * import { createFileExplorerClient } from '@huyooo/file-explorer-bridge-electron/renderer';
100
+ * const client = createFileExplorerClient();
101
+ * const files = await client.readDirectory('/path/to/dir');
284
102
  * ```
285
103
  */
286
- declare function createElectronAdapter(): FileExplorerAdapter;
104
+ declare function createFileExplorerClient(apiName?: string): {
105
+ readDirectory: (dirPath: string) => Promise<FileItem[]>;
106
+ readSystemPath: (pathId: string) => Promise<FileItem[]>;
107
+ getSystemPath: (pathId: string) => Promise<string | null>;
108
+ readFileContent: (filePath: string) => Promise<string>;
109
+ writeFileContent: (filePath: string, content: string) => Promise<OperationResult>;
110
+ createFolder: (parentDir: string, folderName: string) => Promise<OperationResult<{
111
+ finalPath: string;
112
+ }>>;
113
+ createFile: (parentDir: string, fileName: string, content?: string) => Promise<OperationResult<{
114
+ finalPath: string;
115
+ }>>;
116
+ deleteFiles: (paths: string[]) => Promise<OperationResult>;
117
+ renameFile: (oldPath: string, newPath: string) => Promise<OperationResult>;
118
+ copyFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
119
+ copiedPaths: string[];
120
+ }>>;
121
+ moveFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
122
+ movedPaths: string[];
123
+ }>>;
124
+ getFileInfo: (filePath: string) => Promise<OperationResult<FileInfo>>;
125
+ readImageAsBase64: (imagePath: string) => Promise<{
126
+ success: boolean;
127
+ base64?: string;
128
+ mimeType?: string;
129
+ error?: string;
130
+ }>;
131
+ openPath: (filePath: string) => Promise<OperationResult>;
132
+ getApplicationIcon: (appPath: string) => Promise<string | null>;
133
+ getThumbnailUrl: (filePath: string) => Promise<string | null>;
134
+ copyFilesToClipboard: (filePaths: string[]) => Promise<OperationResult>;
135
+ getClipboardFiles: () => Promise<OperationResult<{
136
+ files: string[];
137
+ }>>;
138
+ pasteFiles: (targetDir: string, sourcePaths: string[]) => Promise<OperationResult<{
139
+ pastedPaths: string[];
140
+ }>>;
141
+ searchFiles: (searchPath: string, pattern: string, maxDepth?: number) => Promise<OperationResult<{
142
+ items: FileItem[];
143
+ total: number;
144
+ }>>;
145
+ searchFilesStream: (searchPath: string, pattern: string, searchId: string) => Promise<OperationResult>;
146
+ onSearchResults: (callback: (data: {
147
+ searchId: string;
148
+ items: FileItem[];
149
+ done: boolean;
150
+ }) => void) => () => void;
151
+ compressFiles: (sources: string[], options: CompressOptions) => Promise<CompressResult>;
152
+ extractArchive: (archivePath: string, options: ExtractOptions) => Promise<CompressResult>;
153
+ isArchiveFile: (filePath: string) => Promise<boolean>;
154
+ onCompressProgress: (callback: (data: CompressProgress) => void) => () => void;
155
+ onExtractProgress: (callback: (data: CompressProgress) => void) => () => void;
156
+ watchDirectory: (dirPath: string, watchId: string) => Promise<OperationResult>;
157
+ unwatchDirectory: (watchId: string) => Promise<OperationResult>;
158
+ onWatchEvent: (callback: (data: {
159
+ watchId: string;
160
+ event: WatchEvent;
161
+ }) => void) => () => void;
162
+ showFileInfo: (filePath: string) => Promise<OperationResult>;
163
+ openInTerminal: (dirPath: string) => Promise<OperationResult>;
164
+ openInEditor: (targetPath: string) => Promise<OperationResult>;
165
+ openInNewWindow: (folderPath: string) => Promise<OperationResult>;
166
+ requestWindowFocus: () => void;
167
+ mediaNeedsTranscode: (filePath: string) => Promise<OperationResult<TranscodeInfo>>;
168
+ mediaGetPlayableUrl: (filePath: string) => Promise<{
169
+ success: boolean;
170
+ url?: string;
171
+ error?: string;
172
+ }>;
173
+ mediaGetMetadata: (filePath: string) => Promise<OperationResult<MediaMetadata>>;
174
+ onMediaTranscodeProgress: (callback: (data: {
175
+ filePath: string;
176
+ progress: TranscodeProgress;
177
+ }) => void) => () => void;
178
+ mediaCleanupFile: (filePath: string) => Promise<OperationResult>;
179
+ openMediaPreviewWindow: (filePath: string, mediaType: "image" | "video" | "audio") => Promise<OperationResult>;
180
+ closeMediaPreviewWindow: (filePath: string) => Promise<OperationResult>;
181
+ };
287
182
 
288
- export { type CompressOptions, type CompressProgress, type CompressResult, type ExtractOptions, type FileExplorerAdapter, type MediaMetadata, type MediaTranscodeProgress, type TranscodeInfo, type WatchEvent, type WatchEventType, createElectronAdapter };
183
+ export { createFileExplorerClient };
@@ -1,193 +1,11 @@
1
- import { FileItem, OperationResult, FileInfo, CompressFormat, CompressLevel } from '@huyooo/file-explorer-core';
2
- export { CompressFormat, CompressLevel, FileInfo, FileItem, OperationResult, SystemPathId } from '@huyooo/file-explorer-core';
1
+ import { FileItem, OperationResult, FileInfo, CompressOptions, CompressResult, ExtractOptions, CompressProgress, WatchEvent, TranscodeInfo, MediaMetadata, TranscodeProgress } from '@huyooo/file-explorer-core';
3
2
 
4
3
  /**
5
4
  * File Explorer Electron Bridge - Renderer Process
6
5
  *
7
- * 提供渲染进程使用的适配器
6
+ * 提供渲染进程使用的 client(仅保留 runtime 入口)
8
7
  */
9
8
 
10
- /** 压缩选项 */
11
- interface CompressOptions {
12
- format: CompressFormat;
13
- level?: CompressLevel;
14
- outputName: string;
15
- outputDir: string;
16
- deleteSource?: boolean;
17
- }
18
- /** 解压选项 */
19
- interface ExtractOptions {
20
- targetDir: string;
21
- deleteArchive?: boolean;
22
- }
23
- /** 压缩进度 */
24
- interface CompressProgress {
25
- currentFile: string;
26
- processedCount: number;
27
- totalCount: number;
28
- percent: number;
29
- }
30
- /** 压缩结果 */
31
- interface CompressResult {
32
- success: boolean;
33
- outputPath?: string;
34
- error?: string;
35
- }
36
- /** 文件变化事件类型 */
37
- type WatchEventType = 'add' | 'change' | 'remove' | 'rename';
38
- /** 文件变化事件 */
39
- interface WatchEvent {
40
- type: WatchEventType;
41
- path: string;
42
- filename: string;
43
- }
44
- /** 媒体转码信息 */
45
- interface TranscodeInfo {
46
- type: 'video' | 'audio';
47
- needsTranscode: boolean;
48
- method: 'direct' | 'remux' | 'transcode';
49
- estimatedTime?: number;
50
- targetFormat?: string;
51
- }
52
- /** 媒体转码进度 */
53
- interface MediaTranscodeProgress {
54
- percent: number;
55
- time?: number;
56
- duration?: number;
57
- speed?: string;
58
- }
59
- /** 媒体元数据 */
60
- interface MediaMetadata {
61
- filePath: string;
62
- type: 'video' | 'audio';
63
- duration: number;
64
- title?: string;
65
- artist?: string;
66
- album?: string;
67
- }
68
- /**
69
- * 文件操作适配器接口
70
- */
71
- interface FileExplorerAdapter {
72
- /** 读取目录 */
73
- readDirectory(dirPath: string): Promise<FileItem[]>;
74
- /** 读取系统路径目录 */
75
- readSystemPath(pathId: string): Promise<FileItem[]>;
76
- /** 获取系统路径 */
77
- getSystemPath(pathId: string): Promise<string | null>;
78
- /** 读取文件内容 */
79
- readFileContent(filePath: string): Promise<string>;
80
- /** 写入文件内容 */
81
- writeFileContent(filePath: string, content: string): Promise<OperationResult>;
82
- /** 创建文件夹 */
83
- createFolder(parentDir: string, folderName: string): Promise<OperationResult<{
84
- finalPath: string;
85
- }>>;
86
- /** 创建文件 */
87
- createFile(parentDir: string, fileName: string, content?: string): Promise<OperationResult<{
88
- finalPath: string;
89
- }>>;
90
- /** 删除文件 */
91
- deleteFiles(paths: string[]): Promise<OperationResult>;
92
- /** 重命名文件 */
93
- renameFile(oldPath: string, newPath: string): Promise<OperationResult>;
94
- /** 复制文件 */
95
- copyFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
96
- copiedPaths: string[];
97
- }>>;
98
- /** 移动文件 */
99
- moveFiles(sourcePaths: string[], targetDir: string): Promise<OperationResult<{
100
- movedPaths: string[];
101
- }>>;
102
- /** 获取文件信息 */
103
- getFileInfo(filePath: string): Promise<OperationResult<FileInfo>>;
104
- /** 读取图片为 Base64 */
105
- readImageAsBase64(imagePath: string): Promise<{
106
- success: boolean;
107
- base64?: string;
108
- mimeType?: string;
109
- error?: string;
110
- }>;
111
- /** 使用系统默认应用打开 */
112
- openPath(filePath: string): Promise<OperationResult>;
113
- /** 获取应用程序图标 */
114
- getApplicationIcon(appPath: string): Promise<string | null>;
115
- /** 获取缩略图 URL */
116
- getThumbnailUrl(filePath: string): Promise<string | null>;
117
- /** 复制文件到剪贴板 */
118
- copyFilesToClipboard(filePaths: string[]): Promise<OperationResult>;
119
- /** 从剪贴板获取文件 */
120
- getClipboardFiles(): Promise<OperationResult<{
121
- files: string[];
122
- }>>;
123
- /** 粘贴文件 */
124
- pasteFiles(targetDir: string, sourcePaths: string[]): Promise<OperationResult<{
125
- pastedPaths: string[];
126
- }>>;
127
- /** 搜索文件 */
128
- searchFiles(searchPath: string, pattern: string, maxDepth?: number): Promise<OperationResult<{
129
- items: FileItem[];
130
- total: number;
131
- }>>;
132
- /** 流式搜索文件 */
133
- searchFilesStream(searchPath: string, pattern: string, searchId: string): Promise<OperationResult>;
134
- /** 监听搜索结果 */
135
- onSearchResults(callback: (data: {
136
- searchId: string;
137
- items: FileItem[];
138
- done: boolean;
139
- }) => void): () => void;
140
- /** 压缩文件 */
141
- compressFiles(sources: string[], options: CompressOptions): Promise<CompressResult>;
142
- /** 解压文件 */
143
- extractArchive(archivePath: string, options: ExtractOptions): Promise<CompressResult>;
144
- /** 判断是否为压缩文件 */
145
- isArchiveFile(filePath: string): Promise<boolean>;
146
- /** 监听压缩进度 */
147
- onCompressProgress(callback: (data: CompressProgress) => void): () => void;
148
- /** 监听解压进度 */
149
- onExtractProgress(callback: (data: CompressProgress) => void): () => void;
150
- /** 监听目录变化 */
151
- watchDirectory(dirPath: string, watchId: string): Promise<OperationResult>;
152
- /** 停止监听目录 */
153
- unwatchDirectory(watchId: string): Promise<OperationResult>;
154
- /** 监听文件变化事件 */
155
- onWatchEvent(callback: (data: {
156
- watchId: string;
157
- event: WatchEvent;
158
- }) => void): () => void;
159
- /** 显示文件/文件夹的系统属性窗口 */
160
- showFileInfo(filePath: string): Promise<OperationResult>;
161
- /** 在终端中打开目录 */
162
- openInTerminal(dirPath: string): Promise<OperationResult>;
163
- /** 通过 Cursor 打开 */
164
- openInEditor(targetPath: string): Promise<OperationResult>;
165
- /** 在新窗口中打开文件夹(使用系统文件管理器) */
166
- openInNewWindow(folderPath: string): Promise<OperationResult>;
167
- /** 请求窗口聚焦(用于右键打开菜单前激活窗口) */
168
- requestWindowFocus(): void;
169
- /** 检测媒体文件是否需要转码 */
170
- mediaNeedsTranscode(filePath: string): Promise<OperationResult<TranscodeInfo>>;
171
- /** 获取可播放的媒体 URL(自动转码) */
172
- mediaGetPlayableUrl(filePath: string): Promise<{
173
- success: boolean;
174
- url?: string;
175
- error?: string;
176
- }>;
177
- /** 获取媒体元数据 */
178
- mediaGetMetadata(filePath: string): Promise<OperationResult<MediaMetadata>>;
179
- /** 监听转码进度 */
180
- onMediaTranscodeProgress(callback: (data: {
181
- filePath: string;
182
- progress: MediaTranscodeProgress;
183
- }) => void): () => void;
184
- /** 清理指定文件的转码缓存 */
185
- mediaCleanupFile(filePath: string): Promise<OperationResult>;
186
- /** 打开媒体预览窗口(原生窗口) */
187
- openMediaPreviewWindow(filePath: string, mediaType: 'image' | 'video' | 'audio'): Promise<OperationResult>;
188
- /** 关闭媒体预览窗口 */
189
- closeMediaPreviewWindow(filePath: string): Promise<OperationResult>;
190
- }
191
9
  /**
192
10
  * Window 扩展类型
193
11
  */
@@ -265,7 +83,7 @@ declare global {
265
83
  mediaGetMetadata: (filePath: string) => Promise<OperationResult<MediaMetadata>>;
266
84
  onMediaTranscodeProgress: (callback: (data: {
267
85
  filePath: string;
268
- progress: MediaTranscodeProgress;
86
+ progress: TranscodeProgress;
269
87
  }) => void) => () => void;
270
88
  mediaCleanupFile: (filePath: string) => Promise<OperationResult>;
271
89
  openMediaPreviewWindow: (filePath: string, mediaType: 'image' | 'video' | 'audio') => Promise<OperationResult>;
@@ -274,15 +92,92 @@ declare global {
274
92
  }
275
93
  }
276
94
  /**
277
- * 创建 Electron 适配器
95
+ * 创建 File Explorer Client(渲染进程唯一入口)
278
96
  *
279
97
  * 在渲染进程中使用:
280
98
  * ```ts
281
- * import { createElectronAdapter } from '@aspect/file-explorer-bridge-electron/renderer';
282
- * const adapter = createElectronAdapter();
283
- * const files = await adapter.readDirectory('/path/to/dir');
99
+ * import { createFileExplorerClient } from '@huyooo/file-explorer-bridge-electron/renderer';
100
+ * const client = createFileExplorerClient();
101
+ * const files = await client.readDirectory('/path/to/dir');
284
102
  * ```
285
103
  */
286
- declare function createElectronAdapter(): FileExplorerAdapter;
104
+ declare function createFileExplorerClient(apiName?: string): {
105
+ readDirectory: (dirPath: string) => Promise<FileItem[]>;
106
+ readSystemPath: (pathId: string) => Promise<FileItem[]>;
107
+ getSystemPath: (pathId: string) => Promise<string | null>;
108
+ readFileContent: (filePath: string) => Promise<string>;
109
+ writeFileContent: (filePath: string, content: string) => Promise<OperationResult>;
110
+ createFolder: (parentDir: string, folderName: string) => Promise<OperationResult<{
111
+ finalPath: string;
112
+ }>>;
113
+ createFile: (parentDir: string, fileName: string, content?: string) => Promise<OperationResult<{
114
+ finalPath: string;
115
+ }>>;
116
+ deleteFiles: (paths: string[]) => Promise<OperationResult>;
117
+ renameFile: (oldPath: string, newPath: string) => Promise<OperationResult>;
118
+ copyFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
119
+ copiedPaths: string[];
120
+ }>>;
121
+ moveFiles: (sourcePaths: string[], targetDir: string) => Promise<OperationResult<{
122
+ movedPaths: string[];
123
+ }>>;
124
+ getFileInfo: (filePath: string) => Promise<OperationResult<FileInfo>>;
125
+ readImageAsBase64: (imagePath: string) => Promise<{
126
+ success: boolean;
127
+ base64?: string;
128
+ mimeType?: string;
129
+ error?: string;
130
+ }>;
131
+ openPath: (filePath: string) => Promise<OperationResult>;
132
+ getApplicationIcon: (appPath: string) => Promise<string | null>;
133
+ getThumbnailUrl: (filePath: string) => Promise<string | null>;
134
+ copyFilesToClipboard: (filePaths: string[]) => Promise<OperationResult>;
135
+ getClipboardFiles: () => Promise<OperationResult<{
136
+ files: string[];
137
+ }>>;
138
+ pasteFiles: (targetDir: string, sourcePaths: string[]) => Promise<OperationResult<{
139
+ pastedPaths: string[];
140
+ }>>;
141
+ searchFiles: (searchPath: string, pattern: string, maxDepth?: number) => Promise<OperationResult<{
142
+ items: FileItem[];
143
+ total: number;
144
+ }>>;
145
+ searchFilesStream: (searchPath: string, pattern: string, searchId: string) => Promise<OperationResult>;
146
+ onSearchResults: (callback: (data: {
147
+ searchId: string;
148
+ items: FileItem[];
149
+ done: boolean;
150
+ }) => void) => () => void;
151
+ compressFiles: (sources: string[], options: CompressOptions) => Promise<CompressResult>;
152
+ extractArchive: (archivePath: string, options: ExtractOptions) => Promise<CompressResult>;
153
+ isArchiveFile: (filePath: string) => Promise<boolean>;
154
+ onCompressProgress: (callback: (data: CompressProgress) => void) => () => void;
155
+ onExtractProgress: (callback: (data: CompressProgress) => void) => () => void;
156
+ watchDirectory: (dirPath: string, watchId: string) => Promise<OperationResult>;
157
+ unwatchDirectory: (watchId: string) => Promise<OperationResult>;
158
+ onWatchEvent: (callback: (data: {
159
+ watchId: string;
160
+ event: WatchEvent;
161
+ }) => void) => () => void;
162
+ showFileInfo: (filePath: string) => Promise<OperationResult>;
163
+ openInTerminal: (dirPath: string) => Promise<OperationResult>;
164
+ openInEditor: (targetPath: string) => Promise<OperationResult>;
165
+ openInNewWindow: (folderPath: string) => Promise<OperationResult>;
166
+ requestWindowFocus: () => void;
167
+ mediaNeedsTranscode: (filePath: string) => Promise<OperationResult<TranscodeInfo>>;
168
+ mediaGetPlayableUrl: (filePath: string) => Promise<{
169
+ success: boolean;
170
+ url?: string;
171
+ error?: string;
172
+ }>;
173
+ mediaGetMetadata: (filePath: string) => Promise<OperationResult<MediaMetadata>>;
174
+ onMediaTranscodeProgress: (callback: (data: {
175
+ filePath: string;
176
+ progress: TranscodeProgress;
177
+ }) => void) => () => void;
178
+ mediaCleanupFile: (filePath: string) => Promise<OperationResult>;
179
+ openMediaPreviewWindow: (filePath: string, mediaType: "image" | "video" | "audio") => Promise<OperationResult>;
180
+ closeMediaPreviewWindow: (filePath: string) => Promise<OperationResult>;
181
+ };
287
182
 
288
- export { type CompressOptions, type CompressProgress, type CompressResult, type ExtractOptions, type FileExplorerAdapter, type MediaMetadata, type MediaTranscodeProgress, type TranscodeInfo, type WatchEvent, type WatchEventType, createElectronAdapter };
183
+ export { createFileExplorerClient };
@@ -1,58 +1,14 @@
1
1
  // src/renderer/index.ts
2
- function createElectronAdapter() {
3
- const api = window.fileExplorerAPI;
2
+ function createFileExplorerClient(apiName = "fileExplorerAPI") {
3
+ const api = apiName === "fileExplorerAPI" ? window.fileExplorerAPI : window[apiName];
4
4
  if (!api) {
5
5
  throw new Error(
6
- "window.fileExplorerAPI not found. Make sure to call exposeFileExplorerAPI() in your preload script."
6
+ `window.${apiName} not found. Make sure to call exposeFileExplorerAPI({ apiName }) in your preload script.`
7
7
  );
8
8
  }
9
- return {
10
- readDirectory: (dirPath) => api.readDirectory(dirPath),
11
- readSystemPath: (pathId) => api.readSystemPath(pathId),
12
- getSystemPath: (pathId) => api.getSystemPath(pathId),
13
- readFileContent: (filePath) => api.readFileContent(filePath),
14
- writeFileContent: (filePath, content) => api.writeFileContent(filePath, content),
15
- createFolder: (parentDir, folderName) => api.createFolder(parentDir, folderName),
16
- createFile: (parentDir, fileName, content) => api.createFile(parentDir, fileName, content),
17
- deleteFiles: (paths) => api.deleteFiles(paths),
18
- renameFile: (oldPath, newPath) => api.renameFile(oldPath, newPath),
19
- copyFiles: (sourcePaths, targetDir) => api.copyFiles(sourcePaths, targetDir),
20
- moveFiles: (sourcePaths, targetDir) => api.moveFiles(sourcePaths, targetDir),
21
- getFileInfo: (filePath) => api.getFileInfo(filePath),
22
- readImageAsBase64: (imagePath) => api.readImageAsBase64(imagePath),
23
- openPath: (filePath) => api.openPath(filePath),
24
- getApplicationIcon: (appPath) => api.getApplicationIcon(appPath),
25
- getThumbnailUrl: (filePath) => api.getThumbnailUrl(filePath),
26
- copyFilesToClipboard: (filePaths) => api.copyFilesToClipboard(filePaths),
27
- getClipboardFiles: () => api.getClipboardFiles(),
28
- pasteFiles: (targetDir, sourcePaths) => api.pasteFiles(targetDir, sourcePaths),
29
- searchFiles: (searchPath, pattern, maxDepth) => api.searchFiles(searchPath, pattern, maxDepth),
30
- searchFilesStream: (searchPath, pattern, searchId) => api.searchFilesStream(searchPath, pattern, searchId),
31
- onSearchResults: (callback) => api.onSearchResults(callback),
32
- compressFiles: (sources, options) => api.compressFiles(sources, options),
33
- extractArchive: (archivePath, options) => api.extractArchive(archivePath, options),
34
- isArchiveFile: (filePath) => api.isArchiveFile(filePath),
35
- onCompressProgress: (callback) => api.onCompressProgress(callback),
36
- onExtractProgress: (callback) => api.onExtractProgress(callback),
37
- watchDirectory: (dirPath, watchId) => api.watchDirectory(dirPath, watchId),
38
- unwatchDirectory: (watchId) => api.unwatchDirectory(watchId),
39
- onWatchEvent: (callback) => api.onWatchEvent(callback),
40
- showFileInfo: (filePath) => api.showFileInfo(filePath),
41
- openInTerminal: (dirPath) => api.openInTerminal(dirPath),
42
- openInEditor: (targetPath) => api.openInEditor(targetPath),
43
- openInNewWindow: (folderPath) => api.openInNewWindow(folderPath),
44
- requestWindowFocus: () => api.requestWindowFocus(),
45
- // 媒体服务
46
- mediaNeedsTranscode: (filePath) => api.mediaNeedsTranscode(filePath),
47
- mediaGetPlayableUrl: (filePath) => api.mediaGetPlayableUrl(filePath),
48
- mediaGetMetadata: (filePath) => api.mediaGetMetadata(filePath),
49
- onMediaTranscodeProgress: (callback) => api.onMediaTranscodeProgress(callback),
50
- mediaCleanupFile: (filePath) => api.mediaCleanupFile(filePath),
51
- // 媒体预览窗口
52
- openMediaPreviewWindow: (filePath, mediaType) => api.openMediaPreviewWindow(filePath, mediaType),
53
- closeMediaPreviewWindow: (filePath) => api.closeMediaPreviewWindow(filePath)
54
- };
9
+ const typedApi = api;
10
+ return typedApi;
55
11
  }
56
12
  export {
57
- createElectronAdapter
13
+ createFileExplorerClient
58
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huyooo/file-explorer-bridge-electron",
3
- "version": "0.4.3",
3
+ "version": "0.4.6",
4
4
  "description": "File Explorer Electron Bridge - IPC integration for Electron apps",
5
5
  "type": "module",
6
6
  "main": "./dist/main/index.cjs",
@@ -36,8 +36,8 @@
36
36
  "clean": "rm -rf dist"
37
37
  },
38
38
  "dependencies": {
39
- "@huyooo/file-explorer-core": "^0.4.3",
40
- "@huyooo/file-explorer-preview": "^0.1.0"
39
+ "@huyooo/file-explorer-core": "^0.4.6",
40
+ "@huyooo/file-explorer-preview": "^0.4.6"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "electron": ">=20.0.0"