()
| 39 | } |
| 40 | |
| 41 | private setupIPC(): void { |
| 42 | // 使用系统默认程序打开 URL |
| 43 | ipcMain.on('shell-open-external', async (event, url: string) => { |
| 44 | try { |
| 45 | await shell.openExternal(url) |
| 46 | event.returnValue = { success: true } |
| 47 | } catch (error: unknown) { |
| 48 | console.error('[PluginShell] 打开 URL 失败:', error) |
| 49 | event.returnValue = { |
| 50 | success: false, |
| 51 | error: error instanceof Error ? error.message : '未知错误' |
| 52 | } |
| 53 | } |
| 54 | }) |
| 55 | |
| 56 | // 在文件管理器中显示文件 |
| 57 | ipcMain.on('shell-show-item-in-folder', (event, fullPath: string) => { |
| 58 | try { |
| 59 | shell.showItemInFolder(fullPath) |
| 60 | } catch (error: unknown) { |
| 61 | console.error('[PluginShell] 在文件管理器中显示文件失败:', error) |
| 62 | } |
| 63 | event.returnValue = undefined |
| 64 | }) |
| 65 | |
| 66 | // 使用系统默认方式打开文件或文件夹 |
| 67 | ipcMain.on('shell-open-path', async (event, fullPath: string) => { |
| 68 | try { |
| 69 | const errorMessage = await shell.openPath(fullPath) |
| 70 | event.returnValue = { |
| 71 | success: !errorMessage, |
| 72 | error: errorMessage || undefined |
| 73 | } |
| 74 | } catch (error: unknown) { |
| 75 | console.error('[PluginShell] 使用系统默认方式打开文件失败:', error) |
| 76 | event.returnValue = { |
| 77 | success: false, |
| 78 | error: error instanceof Error ? error.message : '未知错误' |
| 79 | } |
| 80 | } |
| 81 | }) |
| 82 | |
| 83 | // 获取文件系统图标(返回 base64 Data URL,同步) |
| 84 | ipcMain.on('get-file-icon', (event, filePath: string) => { |
| 85 | getFileIconAsBase64(filePath) |
| 86 | .then((icon) => { |
| 87 | event.returnValue = icon |
| 88 | }) |
| 89 | .catch((error: unknown) => { |
| 90 | console.error('[PluginShell] 获取文件图标失败:', filePath, error) |
| 91 | event.returnValue = null |
| 92 | }) |
| 93 | }) |
| 94 | |
| 95 | // 播放系统提示音(同步) |
| 96 | ipcMain.on('shell-beep', (event) => { |
| 97 | try { |
| 98 | shell.beep() |
no test coverage detected