* 在文件管理器中显示文件位置(跨平台) * macOS: 在 Finder 中显示并选中文件 * Windows: 在资源管理器中显示并选中文件 * Linux: 在文件管理器中显示并选中文件 * * Electron 的 shell.showItemInFolder() 是跨平台的 API, * 会自动根据操作系统选择相应的文件管理器
(filePath: string)
| 158 | * 会自动根据操作系统选择相应的文件管理器 |
| 159 | */ |
| 160 | public async revealInFinder(filePath: string): Promise<void> { |
| 161 | try { |
| 162 | if (!filePath) { |
| 163 | throw new Error('文件路径不能为空') |
| 164 | } |
| 165 | |
| 166 | // Electron 的 shell.showItemInFolder() 是跨平台的 |
| 167 | // 在 macOS 上会自动使用 Finder,Windows 上使用资源管理器,Linux 上使用文件管理器 |
| 168 | shell.showItemInFolder(filePath) |
| 169 | } catch (error: unknown) { |
| 170 | const platformName = |
| 171 | process.platform === 'darwin' ? 'macOS' : process.platform === 'win32' ? 'Windows' : 'Linux' |
| 172 | console.error(`[System] 在${platformName}文件管理器中显示文件失败:`, error) |
| 173 | throw error |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | private async showContextMenu(event: Electron.IpcMainInvokeEvent, menuItems: any): Promise<void> { |
| 178 | if (!this.mainWindow) return |