Repository navigation
Expand file tree
/
Copy pathpreload.js
More file actions
90 lines (79 loc) · 4.79 KB
/
Copy pathpreload.js
File metadata and controls
90 lines (79 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { contextBridge, ipcRenderer, webUtils } = require('electron');
contextBridge.exposeInMainWorld('api', {
// Terminal
createTerminal: (opts) => ipcRenderer.invoke('term:create', opts),
sendInput: (id, data) => ipcRenderer.send('term:input', id, data),
resizeTerminal: (id, cols, rows) => ipcRenderer.send('term:resize', id, cols, rows),
killTerminal: (id) => ipcRenderer.send('term:kill', id),
onTermData: (callback) => ipcRenderer.on('term:data', (e, id, data) => callback(id, data)),
onTermExit: (callback) => ipcRenderer.on('term:exit', (e, id, code) => callback(id, code)),
// Native SSH
sshConnect: (cfg) => ipcRenderer.invoke('ssh:connect', cfg),
sshInput: (id, data) => ipcRenderer.send('ssh:input', id, data),
sshResize: (id, cols, rows) => ipcRenderer.send('ssh:resize', id, cols, rows),
sshClose: (id) => ipcRenderer.send('ssh:close', id),
onSshData: (cb) => ipcRenderer.on('ssh:data', (e, id, data) => cb(id, data)),
onSshExit: (cb) => ipcRenderer.on('ssh:exit', (e, id, code) => cb(id, code)),
onSshStatus: (cb) => ipcRenderer.on('ssh:status', (e, id, msg) => cb(id, msg)),
onSshPrompt: (cb) => ipcRenderer.on('ssh:prompt', (e, id, payload) => cb(id, payload)),
sshPromptReply: (id, answers) => ipcRenderer.send('ssh:prompt-reply', id, answers),
sshFindKeys: () => ipcRenderer.invoke('ssh:findKeys'),
sshDefaultUser: () => ipcRenderer.invoke('ssh:defaultUser'),
// SFTP (rides the live SSH session)
sftpList: (id, path) => ipcRenderer.invoke('sftp:list', id, path),
sftpRealpath: (id, path) => ipcRenderer.invoke('sftp:realpath', id, path),
sftpStat: (id, path) => ipcRenderer.invoke('sftp:stat', id, path),
sftpDownload: (id, remote, local) => ipcRenderer.invoke('sftp:download', id, remote, local),
sftpUpload: (id, local, remote) => ipcRenderer.invoke('sftp:upload', id, local, remote),
sftpMkdir: (id, path) => ipcRenderer.invoke('sftp:mkdir', id, path),
sftpRename: (id, from, to) => ipcRenderer.invoke('sftp:rename', id, from, to),
sftpChmod: (id, path, mode) => ipcRenderer.invoke('sftp:chmod', id, path, mode),
sftpDelete: (id, path, isDir) => ipcRenderer.invoke('sftp:delete', id, path, isDir),
onSftpProgress: (cb) => ipcRenderer.on('sftp:progress', (e, id, p) => cb(id, p)),
// FTP
ftpConnect: (config) => ipcRenderer.invoke('ftp:connect', config),
ftpList: (id, path) => ipcRenderer.invoke('ftp:list', id, path),
ftpDownload: (id, remote, local) => ipcRenderer.invoke('ftp:download', id, remote, local),
ftpUpload: (id, local, remote) => ipcRenderer.invoke('ftp:upload', id, local, remote),
ftpMkdir: (id, path) => ipcRenderer.invoke('ftp:mkdir', id, path),
ftpDelete: (id, path, isDir) => ipcRenderer.invoke('ftp:delete', id, path, isDir),
ftpPwd: (id) => ipcRenderer.invoke('ftp:pwd', id),
ftpDisconnect: (id) => ipcRenderer.invoke('ftp:disconnect', id),
// Clipboard
clipboardReadImage: () => ipcRenderer.invoke('clipboard:readImage'),
clipboardWriteText: (text) => ipcRenderer.send('clipboard:writeText', text),
// Dialogs
saveFileDialog: (name) => ipcRenderer.invoke('dialog:saveFile', name),
openFileDialog: (opts) => ipcRenderer.invoke('dialog:openFile', opts),
openKeyDialog: () => ipcRenderer.invoke('dialog:openKey'),
openDirectoryDialog: () => ipcRenderer.invoke('dialog:openDirectory'),
// Electron 32+ removed File.path; this is the supported replacement.
pathForFile: (file) => {
try { return webUtils.getPathForFile(file); } catch { return ''; }
},
// Saved hosts
listHosts: () => ipcRenderer.invoke('hosts:list'),
getHost: (key) => ipcRenderer.invoke('hosts:get', key),
saveHost: (data) => ipcRenderer.invoke('hosts:save', data),
deleteHost: (key) => ipcRenderer.invoke('hosts:delete', key),
// Quicklinks
listQuicklinks: () => ipcRenderer.invoke('quicklinks:list'),
getQuicklink: (id) => ipcRenderer.invoke('quicklinks:get', id),
saveQuicklink: (data) => ipcRenderer.invoke('quicklinks:save', data),
deleteQuicklink: (id) => ipcRenderer.invoke('quicklinks:delete', id),
// App state persistence
loadState: () => ipcRenderer.invoke('state:load'),
saveState: (state) => ipcRenderer.invoke('state:save', state),
// Keep-alive
keepAliveGet: () => ipcRenderer.invoke('keepalive:get'),
keepAliveSet: (patch) => ipcRenderer.invoke('keepalive:set', patch),
// Remote update
updateState: () => ipcRenderer.invoke('update:state'),
updateCheck: () => ipcRenderer.invoke('update:check'),
updateSourceGet: () => ipcRenderer.invoke('update:source:get'),
updateSourceSet: (patch) => ipcRenderer.invoke('update:source:set', patch),
updateSourceBrowse: () => ipcRenderer.invoke('update:source:browse'),
updateDownload: () => ipcRenderer.invoke('update:download'),
updateInstall: () => ipcRenderer.invoke('update:install'),
onUpdateState: (cb) => ipcRenderer.on('update:state', (e, state) => cb(state)),
});