/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/desktop/src/main/ipc/shell.ts
69 строк
2 KB
Ran Luo
chore(deps): upgrade all packages to latest + align shared versions (#4597)
21 июн 2026, 03:40
Не верифицирован
21 июн 2026, 03:40
4129550
Код
Авторство
О чём код?
import { ipcMain, shell, clipboard } from 'electron' import log from 'electron-log' import * as plist from 'plist' export const registerShellHandlers = (): void => { ipcMain.handle('mt::shell::open-external', async(_e, url: string) => { try { await shell.openExternal(url) return true } catch (err) { log.error('shell.openExternal failed:', err) return false } }) ipcMain.on('mt::shell::open-external', (_e, url: string) => { shell.openExternal(url).catch((err) => log.error('shell.openExternal failed:', err)) }) ipcMain.on('mt::shell::show-item', (_e, fullPath: string) => { try { shell.showItemInFolder(fullPath) } catch (err) { log.error('shell.showItemInFolder failed:', err) } }) ipcMain.handle('mt::shell::open-path', async(_e, fullPath: string) => { try { return await shell.openPath(fullPath) } catch (err) { log.error('shell.openPath failed:', err) return String(err instanceof Error ? err.message : err) } }) ipcMain.on('mt::clipboard::write-text', (_e, text: string) => { try { clipboard.writeText(text) } catch (err) { log.error('clipboard.writeText failed:', err) } }) ipcMain.handle('mt::clipboard::read-text', () => { try { return clipboard.readText() } catch { return '' } }) ipcMain.handle('mt::clipboard::guess-file-path', () => { try { if (process.platform === 'darwin') { if (clipboard.has('NSFilenamesPboardType')) { const parsed = plist.parse(clipboard.read('NSFilenamesPboardType')) return Array.isArray(parsed) && parsed.length ? parsed[0] : '' } return '' } if (process.platform === 'win32') { const raw = clipboard.read('FileNameW') const filePath = raw ? raw.replace(new RegExp(String.fromCharCode(0), 'g'), '') : '' return typeof filePath === 'string' ? filePath : '' } return '' } catch (err) { log.error('clipboard.guess-file-path failed:', err) return '' } }) }