@huyooo/file-explorer-bridge-electron 0.2.1 → 0.4.2
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 +284 -5
- package/dist/main/index.d.cts +11 -7
- package/dist/main/index.d.ts +11 -7
- package/dist/main/index.js +295 -7
- package/dist/preload/index.cjs +47 -1
- package/dist/preload/index.d.cts +133 -0
- package/dist/preload/index.d.ts +133 -0
- package/dist/preload/index.js +47 -1
- package/dist/preload/preview.cjs +54 -0
- package/dist/preload/preview.d.cts +28 -0
- package/dist/preload/preview.d.ts +28 -0
- package/dist/preload/preview.js +29 -0
- package/dist/renderer/index.cjs +23 -1
- package/dist/renderer/index.d.cts +141 -3
- package/dist/renderer/index.d.ts +141 -3
- package/dist/renderer/index.js +23 -1
- package/package.json +3 -2
package/dist/main/index.cjs
CHANGED
|
@@ -40,8 +40,11 @@ var import_electron = require("electron");
|
|
|
40
40
|
var import_node_path = __toESM(require("path"), 1);
|
|
41
41
|
var import_file_explorer_core = require("@huyooo/file-explorer-core");
|
|
42
42
|
var import_node_fs = require("fs");
|
|
43
|
+
var import_path = require("@huyooo/file-explorer-preview/path");
|
|
43
44
|
var CHANNEL_PREFIX = "file-explorer";
|
|
45
|
+
var PREVIEW_CHANNEL_PREFIX = "file-explorer-preview";
|
|
44
46
|
var channel = (name) => `${CHANNEL_PREFIX}:${name}`;
|
|
47
|
+
var previewChannel = (name) => `${PREVIEW_CHANNEL_PREFIX}:${name}`;
|
|
45
48
|
var clipboardAdapter = null;
|
|
46
49
|
function setClipboardAdapter(adapter) {
|
|
47
50
|
clipboardAdapter = adapter;
|
|
@@ -56,11 +59,11 @@ function createElectronAdapter() {
|
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
62
|
+
var electronUrlEncoder = import_file_explorer_core.encodeFileUrl;
|
|
63
|
+
var explorerOptions = {};
|
|
64
|
+
var mediaPreviewWindows = /* @__PURE__ */ new Map();
|
|
65
|
+
function registerFileExplorerHandlers(options = {}) {
|
|
66
|
+
explorerOptions = options;
|
|
64
67
|
const adapter = createElectronAdapter();
|
|
65
68
|
import_electron.ipcMain.handle(channel("readDirectory"), async (_event, dirPath) => {
|
|
66
69
|
const thumbnailService = (0, import_file_explorer_core.getThumbnailService)();
|
|
@@ -224,6 +227,282 @@ function registerFileExplorerHandlers() {
|
|
|
224
227
|
}, 100);
|
|
225
228
|
return { success: true };
|
|
226
229
|
});
|
|
230
|
+
import_electron.ipcMain.handle(channel("compressFiles"), async (event, sources, options2) => {
|
|
231
|
+
try {
|
|
232
|
+
const result = await (0, import_file_explorer_core.compressFiles)(sources, options2, (progress) => {
|
|
233
|
+
event.sender.send(channel("compressProgress"), progress);
|
|
234
|
+
});
|
|
235
|
+
return result;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return { success: false, error: String(error) };
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
import_electron.ipcMain.handle(channel("extractArchive"), async (event, archivePath, options2) => {
|
|
241
|
+
try {
|
|
242
|
+
const result = await (0, import_file_explorer_core.extractArchive)(archivePath, options2, (progress) => {
|
|
243
|
+
event.sender.send(channel("extractProgress"), progress);
|
|
244
|
+
});
|
|
245
|
+
return result;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
return { success: false, error: String(error) };
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
import_electron.ipcMain.handle(channel("isArchiveFile"), async (_event, filePath) => {
|
|
251
|
+
return (0, import_file_explorer_core.isArchiveFile)(filePath);
|
|
252
|
+
});
|
|
253
|
+
const watchUnsubscribers = /* @__PURE__ */ new Map();
|
|
254
|
+
import_electron.ipcMain.handle(channel("watchDirectory"), async (event, dirPath, watchId) => {
|
|
255
|
+
try {
|
|
256
|
+
const existingUnsubscribe = watchUnsubscribers.get(watchId);
|
|
257
|
+
if (existingUnsubscribe) {
|
|
258
|
+
existingUnsubscribe();
|
|
259
|
+
watchUnsubscribers.delete(watchId);
|
|
260
|
+
}
|
|
261
|
+
const watchManager = (0, import_file_explorer_core.getWatchManager)();
|
|
262
|
+
const unsubscribe = watchManager.watch(dirPath, (watchEvent) => {
|
|
263
|
+
event.sender.send(channel("watchEvent"), {
|
|
264
|
+
watchId,
|
|
265
|
+
event: watchEvent
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
watchUnsubscribers.set(watchId, unsubscribe);
|
|
269
|
+
return { success: true };
|
|
270
|
+
} catch (error) {
|
|
271
|
+
return { success: false, error: String(error) };
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
import_electron.ipcMain.handle(channel("unwatchDirectory"), async (_event, watchId) => {
|
|
275
|
+
const unsubscribe = watchUnsubscribers.get(watchId);
|
|
276
|
+
if (unsubscribe) {
|
|
277
|
+
unsubscribe();
|
|
278
|
+
watchUnsubscribers.delete(watchId);
|
|
279
|
+
}
|
|
280
|
+
return { success: true };
|
|
281
|
+
});
|
|
282
|
+
import_electron.ipcMain.handle(channel("showFileInfo"), async (_event, filePath) => {
|
|
283
|
+
return await (0, import_file_explorer_core.showFileInfo)(filePath);
|
|
284
|
+
});
|
|
285
|
+
import_electron.ipcMain.handle(channel("openInTerminal"), async (_event, dirPath) => {
|
|
286
|
+
return await (0, import_file_explorer_core.openInTerminal)(dirPath);
|
|
287
|
+
});
|
|
288
|
+
import_electron.ipcMain.handle(channel("openInEditor"), async (_event, targetPath) => {
|
|
289
|
+
return await (0, import_file_explorer_core.openInEditor)(targetPath);
|
|
290
|
+
});
|
|
291
|
+
import_electron.ipcMain.handle(channel("openInNewWindow"), async (_event, folderPath) => {
|
|
292
|
+
try {
|
|
293
|
+
if (explorerOptions.onOpenInNewWindow) {
|
|
294
|
+
explorerOptions.onOpenInNewWindow(folderPath);
|
|
295
|
+
} else {
|
|
296
|
+
await import_electron.shell.openPath(folderPath);
|
|
297
|
+
}
|
|
298
|
+
return { success: true };
|
|
299
|
+
} catch (error) {
|
|
300
|
+
return { success: false, error: String(error) };
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
import_electron.ipcMain.on(channel("requestWindowFocus"), (event) => {
|
|
304
|
+
const win = import_electron.BrowserWindow.fromWebContents(event.sender);
|
|
305
|
+
if (win && !win.isFocused()) {
|
|
306
|
+
win.focus();
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
import_electron.ipcMain.handle(channel("mediaNeedsTranscode"), async (_event, filePath) => {
|
|
310
|
+
const mediaService = (0, import_file_explorer_core.getMediaService)();
|
|
311
|
+
if (!mediaService) {
|
|
312
|
+
return { success: false, error: "\u5A92\u4F53\u670D\u52A1\u672A\u521D\u59CB\u5316" };
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
const info = await mediaService.needsTranscode(filePath);
|
|
316
|
+
return { success: true, data: info };
|
|
317
|
+
} catch (error) {
|
|
318
|
+
return { success: false, error: String(error) };
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
import_electron.ipcMain.handle(channel("mediaGetPlayableUrl"), async (event, filePath) => {
|
|
322
|
+
const mediaService = (0, import_file_explorer_core.getMediaService)();
|
|
323
|
+
if (!mediaService) {
|
|
324
|
+
return { success: false, error: "\u5A92\u4F53\u670D\u52A1\u672A\u521D\u59CB\u5316" };
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
const url = await mediaService.getPlayableUrl(filePath, (progress) => {
|
|
328
|
+
event.sender.send(channel("mediaTranscodeProgress"), {
|
|
329
|
+
filePath,
|
|
330
|
+
progress
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
return { success: true, url };
|
|
334
|
+
} catch (error) {
|
|
335
|
+
return { success: false, error: String(error) };
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
import_electron.ipcMain.handle(channel("mediaGetMetadata"), async (_event, filePath) => {
|
|
339
|
+
const mediaService = (0, import_file_explorer_core.getMediaService)();
|
|
340
|
+
if (!mediaService) {
|
|
341
|
+
return { success: false, error: "\u5A92\u4F53\u670D\u52A1\u672A\u521D\u59CB\u5316" };
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
const metadata = await mediaService.getMetadata(filePath);
|
|
345
|
+
return { success: true, data: metadata };
|
|
346
|
+
} catch (error) {
|
|
347
|
+
return { success: false, error: String(error) };
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
import_electron.ipcMain.handle(channel("mediaCleanupFile"), async (_event, filePath) => {
|
|
351
|
+
const mediaService = (0, import_file_explorer_core.getMediaService)();
|
|
352
|
+
if (!mediaService) {
|
|
353
|
+
return { success: false, error: "\u5A92\u4F53\u670D\u52A1\u672A\u521D\u59CB\u5316" };
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
await mediaService.cleanupFile(filePath);
|
|
357
|
+
return { success: true };
|
|
358
|
+
} catch (error) {
|
|
359
|
+
return { success: false, error: String(error) };
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
import_electron.ipcMain.handle(channel("openMediaPreviewWindow"), async (event, filePath, mediaType) => {
|
|
363
|
+
try {
|
|
364
|
+
const fileName = import_node_path.default.basename(filePath);
|
|
365
|
+
const mediaService = (0, import_file_explorer_core.getMediaService)();
|
|
366
|
+
let fileUrl;
|
|
367
|
+
if (mediaType === "image") {
|
|
368
|
+
fileUrl = electronUrlEncoder(filePath);
|
|
369
|
+
} else if (mediaService) {
|
|
370
|
+
const playableUrl = await mediaService.getPlayableUrl(filePath, (progress) => {
|
|
371
|
+
event.sender.send(channel("mediaTranscodeProgress"), {
|
|
372
|
+
filePath,
|
|
373
|
+
progress
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
fileUrl = playableUrl || electronUrlEncoder(filePath);
|
|
377
|
+
} else {
|
|
378
|
+
fileUrl = electronUrlEncoder(filePath);
|
|
379
|
+
}
|
|
380
|
+
const existingWindow = mediaPreviewWindows.get(filePath);
|
|
381
|
+
if (existingWindow && !existingWindow.isDestroyed()) {
|
|
382
|
+
existingWindow.focus();
|
|
383
|
+
return { success: true };
|
|
384
|
+
}
|
|
385
|
+
const isMac = process.platform === "darwin";
|
|
386
|
+
const isWin = process.platform === "win32";
|
|
387
|
+
const titleBarHeight = isMac ? 38 : 32;
|
|
388
|
+
let contentWidth = 720;
|
|
389
|
+
let contentHeight = 405;
|
|
390
|
+
let minContentWidth = 720;
|
|
391
|
+
let minContentHeight = 405;
|
|
392
|
+
if (mediaType === "audio") {
|
|
393
|
+
contentWidth = 720;
|
|
394
|
+
contentHeight = 405;
|
|
395
|
+
minContentWidth = 720;
|
|
396
|
+
minContentHeight = 405;
|
|
397
|
+
} else if (mediaType === "image") {
|
|
398
|
+
contentWidth = 1e3;
|
|
399
|
+
contentHeight = 700;
|
|
400
|
+
minContentWidth = 600;
|
|
401
|
+
minContentHeight = 400;
|
|
402
|
+
}
|
|
403
|
+
const width = contentWidth;
|
|
404
|
+
const height = contentHeight + titleBarHeight;
|
|
405
|
+
const minWidth = minContentWidth;
|
|
406
|
+
const minHeight = minContentHeight + titleBarHeight;
|
|
407
|
+
const previewPreloadPath = import_node_path.default.join(__dirname, "../preload/preview.cjs");
|
|
408
|
+
const previewWindow = new import_electron.BrowserWindow({
|
|
409
|
+
width,
|
|
410
|
+
height,
|
|
411
|
+
minWidth,
|
|
412
|
+
minHeight,
|
|
413
|
+
title: fileName,
|
|
414
|
+
modal: false,
|
|
415
|
+
show: false,
|
|
416
|
+
backgroundColor: "#1a1a1a",
|
|
417
|
+
// 窗口功能
|
|
418
|
+
resizable: true,
|
|
419
|
+
maximizable: true,
|
|
420
|
+
fullscreenable: true,
|
|
421
|
+
// Windows 和 macOS 都使用无边框样式,自定义标题栏
|
|
422
|
+
frame: isMac ? true : false,
|
|
423
|
+
// macOS 用 hiddenInset,Windows 完全无边框
|
|
424
|
+
titleBarStyle: isMac ? "hiddenInset" : void 0,
|
|
425
|
+
trafficLightPosition: isMac ? { x: 12, y: 12 } : void 0,
|
|
426
|
+
webPreferences: {
|
|
427
|
+
preload: previewPreloadPath,
|
|
428
|
+
nodeIntegration: false,
|
|
429
|
+
contextIsolation: true,
|
|
430
|
+
// 注意:以下设置会触发安全警告,但这是必要的
|
|
431
|
+
// - sandbox: false - 需要加载本地媒体文件(file:// 协议)
|
|
432
|
+
// - webSecurity: false - 允许加载本地文件和 Iconify CDN
|
|
433
|
+
// 这些警告在开发环境中显示,打包后不会显示
|
|
434
|
+
sandbox: false,
|
|
435
|
+
webSecurity: false
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
const previewHtmlPath = (0, import_path.getPreviewHtmlPath)();
|
|
439
|
+
const searchParams = new URLSearchParams({
|
|
440
|
+
type: mediaType,
|
|
441
|
+
url: encodeURIComponent(fileUrl),
|
|
442
|
+
name: encodeURIComponent(fileName),
|
|
443
|
+
platform: isMac ? "darwin" : isWin ? "win32" : "linux"
|
|
444
|
+
});
|
|
445
|
+
previewWindow.loadFile(previewHtmlPath, { search: searchParams.toString() });
|
|
446
|
+
previewWindow.once("ready-to-show", () => {
|
|
447
|
+
previewWindow.show();
|
|
448
|
+
});
|
|
449
|
+
previewWindow.on("maximize", () => {
|
|
450
|
+
previewWindow.webContents.send(previewChannel("maximizeChange"), true);
|
|
451
|
+
});
|
|
452
|
+
previewWindow.on("unmaximize", () => {
|
|
453
|
+
previewWindow.webContents.send(previewChannel("maximizeChange"), false);
|
|
454
|
+
});
|
|
455
|
+
previewWindow.on("closed", () => {
|
|
456
|
+
mediaPreviewWindows.delete(filePath);
|
|
457
|
+
});
|
|
458
|
+
mediaPreviewWindows.set(filePath, previewWindow);
|
|
459
|
+
return { success: true };
|
|
460
|
+
} catch (error) {
|
|
461
|
+
return { success: false, error: String(error) };
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
import_electron.ipcMain.handle(channel("closeMediaPreviewWindow"), async (_event, filePath) => {
|
|
465
|
+
const window = mediaPreviewWindows.get(filePath);
|
|
466
|
+
if (window && !window.isDestroyed()) {
|
|
467
|
+
window.close();
|
|
468
|
+
mediaPreviewWindows.delete(filePath);
|
|
469
|
+
}
|
|
470
|
+
return { success: true };
|
|
471
|
+
});
|
|
472
|
+
import_electron.ipcMain.on(previewChannel("minimize"), (event) => {
|
|
473
|
+
const win = import_electron.BrowserWindow.fromWebContents(event.sender);
|
|
474
|
+
if (win) {
|
|
475
|
+
win.minimize();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
import_electron.ipcMain.on(previewChannel("toggleMaximize"), (event) => {
|
|
479
|
+
const win = import_electron.BrowserWindow.fromWebContents(event.sender);
|
|
480
|
+
if (win) {
|
|
481
|
+
if (win.isMaximized()) {
|
|
482
|
+
win.unmaximize();
|
|
483
|
+
} else {
|
|
484
|
+
win.maximize();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
import_electron.ipcMain.on(previewChannel("close"), (event) => {
|
|
489
|
+
const win = import_electron.BrowserWindow.fromWebContents(event.sender);
|
|
490
|
+
if (win) {
|
|
491
|
+
win.close();
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
import_electron.ipcMain.on(previewChannel("hide"), (event) => {
|
|
495
|
+
const win = import_electron.BrowserWindow.fromWebContents(event.sender);
|
|
496
|
+
if (win) {
|
|
497
|
+
win.hide();
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
import_electron.ipcMain.on(previewChannel("show"), (event) => {
|
|
501
|
+
const win = import_electron.BrowserWindow.fromWebContents(event.sender);
|
|
502
|
+
if (win) {
|
|
503
|
+
win.show();
|
|
504
|
+
}
|
|
505
|
+
});
|
|
227
506
|
console.log("\u2705 File Explorer IPC handlers registered");
|
|
228
507
|
}
|
|
229
508
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/main/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlatformAdapter, ClipboardAdapter } from '@huyooo/file-explorer-core';
|
|
1
|
+
import { PlatformAdapter, encodeFileUrl, ClipboardAdapter } from '@huyooo/file-explorer-core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* File Explorer Electron Bridge - Main Process
|
|
@@ -15,13 +15,17 @@ declare function setClipboardAdapter(adapter: ClipboardAdapter): void;
|
|
|
15
15
|
* 创建 Electron 平台适配器
|
|
16
16
|
*/
|
|
17
17
|
declare function createElectronAdapter(): PlatformAdapter;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
|
|
18
|
+
/** URL 编码器(使用 core 中的协议工具) */
|
|
19
|
+
declare const electronUrlEncoder: typeof encodeFileUrl;
|
|
20
|
+
/** 文件管理器配置选项 */
|
|
21
|
+
interface FileExplorerOptions {
|
|
22
|
+
/** 在新窗口中打开文件夹的回调 */
|
|
23
|
+
onOpenInNewWindow?: (folderPath: string) => void;
|
|
24
|
+
}
|
|
22
25
|
/**
|
|
23
26
|
* 注册文件系统 IPC handlers
|
|
27
|
+
* @param options 可选配置
|
|
24
28
|
*/
|
|
25
|
-
declare function registerFileExplorerHandlers(): void;
|
|
29
|
+
declare function registerFileExplorerHandlers(options?: FileExplorerOptions): void;
|
|
26
30
|
|
|
27
|
-
export { createElectronAdapter, electronUrlEncoder, registerFileExplorerHandlers, setClipboardAdapter };
|
|
31
|
+
export { type FileExplorerOptions, createElectronAdapter, electronUrlEncoder, registerFileExplorerHandlers, setClipboardAdapter };
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlatformAdapter, ClipboardAdapter } from '@huyooo/file-explorer-core';
|
|
1
|
+
import { PlatformAdapter, encodeFileUrl, ClipboardAdapter } from '@huyooo/file-explorer-core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* File Explorer Electron Bridge - Main Process
|
|
@@ -15,13 +15,17 @@ declare function setClipboardAdapter(adapter: ClipboardAdapter): void;
|
|
|
15
15
|
* 创建 Electron 平台适配器
|
|
16
16
|
*/
|
|
17
17
|
declare function createElectronAdapter(): PlatformAdapter;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
|
|
18
|
+
/** URL 编码器(使用 core 中的协议工具) */
|
|
19
|
+
declare const electronUrlEncoder: typeof encodeFileUrl;
|
|
20
|
+
/** 文件管理器配置选项 */
|
|
21
|
+
interface FileExplorerOptions {
|
|
22
|
+
/** 在新窗口中打开文件夹的回调 */
|
|
23
|
+
onOpenInNewWindow?: (folderPath: string) => void;
|
|
24
|
+
}
|
|
22
25
|
/**
|
|
23
26
|
* 注册文件系统 IPC handlers
|
|
27
|
+
* @param options 可选配置
|
|
24
28
|
*/
|
|
25
|
-
declare function registerFileExplorerHandlers(): void;
|
|
29
|
+
declare function registerFileExplorerHandlers(options?: FileExplorerOptions): void;
|
|
26
30
|
|
|
27
|
-
export { createElectronAdapter, electronUrlEncoder, registerFileExplorerHandlers, setClipboardAdapter };
|
|
31
|
+
export { type FileExplorerOptions, createElectronAdapter, electronUrlEncoder, registerFileExplorerHandlers, setClipboardAdapter };
|