mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-25 01:40:45 +00:00
* chore: ignore local .worktrees/ directory Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): editorTabStore scaffold with single-tab ops Implements the EditorTabStore class singleton (matching activeTabStore pattern) with updateContent, markSaved, setWordWrap, setSavingState, close, and subscribe. Includes useSyncExternalStore hooks and 6 passing unit tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): editorTabStore promoteFromModal with per-session path dedup * feat(editor): confirmCloseBySession for session teardown Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(sftp): writeTextFileByConnection for pane-agnostic saves Adds a new `writeTextFileByConnection(connectionId, expectedHostId, filePath, content, filenameEncoding?)` method to `useSftpExternalOperations` that looks up the SFTP pane by connection ID (with a hostId safety check) instead of the left/right-side coupling used by `writeTextFile`. Threads the existing `getPaneByConnectionId` callback through the call site and re-exports the new method via `SftpStateApi`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(editor): editorSftpBridge singleton for out-of-React saves Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(editor): extract TextEditorPane from TextEditorModal Lift Monaco editor body + toolbar + theme sync + paste fallback into a pure TextEditorPane component. Adds sftp.editor.maximize i18n key to en.ts and zh-CN.ts locale files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(editor): drop unused getLanguageId import in TextEditorPane Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(editor): TextEditorModal delegates to TextEditorPane Replace the monolithic modal (560 lines including full Monaco setup) with a thin Dialog shell (~150 lines) that owns content/saving/saveError/ languageId state, save orchestration, and dirty-check on close, then delegates all editor chrome to <TextEditorPane chrome="modal" />. Exports TextEditorModalSnapshot for the optional onPromoteToTab callback so callers can later wire tab promotion (Task 12) without breaking the existing interface — the new prop is optional and existing callers (SftpOverlays.tsx) are source-compatible with zero changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(editor): include fileName and wordWrap in TextEditorModalSnapshot Task 12 will populate the promoted tab with these fields, so the snapshot must carry them from the modal at maximize time. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): UnsavedChangesDialog three-button confirm * fix(editor): resolve UnsavedChangesDialog re-entrance and unmount leaks - Re-entrance: if prompt() is called while a prior prompt is still pending, cancel the prior one so its caller doesn't hang forever. - Unmount: resolve any in-flight prompt as "cancel" in the effect cleanup so awaiters don't leak when the provider unmounts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): TextEditorTabView tab-form shell Add TextEditorTabView component that binds an editorTabStore entry to TextEditorPane, with CSS display:none toggling for inactive tabs so the Monaco instance persists across tab switches. Also adds setLanguage public method to EditorTabStore (lands Task 15's intent early — Task 15 can be a no-op). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(editor): read live store state in TextEditorTabView handlers React state snapshot lags the store by a microtask. Closing over `tab` meant a keystroke between Monaco's onChange and a Ctrl+S would write stale content and mark a stale baseline. Read via editorTabStore.getTab at call time instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): dispatch editor:* tab ids in App and activeTabStore - Add EDITOR_PREFIX, isEditorTabId, toEditorTabId, fromEditorTabId helpers - Add useIsEditorTabActive hook to activeTabStore - Update useIsTerminalLayerVisible to exclude editor tabs - Import useEditorTabs and TextEditorTabView into App.tsx - Append editor tab ids (editor:<id>) to allTabs in hotkey handler - Mount TextEditorTabView per editorTab with CSS visibility toggling - Add editorTabs to executeHotkeyAction useCallback dependency array Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(editor): render editor tabs in TopTabs with icon/dirty/tooltip - Add `fromEditorTabId`, `isEditorTabId` imports to TopTabs.tsx - Add `FileCode`, `FileText` icons; use FileCode for code-like extensions - Extend `TopTabsProps` with `editorTabs`, `onRequestCloseEditorTab`, `hostById` - Build `editorTabMap` for O(1) lookup; add `editor` branch in `orderedTabItems` - Render editor tab chrome matching terminal tab style: file icon, dirty dot (●), filename with disambiguation suffix for duplicate filenames, close button - In App.tsx: add stub `handleRequestCloseEditorTab`, `orderedTabsWithEditors`, pass new props to `<TopTabs>` Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(editor): hoist editor-tab code-extension regex and use onSelectTab - Move CODE_EXTENSIONS_RE to module scope so it isn't recompiled per render. - Call onSelectTab(tabId) for consistency with other tab types, instead of reaching into activeTabStore directly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): maximize modal to tab and dirty-confirm tab close Wire onPromoteToTab from TextEditorModal through SftpOverlays and useSftpViewFileOps so clicking the maximize button snapshots editor state into editorTabStore and activates the new editor tab. Replace the stub handleRequestCloseEditorTab in App.tsx with a real dirty-confirm flow using UnsavedChangesProvider render-prop: clean tabs close immediately, dirty tabs prompt save/discard/cancel, and save routes through editorSftpBridge with markSaved on success. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(editor): register SFTP bridge and gate session close on dirty editor tabs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(editor): make onDisconnect async so host-picker waits for dirty check The session-close dirty gate added in Task 13 made onDisconnect async, but the host-picker in SftpPaneDialogs still called it synchronously before kicking off onConnect — a fire-and-forget that raced past the dirty prompt and let unsaved editor tabs slip through. Propagate the Promise return type through SftpPaneCallbacks / SftpPaneDialogs / useSftpViewPaneActionsResult and await it at the host-picker call sites. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): block app quit while editor tabs are dirty Add a before-quit IPC guard that asks the renderer whether any editor tab has unsaved changes. If dirty tabs exist, preventDefault() blocks the quit and a warning toast is shown. The app quits normally once editors are clean. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(editor): add 5s timeout fallback to quit-guard IPC check If the renderer crashes or throws before reporting back, the quitGuard would stay busy forever and the app could not be quit. Fall back to force-quit after 5 s if no reply arrives. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): quit-guard uses quitConfirmed flag to prevent re-entry loop The prior flow reset quitGuardChannelBusy before calling app.quit(), which on macOS re-fires before-quit and re-entered the dirty check with the flag cleared — creating an infinite IPC loop. Introduce a separate quitConfirmed flag that commits to quitting before app.quit() fires, so the re-entry takes the fast path. Also extract QUIT_GUARD_TIMEOUT_MS and clarify that a concurrent quit while a check is in flight is swallowed (preventDefault) rather than letting the second event through. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): use absolute inset-0 for tab panel and add sr-only DialogTitle Two bugs surfaced during the first dev-server smoke test: 1. Editor tab content was blank because TextEditorTabView used only className="h-full", while its sibling panels (VaultView, SftpView, TerminalLayerMount, LogView) all fill their flex-1 parent via `absolute inset-0`. In normal flow the editor tab collapsed to zero height. Match the sibling convention. 2. Radix printed an accessibility warning because the Task 7 refactor pulled the DialogTitle out of DialogContent and into the Pane header (now a plain span). Add a visually hidden DialogTitle that mirrors the filename, so screen readers have a title without showing it twice. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): raise tab panel z-index to 20 so it sits above TerminalLayer TerminalLayer's root is visibility:hidden when the active tab is an editor tab, but its inner panels set `absolute inset-0 z-10` on their own and those still paint. Without an explicit z on the editor tab panel, TerminalLayer's inner bg-background div was covering the Monaco content, producing a blank screen. Also add bg-background to the wrapper so the editor tab paints an opaque surface (matches the pattern VaultViewContainer / TerminalLayer follow). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): show host label and remote path next to filename in tab header The editor tab form previously only showed the bare filename in its header, which is ambiguous when the same filename is open against multiple hosts. Add an optional subtitle prop on TextEditorPane and populate it from the tab form with `<hostLabel>:<remotePath>` rendered in muted text beside the filename. The modal keeps its existing filename-only header. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): bridge supports multiple useSftpState instances useSftpState is instantiated in both the top-level SftpView and the terminal's SftpSidePanel, each owning its own pane registry. The editor bridge previously stored only one writer, so maximizing a file opened from the terminal side panel registered nothing (bridge was owned by SftpView which may never have mounted) and save failed with "bridge not registered". Change the bridge to track a Set of writers and dispatch by trying each until one owns the connectionId (signalled by its specific "connection no longer available" error). Add registerEditorSftpWriterScoped that returns an unregister fn so each instance's cleanup removes only its own entry. Register in both SftpView and SftpSidePanel. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): Cmd+W closes editor tab + terminal close forces tab close Two behaviors added after user feedback from dev-server smoke-test: 1. Cmd/Ctrl+W (the closeTab hotkey) previously did nothing on editor tabs because executeHotkeyAction had no branch for editor:* ids. Add one that reaches into the UnsavedChangesProvider render-prop's close flow via a ref, routing through the existing dirty-confirm path. 2. Closing a terminal tab unmounts its SftpSidePanel which destroys the useSftpState instance that owned the connection. Any editor tab promoted from that panel would then be stuck — bridge gone, save channel dead. On SftpSidePanel unmount, gather the connection ids it owned and call a new editorTabStore.forceCloseBySessions to drop matching editor tabs. Dirty state is dropped because the user closed the terminal knowing the file was open — there is no save channel left anyway. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): Cmd/Ctrl+W works when focus is inside Monaco Monaco's internal key-event dispatcher swallows keydown before the capture-phase handler on the Pane's root div can see it, so the global hotkey dispatcher never got the chance to close the editor tab when the editor had focus. Register a Monaco editor command for the close-tab keybinding and route it through a handleCloseRef — mirrors the same pattern used for Cmd/Ctrl+S. Also drop the modal-only guard in the capture-phase handler so the outer-chrome path works in tab mode too. TextEditorTabView now receives an onRequestClose(tabId) prop that App.tsx wires via the render-prop-exposed handleRequestCloseEditorTabRef, same mechanism as the hotkey-dispatcher path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): fall back to Vaults when forceCloseBySessions removes the active tab Closing a terminal tab triggers SftpSidePanel unmount which force-closes its editor tabs. If the editor tab being removed happened to be the active tab (user maximized → then closed the owning terminal from another path), the app ended up on a stale activeTabId with no selected tab and blank content. Inside forceCloseBySessions, if the active tab was one of the removed editor ids, redirect to 'vault'. Picking a more sophisticated neighbor would need the full orderedTabs list which isn't reachable from this layer; Vaults is always valid. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1446 lines
54 KiB
JavaScript
1446 lines
54 KiB
JavaScript
const { ipcRenderer, contextBridge, webUtils } = require("electron");
|
|
const os = require("node:os");
|
|
|
|
const dataListeners = new Map();
|
|
const exitListeners = new Map();
|
|
const transferProgressListeners = new Map();
|
|
const transferCompleteListeners = new Map();
|
|
const transferErrorListeners = new Map();
|
|
const transferCancelledListeners = new Map();
|
|
const chainProgressListeners = new Map();
|
|
const zmodemListeners = new Map();
|
|
const sftpConnectionProgressListeners = new Set();
|
|
const authFailedListeners = new Map();
|
|
const languageChangeListeners = new Set();
|
|
const fullscreenChangeListeners = new Set();
|
|
const keyboardInteractiveListeners = new Set();
|
|
const passphraseListeners = new Set();
|
|
const passphraseTimeoutListeners = new Set();
|
|
const updateDownloadProgressListeners = new Set();
|
|
const updateDownloadedListeners = new Set();
|
|
const updateAvailableListeners = new Set();
|
|
const updateNotAvailableListeners = new Set();
|
|
const updateErrorListeners = new Set();
|
|
|
|
function cleanupTransferListeners(transferId) {
|
|
transferProgressListeners.delete(transferId);
|
|
transferCompleteListeners.delete(transferId);
|
|
transferErrorListeners.delete(transferId);
|
|
transferCancelledListeners.delete(transferId);
|
|
}
|
|
|
|
// ── MCP marker filter with per-session line buffering ──
|
|
// PTY data arrives in arbitrary chunks; the marker string (__NCMCP_) can be
|
|
// split across chunk boundaries so a simple data.includes() guard misses it.
|
|
// We buffer the trailing fragment of each chunk and prepend it to the next
|
|
// chunk, then filter complete lines that contain the marker.
|
|
|
|
const _mcpLineBufs = new Map(); // sessionId -> trailing fragment string
|
|
const _mcpFlushTimers = new Map(); // sessionId -> delayed-flush timer
|
|
|
|
// Returns true if `s` ends with a non-empty prefix of "__NCMCP_"
|
|
// (i.e. the next chunk might complete it into a marker-containing line).
|
|
function _endsWithMarkerPrefix(s) {
|
|
const p = "__NCMCP_";
|
|
for (let i = 1; i < p.length; i++) {
|
|
if (s.endsWith(p.slice(0, i))) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function filterMcpChunk(sessionId, chunk) {
|
|
// Cancel any pending delayed flush — new data arrived
|
|
const pendingTimer = _mcpFlushTimers.get(sessionId);
|
|
if (pendingTimer) {
|
|
clearTimeout(pendingTimer);
|
|
_mcpFlushTimers.delete(sessionId);
|
|
}
|
|
|
|
// Prepend any buffered fragment from the previous chunk
|
|
const held = _mcpLineBufs.get(sessionId) || "";
|
|
const data = held + chunk;
|
|
_mcpLineBufs.delete(sessionId);
|
|
|
|
// Fast path: nothing suspicious in the combined data
|
|
if (!data.includes("__NCMCP_") && !_endsWithMarkerPrefix(data)) {
|
|
return data;
|
|
}
|
|
|
|
// Slow path: scan line by line
|
|
let result = "";
|
|
let droppedAny = false;
|
|
let pos = 0;
|
|
while (pos < data.length) {
|
|
const nlIdx = data.indexOf("\n", pos);
|
|
if (nlIdx === -1) {
|
|
// Incomplete trailing line — no newline yet.
|
|
// If we dropped any marker line in this chunk, or the tail itself
|
|
// looks like it could contain a marker, buffer it. Long command
|
|
// echoes can wrap across PTY lines; wrapped fragments that don't
|
|
// contain __NCMCP_ would otherwise leak through as garbage.
|
|
const tail = data.slice(pos);
|
|
if (droppedAny || tail.includes("__NCMCP_") || _endsWithMarkerPrefix(tail)) {
|
|
_mcpLineBufs.set(sessionId, tail);
|
|
} else {
|
|
result += tail; // safe to display immediately
|
|
}
|
|
break;
|
|
}
|
|
const line = data.slice(pos, nlIdx + 1); // includes the \n
|
|
if (!line.includes("__NCMCP_")) {
|
|
result += line;
|
|
} else {
|
|
droppedAny = true;
|
|
}
|
|
pos = nlIdx + 1;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Deliver data to session listeners. Used both by the normal data path
|
|
* and by the delayed-flush timer.
|
|
*/
|
|
function _deliverToListeners(sessionId, data) {
|
|
const set = dataListeners.get(sessionId);
|
|
if (!set || !data) return;
|
|
set.forEach((cb) => {
|
|
try { cb(data); } catch (err) { console.error("Data callback failed", err); }
|
|
});
|
|
}
|
|
|
|
// ZMODEM file transfer events
|
|
ipcRenderer.on("netcatty:zmodem:detect", (_event, payload) => {
|
|
const set = zmodemListeners.get(payload.sessionId);
|
|
if (!set) return;
|
|
set.forEach((cb) => { try { cb({ type: "detect", ...payload }); } catch {} });
|
|
});
|
|
ipcRenderer.on("netcatty:zmodem:progress", (_event, payload) => {
|
|
const set = zmodemListeners.get(payload.sessionId);
|
|
if (!set) return;
|
|
set.forEach((cb) => { try { cb({ type: "progress", ...payload }); } catch {} });
|
|
});
|
|
ipcRenderer.on("netcatty:zmodem:complete", (_event, payload) => {
|
|
const set = zmodemListeners.get(payload.sessionId);
|
|
if (!set) return;
|
|
set.forEach((cb) => { try { cb({ type: "complete", ...payload }); } catch {} });
|
|
});
|
|
ipcRenderer.on("netcatty:zmodem:error", (_event, payload) => {
|
|
const set = zmodemListeners.get(payload.sessionId);
|
|
if (!set) return;
|
|
set.forEach((cb) => { try { cb({ type: "error", ...payload }); } catch {} });
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:data", (_event, payload) => {
|
|
const set = dataListeners.get(payload.sessionId);
|
|
if (!set) return;
|
|
if (payload?.syntheticEcho) {
|
|
_deliverToListeners(payload.sessionId, payload.data);
|
|
return;
|
|
}
|
|
const data = filterMcpChunk(payload.sessionId, payload.data);
|
|
if (data) {
|
|
set.forEach((cb) => {
|
|
try {
|
|
cb(data);
|
|
} catch (err) {
|
|
console.error("Data callback failed", err);
|
|
}
|
|
});
|
|
}
|
|
// If there is buffered content waiting for more data (e.g. a prompt
|
|
// right after a dropped marker line), schedule a delayed flush so it
|
|
// appears after a short pause instead of staying hidden forever.
|
|
if (_mcpLineBufs.has(payload.sessionId)) {
|
|
const sid = payload.sessionId;
|
|
_mcpFlushTimers.set(sid, setTimeout(() => {
|
|
const held = _mcpLineBufs.get(sid);
|
|
_mcpLineBufs.delete(sid);
|
|
_mcpFlushTimers.delete(sid);
|
|
if (held) _deliverToListeners(sid, held);
|
|
}, 80));
|
|
}
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:exit", (_event, payload) => {
|
|
const set = exitListeners.get(payload.sessionId);
|
|
if (set) {
|
|
set.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("Exit callback failed", err);
|
|
}
|
|
});
|
|
}
|
|
dataListeners.delete(payload.sessionId);
|
|
exitListeners.delete(payload.sessionId);
|
|
zmodemListeners.delete(payload.sessionId);
|
|
const pendingTimer = _mcpFlushTimers.get(payload.sessionId);
|
|
if (pendingTimer) {
|
|
clearTimeout(pendingTimer);
|
|
_mcpFlushTimers.delete(payload.sessionId);
|
|
}
|
|
_mcpLineBufs.delete(payload.sessionId); // clean up any held fragment
|
|
});
|
|
|
|
// Chain progress events (for jump host connections)
|
|
ipcRenderer.on("netcatty:chain:progress", (_event, payload) => {
|
|
const { sessionId, hop, total, label, status, error } = payload;
|
|
// Notify all registered chain progress listeners
|
|
chainProgressListeners.forEach((cb) => {
|
|
try {
|
|
cb(sessionId, hop, total, label, status, error);
|
|
} catch (err) {
|
|
console.error("Chain progress callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
// SFTP connection progress events (auth method logs)
|
|
ipcRenderer.on("netcatty:sftp:connection-progress", (_event, payload) => {
|
|
sftpConnectionProgressListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload.sessionId, payload.label, payload.status, payload.detail);
|
|
} catch (err) {
|
|
console.error("SFTP connection progress callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:languageChanged", (_event, language) => {
|
|
languageChangeListeners.forEach((cb) => {
|
|
try {
|
|
cb(language);
|
|
} catch (err) {
|
|
console.error("Language changed callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:window:fullscreen-changed", (_event, isFullscreen) => {
|
|
fullscreenChangeListeners.forEach((cb) => {
|
|
try {
|
|
cb(isFullscreen);
|
|
} catch (err) {
|
|
console.error("Fullscreen changed callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Authentication failed events
|
|
ipcRenderer.on("netcatty:auth:failed", (_event, payload) => {
|
|
const set = authFailedListeners.get(payload.sessionId);
|
|
if (set) {
|
|
set.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("Auth failed callback failed", err);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Keyboard-interactive authentication events (2FA/MFA)
|
|
ipcRenderer.on("netcatty:keyboard-interactive", (_event, payload) => {
|
|
keyboardInteractiveListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("Keyboard-interactive callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Passphrase request events for encrypted SSH keys
|
|
ipcRenderer.on("netcatty:passphrase-request", (_event, payload) => {
|
|
passphraseListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("Passphrase request callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Passphrase timeout events (request expired)
|
|
ipcRenderer.on("netcatty:passphrase-timeout", (_event, payload) => {
|
|
passphraseTimeoutListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("Passphrase timeout callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Auto-update events
|
|
ipcRenderer.on("netcatty:update:update-available", (_event, payload) => {
|
|
updateAvailableListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("onUpdateAvailable callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:update:update-not-available", () => {
|
|
updateNotAvailableListeners.forEach((cb) => {
|
|
try {
|
|
cb();
|
|
} catch (err) {
|
|
console.error("onUpdateNotAvailable callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:update:download-progress", (_event, payload) => {
|
|
updateDownloadProgressListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("Update download-progress callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:update:downloaded", () => {
|
|
updateDownloadedListeners.forEach((cb) => {
|
|
try {
|
|
cb();
|
|
} catch (err) {
|
|
console.error("Update downloaded callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:update:error", (_event, payload) => {
|
|
updateErrorListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("Update error callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Transfer progress events
|
|
ipcRenderer.on("netcatty:transfer:progress", (_event, payload) => {
|
|
const cb = transferProgressListeners.get(payload.transferId);
|
|
if (cb) {
|
|
try {
|
|
cb(payload.transferred, payload.totalBytes, payload.speed);
|
|
} catch (err) {
|
|
console.error("Transfer progress callback failed", err);
|
|
}
|
|
}
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:transfer:complete", (_event, payload) => {
|
|
const cb = transferCompleteListeners.get(payload.transferId);
|
|
if (cb) {
|
|
try {
|
|
cb();
|
|
} catch (err) {
|
|
console.error("Transfer complete callback failed", err);
|
|
}
|
|
}
|
|
cleanupTransferListeners(payload.transferId);
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:transfer:error", (_event, payload) => {
|
|
const cb = transferErrorListeners.get(payload.transferId);
|
|
if (cb) {
|
|
try {
|
|
cb(payload.error);
|
|
} catch (err) {
|
|
console.error("Transfer error callback failed", err);
|
|
}
|
|
}
|
|
cleanupTransferListeners(payload.transferId);
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:transfer:cancelled", (_event, payload) => {
|
|
const cb = transferCancelledListeners.get(payload.transferId);
|
|
if (cb) {
|
|
try { cb(); } catch { }
|
|
}
|
|
cleanupTransferListeners(payload.transferId);
|
|
});
|
|
|
|
// Upload with progress listeners
|
|
const uploadProgressListeners = new Map();
|
|
const uploadCompleteListeners = new Map();
|
|
const uploadErrorListeners = new Map();
|
|
|
|
// Compress upload listeners
|
|
const compressProgressListeners = new Map();
|
|
const compressCompleteListeners = new Map();
|
|
const compressErrorListeners = new Map();
|
|
|
|
ipcRenderer.on("netcatty:upload:progress", (_event, payload) => {
|
|
const cb = uploadProgressListeners.get(payload.transferId);
|
|
if (cb) {
|
|
try {
|
|
cb(payload.transferred, payload.totalBytes, payload.speed);
|
|
} catch (err) {
|
|
console.error("Upload progress callback failed", err);
|
|
}
|
|
}
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:upload:complete", (_event, payload) => {
|
|
const cb = uploadCompleteListeners.get(payload.transferId);
|
|
if (cb) {
|
|
try {
|
|
cb();
|
|
} catch (err) {
|
|
console.error("Upload complete callback failed", err);
|
|
}
|
|
}
|
|
// Cleanup listeners
|
|
uploadProgressListeners.delete(payload.transferId);
|
|
uploadCompleteListeners.delete(payload.transferId);
|
|
uploadErrorListeners.delete(payload.transferId);
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:upload:error", (_event, payload) => {
|
|
const cb = uploadErrorListeners.get(payload.transferId);
|
|
if (cb) {
|
|
try {
|
|
cb(payload.error);
|
|
} catch (err) {
|
|
console.error("Upload error callback failed", err);
|
|
}
|
|
}
|
|
// Cleanup listeners
|
|
uploadProgressListeners.delete(payload.transferId);
|
|
uploadCompleteListeners.delete(payload.transferId);
|
|
uploadErrorListeners.delete(payload.transferId);
|
|
});
|
|
|
|
// Compress upload events
|
|
ipcRenderer.on("netcatty:compress:progress", (_event, payload) => {
|
|
const cb = compressProgressListeners.get(payload.compressionId);
|
|
if (cb) {
|
|
try {
|
|
cb(payload.phase, payload.transferred, payload.total);
|
|
} catch (err) {
|
|
console.error("Compress progress callback failed", err);
|
|
}
|
|
}
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:compress:complete", (_event, payload) => {
|
|
const cb = compressCompleteListeners.get(payload.compressionId);
|
|
if (cb) {
|
|
try {
|
|
cb();
|
|
} catch (err) {
|
|
console.error("Compress complete callback failed", err);
|
|
}
|
|
}
|
|
// Cleanup listeners
|
|
compressProgressListeners.delete(payload.compressionId);
|
|
compressCompleteListeners.delete(payload.compressionId);
|
|
compressErrorListeners.delete(payload.compressionId);
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:compress:error", (_event, payload) => {
|
|
const cb = compressErrorListeners.get(payload.compressionId);
|
|
if (cb) {
|
|
try {
|
|
cb(payload.error);
|
|
} catch (err) {
|
|
console.error("Compress error callback failed", err);
|
|
}
|
|
}
|
|
// Cleanup listeners
|
|
compressProgressListeners.delete(payload.compressionId);
|
|
compressCompleteListeners.delete(payload.compressionId);
|
|
compressErrorListeners.delete(payload.compressionId);
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:compress:cancelled", (_event, payload) => {
|
|
// Just cleanup listeners, the UI already knows it's cancelled
|
|
compressProgressListeners.delete(payload.compressionId);
|
|
compressCompleteListeners.delete(payload.compressionId);
|
|
compressErrorListeners.delete(payload.compressionId);
|
|
});
|
|
|
|
// Port forwarding status listeners
|
|
const portForwardStatusListeners = new Map();
|
|
|
|
ipcRenderer.on("netcatty:portforward:status", (_event, payload) => {
|
|
const { tunnelId, status, error } = payload;
|
|
const callbacks = portForwardStatusListeners.get(tunnelId);
|
|
if (callbacks) {
|
|
callbacks.forEach((cb) => {
|
|
try {
|
|
cb(status, error);
|
|
} catch (err) {
|
|
console.error("Port forward status callback failed", err);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// File watcher listeners (for auto-sync feature)
|
|
const fileWatchSyncedListeners = new Set();
|
|
const fileWatchErrorListeners = new Set();
|
|
|
|
ipcRenderer.on("netcatty:filewatch:synced", (_event, payload) => {
|
|
fileWatchSyncedListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("File watch synced callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
ipcRenderer.on("netcatty:filewatch:error", (_event, payload) => {
|
|
fileWatchErrorListeners.forEach((cb) => {
|
|
try {
|
|
cb(payload);
|
|
} catch (err) {
|
|
console.error("File watch error callback failed", err);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Buffer the latest tray menu data so it can be replayed when the React
|
|
// component subscribes after lazy-mount (avoiding the first-open race).
|
|
let _lastTrayMenuData = null;
|
|
ipcRenderer.on("netcatty:trayPanel:setMenuData", (_event, data) => {
|
|
_lastTrayMenuData = data;
|
|
});
|
|
|
|
const api = {
|
|
getWindowsPtyInfo: () => {
|
|
if (process.platform !== "win32") {
|
|
return null;
|
|
}
|
|
|
|
const releaseParts = os.release().split(".");
|
|
const buildNumber = Number.parseInt(releaseParts[2] || "", 10);
|
|
const hasBuildNumber = Number.isFinite(buildNumber);
|
|
const backend =
|
|
hasBuildNumber && buildNumber < 18309 ? "winpty" : "conpty";
|
|
|
|
return hasBuildNumber ? { backend, buildNumber } : { backend };
|
|
},
|
|
startSSHSession: async (options) => {
|
|
const result = await ipcRenderer.invoke("netcatty:start", options);
|
|
return result.sessionId;
|
|
},
|
|
startTelnetSession: async (options) => {
|
|
const result = await ipcRenderer.invoke("netcatty:telnet:start", options);
|
|
return result.sessionId;
|
|
},
|
|
startMoshSession: async (options) => {
|
|
const result = await ipcRenderer.invoke("netcatty:mosh:start", options);
|
|
return result.sessionId;
|
|
},
|
|
startLocalSession: async (options) => {
|
|
const result = await ipcRenderer.invoke("netcatty:local:start", options || {});
|
|
return result.sessionId;
|
|
},
|
|
startSerialSession: async (options) => {
|
|
const result = await ipcRenderer.invoke("netcatty:serial:start", options);
|
|
return result.sessionId;
|
|
},
|
|
listSerialPorts: async () => {
|
|
return ipcRenderer.invoke("netcatty:serial:list");
|
|
},
|
|
getDefaultShell: async () => {
|
|
return ipcRenderer.invoke("netcatty:local:defaultShell");
|
|
},
|
|
discoverShells: () => ipcRenderer.invoke("netcatty:shells:discover"),
|
|
validatePath: async (path, type) => {
|
|
return ipcRenderer.invoke("netcatty:local:validatePath", { path, type });
|
|
},
|
|
writeToSession: (sessionId, data) => {
|
|
ipcRenderer.send("netcatty:write", { sessionId, data });
|
|
},
|
|
execCommand: async (options) => {
|
|
return ipcRenderer.invoke("netcatty:ssh:exec", options);
|
|
},
|
|
getSessionPwd: async (sessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ssh:pwd", { sessionId });
|
|
},
|
|
getSessionRemoteInfo: async (sessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ssh:remoteInfo", { sessionId });
|
|
},
|
|
getSessionDistroInfo: async (sessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ssh:distroInfo", { sessionId });
|
|
},
|
|
getServerStats: async (sessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ssh:stats", { sessionId });
|
|
},
|
|
generateKeyPair: async (options) => {
|
|
return ipcRenderer.invoke("netcatty:key:generate", options);
|
|
},
|
|
checkSshAgent: async () => {
|
|
return ipcRenderer.invoke("netcatty:ssh:check-agent");
|
|
},
|
|
getDefaultKeys: async () => {
|
|
return ipcRenderer.invoke("netcatty:ssh:get-default-keys");
|
|
},
|
|
resizeSession: (sessionId, cols, rows) => {
|
|
ipcRenderer.send("netcatty:resize", { sessionId, cols, rows });
|
|
},
|
|
closeSession: (sessionId) => {
|
|
ipcRenderer.send("netcatty:close", { sessionId });
|
|
},
|
|
setSessionEncoding: (sessionId, encoding) =>
|
|
ipcRenderer.invoke("netcatty:ssh:setEncoding", { sessionId, encoding }),
|
|
onZmodemEvent: (sessionId, cb) => {
|
|
if (!zmodemListeners.has(sessionId)) zmodemListeners.set(sessionId, new Set());
|
|
zmodemListeners.get(sessionId).add(cb);
|
|
return () => zmodemListeners.get(sessionId)?.delete(cb);
|
|
},
|
|
cancelZmodem: (sessionId) => {
|
|
ipcRenderer.send("netcatty:zmodem:cancel", { sessionId });
|
|
},
|
|
onSessionData: (sessionId, cb) => {
|
|
if (!dataListeners.has(sessionId)) dataListeners.set(sessionId, new Set());
|
|
dataListeners.get(sessionId).add(cb);
|
|
return () => dataListeners.get(sessionId)?.delete(cb);
|
|
},
|
|
onSessionExit: (sessionId, cb) => {
|
|
if (!exitListeners.has(sessionId)) exitListeners.set(sessionId, new Set());
|
|
exitListeners.get(sessionId).add(cb);
|
|
return () => exitListeners.get(sessionId)?.delete(cb);
|
|
},
|
|
onAuthFailed: (sessionId, cb) => {
|
|
if (!authFailedListeners.has(sessionId)) authFailedListeners.set(sessionId, new Set());
|
|
authFailedListeners.get(sessionId).add(cb);
|
|
return () => authFailedListeners.get(sessionId)?.delete(cb);
|
|
},
|
|
// Keyboard-interactive authentication (2FA/MFA)
|
|
onKeyboardInteractive: (cb) => {
|
|
keyboardInteractiveListeners.add(cb);
|
|
return () => keyboardInteractiveListeners.delete(cb);
|
|
},
|
|
respondKeyboardInteractive: async (requestId, responses, cancelled = false) => {
|
|
return ipcRenderer.invoke("netcatty:keyboard-interactive:respond", {
|
|
requestId,
|
|
responses,
|
|
cancelled,
|
|
});
|
|
},
|
|
// Passphrase request for encrypted SSH keys
|
|
onPassphraseRequest: (cb) => {
|
|
passphraseListeners.add(cb);
|
|
return () => passphraseListeners.delete(cb);
|
|
},
|
|
respondPassphrase: async (requestId, passphrase, cancelled = false) => {
|
|
return ipcRenderer.invoke("netcatty:passphrase:respond", {
|
|
requestId,
|
|
passphrase,
|
|
cancelled,
|
|
});
|
|
},
|
|
respondPassphraseSkip: async (requestId) => {
|
|
return ipcRenderer.invoke("netcatty:passphrase:respond", {
|
|
requestId,
|
|
passphrase: '',
|
|
skipped: true,
|
|
});
|
|
},
|
|
onPassphraseTimeout: (cb) => {
|
|
passphraseTimeoutListeners.add(cb);
|
|
return () => passphraseTimeoutListeners.delete(cb);
|
|
},
|
|
openSftp: async (options) => {
|
|
const result = await ipcRenderer.invoke("netcatty:sftp:open", options);
|
|
return result.sftpId;
|
|
},
|
|
listSftp: async (sftpId, path, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:list", { sftpId, path, encoding });
|
|
},
|
|
readSftp: async (sftpId, path, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:read", { sftpId, path, encoding });
|
|
},
|
|
readSftpBinary: async (sftpId, path, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:readBinary", { sftpId, path, encoding });
|
|
},
|
|
writeSftp: async (sftpId, path, content, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:write", { sftpId, path, content, encoding });
|
|
},
|
|
writeSftpBinary: async (sftpId, path, content, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:writeBinary", { sftpId, path, content, encoding });
|
|
},
|
|
closeSftp: async (sftpId) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:close", { sftpId });
|
|
},
|
|
mkdirSftp: async (sftpId, path, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:mkdir", { sftpId, path, encoding });
|
|
},
|
|
deleteSftp: async (sftpId, path, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:delete", { sftpId, path, encoding });
|
|
},
|
|
renameSftp: async (sftpId, oldPath, newPath, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:rename", { sftpId, oldPath, newPath, encoding });
|
|
},
|
|
statSftp: async (sftpId, path, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:stat", { sftpId, path, encoding });
|
|
},
|
|
chmodSftp: async (sftpId, path, mode, encoding) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:chmod", { sftpId, path, mode, encoding });
|
|
},
|
|
getSftpHomeDir: async (sftpId) => {
|
|
return ipcRenderer.invoke("netcatty:sftp:homeDir", { sftpId });
|
|
},
|
|
// Write binary with real-time progress callback
|
|
writeSftpBinaryWithProgress: async (sftpId, path, content, transferId, encoding, onProgress, onComplete, onError) => {
|
|
// Register callbacks
|
|
if (onProgress) uploadProgressListeners.set(transferId, onProgress);
|
|
if (onComplete) uploadCompleteListeners.set(transferId, onComplete);
|
|
if (onError) uploadErrorListeners.set(transferId, onError);
|
|
|
|
return ipcRenderer.invoke("netcatty:sftp:writeBinaryWithProgress", {
|
|
sftpId,
|
|
path,
|
|
content,
|
|
transferId,
|
|
encoding,
|
|
});
|
|
},
|
|
// Cancel an in-progress SFTP upload
|
|
cancelSftpUpload: async (transferId) => {
|
|
// Cleanup listeners
|
|
uploadProgressListeners.delete(transferId);
|
|
uploadCompleteListeners.delete(transferId);
|
|
uploadErrorListeners.delete(transferId);
|
|
return ipcRenderer.invoke("netcatty:sftp:cancelUpload", { transferId });
|
|
},
|
|
// Local filesystem operations
|
|
listLocalDir: async (path) => {
|
|
return ipcRenderer.invoke("netcatty:local:list", { path });
|
|
},
|
|
readLocalFile: async (path) => {
|
|
return ipcRenderer.invoke("netcatty:local:read", { path });
|
|
},
|
|
writeLocalFile: async (path, content) => {
|
|
return ipcRenderer.invoke("netcatty:local:write", { path, content });
|
|
},
|
|
deleteLocalFile: async (path) => {
|
|
return ipcRenderer.invoke("netcatty:local:delete", { path });
|
|
},
|
|
renameLocalFile: async (oldPath, newPath) => {
|
|
return ipcRenderer.invoke("netcatty:local:rename", { oldPath, newPath });
|
|
},
|
|
mkdirLocal: async (path) => {
|
|
return ipcRenderer.invoke("netcatty:local:mkdir", { path });
|
|
},
|
|
statLocal: async (path) => {
|
|
return ipcRenderer.invoke("netcatty:local:stat", { path });
|
|
},
|
|
getHomeDir: async () => {
|
|
return ipcRenderer.invoke("netcatty:local:homedir");
|
|
},
|
|
getSystemInfo: async () => {
|
|
return ipcRenderer.invoke("netcatty:system:info");
|
|
},
|
|
// Read system known_hosts file
|
|
readKnownHosts: async () => {
|
|
return ipcRenderer.invoke("netcatty:known-hosts:read");
|
|
},
|
|
setTheme: async (theme) => {
|
|
return ipcRenderer.invoke("netcatty:setTheme", theme);
|
|
},
|
|
setBackgroundColor: async (color) => {
|
|
return ipcRenderer.invoke("netcatty:setBackgroundColor", color);
|
|
},
|
|
setLanguage: async (language) => {
|
|
return ipcRenderer.invoke("netcatty:setLanguage", language);
|
|
},
|
|
onLanguageChanged: (cb) => {
|
|
languageChangeListeners.add(cb);
|
|
return () => languageChangeListeners.delete(cb);
|
|
},
|
|
// Streaming transfer with real progress
|
|
startStreamTransfer: async (options, onProgress, onComplete, onError) => {
|
|
const { transferId } = options;
|
|
// Register callbacks
|
|
if (onProgress) transferProgressListeners.set(transferId, onProgress);
|
|
if (onComplete) transferCompleteListeners.set(transferId, onComplete);
|
|
if (onError) transferErrorListeners.set(transferId, onError);
|
|
|
|
return ipcRenderer.invoke("netcatty:transfer:start", options);
|
|
},
|
|
cancelTransfer: async (transferId) => {
|
|
cleanupTransferListeners(transferId);
|
|
return ipcRenderer.invoke("netcatty:transfer:cancel", { transferId });
|
|
},
|
|
sameHostCopyDirectory: async (sftpId, sourcePath, targetPath, encoding, transferId) => {
|
|
return ipcRenderer.invoke("netcatty:transfer:same-host-copy-dir", { sftpId, sourcePath, targetPath, encoding, transferId });
|
|
},
|
|
// Compressed folder upload
|
|
startCompressedUpload: async (options, onProgress, onComplete, onError) => {
|
|
const { compressionId } = options;
|
|
// Register callbacks
|
|
if (onProgress) compressProgressListeners.set(compressionId, onProgress);
|
|
if (onComplete) compressCompleteListeners.set(compressionId, onComplete);
|
|
if (onError) compressErrorListeners.set(compressionId, onError);
|
|
|
|
return ipcRenderer.invoke("netcatty:compress:start", options);
|
|
},
|
|
cancelCompressedUpload: async (compressionId) => {
|
|
// Cleanup listeners
|
|
compressProgressListeners.delete(compressionId);
|
|
compressCompleteListeners.delete(compressionId);
|
|
compressErrorListeners.delete(compressionId);
|
|
return ipcRenderer.invoke("netcatty:compress:cancel", { compressionId });
|
|
},
|
|
checkCompressedUploadSupport: async (sftpId) => {
|
|
return ipcRenderer.invoke("netcatty:compress:checkSupport", { sftpId });
|
|
},
|
|
// Window controls for custom title bar
|
|
windowMinimize: () => ipcRenderer.invoke("netcatty:window:minimize"),
|
|
windowMaximize: () => ipcRenderer.invoke("netcatty:window:maximize"),
|
|
windowClose: () => ipcRenderer.invoke("netcatty:window:close"),
|
|
windowIsMaximized: () => ipcRenderer.invoke("netcatty:window:isMaximized"),
|
|
windowIsFullscreen: () => ipcRenderer.invoke("netcatty:window:isFullscreen"),
|
|
onWindowFullScreenChanged: (cb) => {
|
|
fullscreenChangeListeners.add(cb);
|
|
return () => fullscreenChangeListeners.delete(cb);
|
|
},
|
|
|
|
// Settings window
|
|
openSettingsWindow: () => ipcRenderer.invoke("netcatty:settings:open"),
|
|
closeSettingsWindow: () => ipcRenderer.invoke("netcatty:settings:close"),
|
|
|
|
// Cross-window settings sync
|
|
notifySettingsChanged: (payload) => ipcRenderer.send("netcatty:settings:changed", payload),
|
|
onSettingsChanged: (callback) => {
|
|
const handler = (_event, payload) => callback(payload);
|
|
ipcRenderer.on("netcatty:settings:changed", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:settings:changed", handler);
|
|
},
|
|
|
|
// Cloud sync session (in-memory only, shared across windows)
|
|
cloudSyncSetSessionPassword: (password) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:session:setPassword", password),
|
|
cloudSyncGetSessionPassword: () =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:session:getPassword"),
|
|
cloudSyncClearSessionPassword: () =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:session:clearPassword"),
|
|
|
|
// Cloud sync network operations (proxied via main process)
|
|
cloudSyncWebdavInitialize: (config) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:webdav:initialize", { config }),
|
|
cloudSyncWebdavUpload: (config, syncedFile) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:webdav:upload", { config, syncedFile }),
|
|
cloudSyncWebdavDownload: (config) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:webdav:download", { config }),
|
|
cloudSyncWebdavDelete: (config) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:webdav:delete", { config }),
|
|
|
|
cloudSyncS3Initialize: (config) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:s3:initialize", { config }),
|
|
cloudSyncS3Upload: (config, syncedFile) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:s3:upload", { config, syncedFile }),
|
|
cloudSyncS3Download: (config) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:s3:download", { config }),
|
|
cloudSyncS3Delete: (config) =>
|
|
ipcRenderer.invoke("netcatty:cloudSync:s3:delete", { config }),
|
|
|
|
// Open URL in default browser
|
|
openExternal: (url) => ipcRenderer.invoke("netcatty:openExternal", url),
|
|
|
|
// App info
|
|
getAppInfo: () => ipcRenderer.invoke("netcatty:app:getInfo"),
|
|
ptyGetChildProcesses: (sessionId) =>
|
|
ipcRenderer.invoke("netcatty:pty:childProcesses", sessionId),
|
|
confirmCloseBusy: (payload) =>
|
|
ipcRenderer.invoke("netcatty:dialog:confirmCloseBusy", payload),
|
|
getVaultBackupCapabilities: () =>
|
|
ipcRenderer.invoke("netcatty:vaultBackups:capabilities"),
|
|
createVaultBackup: (payload) =>
|
|
ipcRenderer.invoke("netcatty:vaultBackups:create", payload),
|
|
listVaultBackups: () =>
|
|
ipcRenderer.invoke("netcatty:vaultBackups:list"),
|
|
readVaultBackup: (payload) =>
|
|
ipcRenderer.invoke("netcatty:vaultBackups:read", payload),
|
|
trimVaultBackups: (payload) =>
|
|
ipcRenderer.invoke("netcatty:vaultBackups:trim", payload),
|
|
openVaultBackupDir: () =>
|
|
ipcRenderer.invoke("netcatty:vaultBackups:openDir"),
|
|
// Subscribe to cross-window "backups changed" events emitted by the
|
|
// main process whenever a create/trim actually mutated the on-disk
|
|
// set. Returns an unsubscribe function so React-style consumers can
|
|
// release the listener on unmount without leaking IPC handlers.
|
|
onVaultBackupsChanged: (handler) => {
|
|
if (typeof handler !== "function") return () => {};
|
|
const listener = () => {
|
|
try { handler(); } catch (error) {
|
|
console.warn("[preload] onVaultBackupsChanged handler threw:", error);
|
|
}
|
|
};
|
|
ipcRenderer.on("netcatty:vaultBackups:changed", listener);
|
|
return () => {
|
|
try { ipcRenderer.removeListener("netcatty:vaultBackups:changed", listener); }
|
|
catch { /* ignore */ }
|
|
};
|
|
},
|
|
|
|
// Tell main process the renderer has mounted/painted (used to avoid initial blank screen).
|
|
rendererReady: () => ipcRenderer.send("netcatty:renderer:ready"),
|
|
|
|
// Quit guard: main process asks whether any editor tabs have unsaved changes.
|
|
// Returns an unsubscribe function so React effects can clean up on unmount.
|
|
onCheckDirtyEditors: (listener) => {
|
|
const handler = () => listener();
|
|
ipcRenderer.on("app:query-dirty-editors", handler);
|
|
return () => ipcRenderer.removeListener("app:query-dirty-editors", handler);
|
|
},
|
|
// Renderer reports the dirty-check result back to the main process.
|
|
reportDirtyEditorsResult: (hasDirty) => ipcRenderer.send("app:dirty-editors-result", { hasDirty }),
|
|
|
|
// Port Forwarding API
|
|
startPortForward: async (options) => {
|
|
return ipcRenderer.invoke("netcatty:portforward:start", options);
|
|
},
|
|
stopPortForward: async (tunnelId) => {
|
|
return ipcRenderer.invoke("netcatty:portforward:stop", { tunnelId });
|
|
},
|
|
getPortForwardStatus: async (tunnelId) => {
|
|
return ipcRenderer.invoke("netcatty:portforward:status", { tunnelId });
|
|
},
|
|
listPortForwards: async () => {
|
|
return ipcRenderer.invoke("netcatty:portforward:list");
|
|
},
|
|
stopAllPortForwards: async () => {
|
|
return ipcRenderer.invoke("netcatty:portforward:stopAll");
|
|
},
|
|
stopPortForwardByRuleId: async (ruleId) => {
|
|
return ipcRenderer.invoke("netcatty:portforward:stopByRuleId", { ruleId });
|
|
},
|
|
onPortForwardStatus: (tunnelId, cb) => {
|
|
if (!portForwardStatusListeners.has(tunnelId)) {
|
|
portForwardStatusListeners.set(tunnelId, new Set());
|
|
}
|
|
portForwardStatusListeners.get(tunnelId).add(cb);
|
|
return () => {
|
|
portForwardStatusListeners.get(tunnelId)?.delete(cb);
|
|
if (portForwardStatusListeners.get(tunnelId)?.size === 0) {
|
|
portForwardStatusListeners.delete(tunnelId);
|
|
}
|
|
};
|
|
},
|
|
// Chain progress listener for jump host connections
|
|
onChainProgress: (cb) => {
|
|
const id = Date.now().toString() + Math.random().toString(16).slice(2);
|
|
chainProgressListeners.set(id, cb);
|
|
return () => {
|
|
chainProgressListeners.delete(id);
|
|
};
|
|
},
|
|
// SFTP connection progress listener (auth method logs)
|
|
onSftpConnectionProgress: (cb) => {
|
|
sftpConnectionProgressListeners.add(cb);
|
|
return () => {
|
|
sftpConnectionProgressListeners.delete(cb);
|
|
};
|
|
},
|
|
|
|
// OAuth callback server
|
|
startOAuthCallback: (expectedState) => ipcRenderer.invoke("oauth:startCallback", expectedState),
|
|
cancelOAuthCallback: () => ipcRenderer.invoke("oauth:cancelCallback"),
|
|
|
|
// GitHub Device Flow (proxied via main process to avoid CORS)
|
|
githubStartDeviceFlow: (options) => ipcRenderer.invoke("netcatty:github:deviceFlow:start", options),
|
|
githubPollDeviceFlowToken: (options) => ipcRenderer.invoke("netcatty:github:deviceFlow:poll", options),
|
|
|
|
// Google OAuth (proxied via main process to avoid CORS)
|
|
googleExchangeCodeForTokens: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:oauth:exchange", options),
|
|
googleRefreshAccessToken: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:oauth:refresh", options),
|
|
googleGetUserInfo: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:oauth:userinfo", options),
|
|
|
|
// Google Drive API (proxied via main process to avoid CORS/COEP issues in renderer)
|
|
googleDriveFindSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:drive:findSyncFile", options),
|
|
googleDriveCreateSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:drive:createSyncFile", options),
|
|
googleDriveUpdateSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:drive:updateSyncFile", options),
|
|
googleDriveDownloadSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:drive:downloadSyncFile", options),
|
|
googleDriveDeleteSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:google:drive:deleteSyncFile", options),
|
|
|
|
// OneDrive OAuth + Graph (proxied via main process to avoid CORS)
|
|
onedriveExchangeCodeForTokens: (options) =>
|
|
ipcRenderer.invoke("netcatty:onedrive:oauth:exchange", options),
|
|
onedriveRefreshAccessToken: (options) =>
|
|
ipcRenderer.invoke("netcatty:onedrive:oauth:refresh", options),
|
|
onedriveGetUserInfo: (options) =>
|
|
ipcRenderer.invoke("netcatty:onedrive:oauth:userinfo", options),
|
|
onedriveFindSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:onedrive:drive:findSyncFile", options),
|
|
onedriveUploadSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:onedrive:drive:uploadSyncFile", options),
|
|
onedriveDownloadSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:onedrive:drive:downloadSyncFile", options),
|
|
onedriveDeleteSyncFile: (options) =>
|
|
ipcRenderer.invoke("netcatty:onedrive:drive:deleteSyncFile", options),
|
|
|
|
// File opener helpers (for "Open With" feature)
|
|
selectApplication: () =>
|
|
ipcRenderer.invoke("netcatty:selectApplication"),
|
|
openWithApplication: (filePath, appPath) =>
|
|
ipcRenderer.invoke("netcatty:openWithApplication", { filePath, appPath }),
|
|
downloadSftpToTemp: (sftpId, remotePath, fileName, encoding) =>
|
|
ipcRenderer.invoke("netcatty:sftp:downloadToTemp", { sftpId, remotePath, fileName, encoding }),
|
|
downloadSftpToTempWithProgress: (sftpId, remotePath, fileName, encoding, transferId, onProgress, onComplete, onError, onCancelled) => {
|
|
if (onProgress) transferProgressListeners.set(transferId, onProgress);
|
|
if (onComplete) transferCompleteListeners.set(transferId, onComplete);
|
|
if (onError) transferErrorListeners.set(transferId, onError);
|
|
if (onCancelled) transferCancelledListeners.set(transferId, onCancelled);
|
|
return ipcRenderer
|
|
.invoke("netcatty:sftp:downloadToTempWithProgress", { sftpId, remotePath, fileName, encoding, transferId })
|
|
.catch((err) => {
|
|
cleanupTransferListeners(transferId);
|
|
throw err;
|
|
});
|
|
},
|
|
|
|
// Save dialog for file downloads
|
|
showSaveDialog: (defaultPath, filters) =>
|
|
ipcRenderer.invoke("netcatty:showSaveDialog", { defaultPath, filters }),
|
|
selectDirectory: (title, defaultPath) =>
|
|
ipcRenderer.invoke("netcatty:selectDirectory", { title, defaultPath }),
|
|
selectFile: (title, defaultPath, filters) =>
|
|
ipcRenderer.invoke("netcatty:selectFile", { title, defaultPath, filters }),
|
|
|
|
// File watcher for auto-sync feature
|
|
startFileWatch: (localPath, remotePath, sftpId, encoding) =>
|
|
ipcRenderer.invoke("netcatty:filewatch:start", { localPath, remotePath, sftpId, encoding }),
|
|
stopFileWatch: (watchId, cleanupTempFile = false) =>
|
|
ipcRenderer.invoke("netcatty:filewatch:stop", { watchId, cleanupTempFile }),
|
|
listFileWatches: () =>
|
|
ipcRenderer.invoke("netcatty:filewatch:list"),
|
|
registerTempFile: (sftpId, localPath) =>
|
|
ipcRenderer.invoke("netcatty:filewatch:registerTempFile", { sftpId, localPath }),
|
|
onFileWatchSynced: (cb) => {
|
|
fileWatchSyncedListeners.add(cb);
|
|
return () => fileWatchSyncedListeners.delete(cb);
|
|
},
|
|
onFileWatchError: (cb) => {
|
|
fileWatchErrorListeners.add(cb);
|
|
return () => fileWatchErrorListeners.delete(cb);
|
|
},
|
|
|
|
// Temp file cleanup
|
|
deleteTempFile: (filePath) =>
|
|
ipcRenderer.invoke("netcatty:deleteTempFile", { filePath }),
|
|
|
|
// Temp directory management
|
|
getTempDirInfo: () =>
|
|
ipcRenderer.invoke("netcatty:tempdir:getInfo"),
|
|
clearTempDir: () =>
|
|
ipcRenderer.invoke("netcatty:tempdir:clear"),
|
|
getTempDirPath: () =>
|
|
ipcRenderer.invoke("netcatty:tempdir:getPath"),
|
|
openTempDir: () =>
|
|
ipcRenderer.invoke("netcatty:tempdir:open"),
|
|
|
|
// Session Logs
|
|
exportSessionLog: (payload) =>
|
|
ipcRenderer.invoke("netcatty:sessionLogs:export", payload),
|
|
selectSessionLogsDir: () =>
|
|
ipcRenderer.invoke("netcatty:sessionLogs:selectDir"),
|
|
autoSaveSessionLog: (payload) =>
|
|
ipcRenderer.invoke("netcatty:sessionLogs:autoSave", payload),
|
|
openSessionLogsDir: (directory) =>
|
|
ipcRenderer.invoke("netcatty:sessionLogs:openDir", { directory }),
|
|
|
|
// Crash Logs
|
|
getCrashLogs: () =>
|
|
ipcRenderer.invoke("netcatty:crashLogs:list"),
|
|
readCrashLog: (fileName) =>
|
|
ipcRenderer.invoke("netcatty:crashLogs:read", { fileName }),
|
|
clearCrashLogs: () =>
|
|
ipcRenderer.invoke("netcatty:crashLogs:clear"),
|
|
openCrashLogsDir: () =>
|
|
ipcRenderer.invoke("netcatty:crashLogs:openDir"),
|
|
|
|
// Global Toggle Hotkey (Quake Mode)
|
|
registerGlobalHotkey: (hotkey) =>
|
|
ipcRenderer.invoke("netcatty:globalHotkey:register", { hotkey }),
|
|
unregisterGlobalHotkey: () =>
|
|
ipcRenderer.invoke("netcatty:globalHotkey:unregister"),
|
|
getGlobalHotkeyStatus: () =>
|
|
ipcRenderer.invoke("netcatty:globalHotkey:status"),
|
|
|
|
// System Tray / Close to Tray
|
|
setCloseToTray: (enabled) =>
|
|
ipcRenderer.invoke("netcatty:tray:setCloseToTray", { enabled }),
|
|
isCloseToTray: () =>
|
|
ipcRenderer.invoke("netcatty:tray:isCloseToTray"),
|
|
updateTrayMenuData: (data) =>
|
|
ipcRenderer.invoke("netcatty:tray:updateMenuData", data),
|
|
// Listen for tray menu actions
|
|
onTrayFocusSession: (callback) => {
|
|
const handler = (_event, sessionId) => callback(sessionId);
|
|
ipcRenderer.on("netcatty:tray:focusSession", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:tray:focusSession", handler);
|
|
},
|
|
onTrayTogglePortForward: (callback) => {
|
|
const handler = (_event, ruleId, start) => callback(ruleId, start);
|
|
ipcRenderer.on("netcatty:tray:togglePortForward", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:tray:togglePortForward", handler);
|
|
},
|
|
|
|
// Tray panel actions forwarded to main window
|
|
onTrayPanelJumpToSession: (callback) => {
|
|
const handler = (_event, sessionId) => callback(sessionId);
|
|
ipcRenderer.on("netcatty:trayPanel:jumpToSession", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:trayPanel:jumpToSession", handler);
|
|
},
|
|
onTrayPanelConnectToHost: (callback) => {
|
|
const handler = (_event, hostId) => callback(hostId);
|
|
ipcRenderer.on("netcatty:trayPanel:connectToHost", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:trayPanel:connectToHost", handler);
|
|
},
|
|
|
|
// Tray panel window
|
|
hideTrayPanel: () => ipcRenderer.invoke("netcatty:trayPanel:hide"),
|
|
openMainWindow: () => ipcRenderer.invoke("netcatty:trayPanel:openMainWindow"),
|
|
quitApp: () => ipcRenderer.invoke("netcatty:trayPanel:quitApp"),
|
|
jumpToSessionFromTrayPanel: (sessionId) =>
|
|
ipcRenderer.invoke("netcatty:trayPanel:jumpToSession", sessionId),
|
|
connectToHostFromTrayPanel: (hostId) =>
|
|
ipcRenderer.invoke("netcatty:trayPanel:connectToHost", hostId),
|
|
onTrayPanelCloseRequest: (callback) => {
|
|
const handler = () => callback();
|
|
ipcRenderer.on("netcatty:trayPanel:closeRequest", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:trayPanel:closeRequest", handler);
|
|
},
|
|
|
|
onTrayPanelRefresh: (callback) => {
|
|
const handler = () => callback();
|
|
ipcRenderer.on("netcatty:trayPanel:refresh", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:trayPanel:refresh", handler);
|
|
},
|
|
|
|
onTrayPanelMenuData: (callback) => {
|
|
// Replay buffered data so late subscribers (e.g. after React lazy-mount) don't miss
|
|
// the initial payload that was sent before the useEffect listener was registered.
|
|
if (_lastTrayMenuData) {
|
|
queueMicrotask(() => callback(_lastTrayMenuData));
|
|
}
|
|
const handler = (_event, data) => {
|
|
_lastTrayMenuData = data;
|
|
callback(data);
|
|
};
|
|
ipcRenderer.on("netcatty:trayPanel:setMenuData", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:trayPanel:setMenuData", handler);
|
|
},
|
|
|
|
// Get file path from File object (for drag-and-drop)
|
|
getPathForFile: (file) => {
|
|
try {
|
|
return webUtils.getPathForFile(file);
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
},
|
|
|
|
// Clipboard fallback helpers
|
|
readClipboardText: async () => {
|
|
return ipcRenderer.invoke("netcatty:clipboard:readText");
|
|
},
|
|
|
|
// Credential encryption (field-level safeStorage)
|
|
credentialsAvailable: () => ipcRenderer.invoke("netcatty:credentials:available"),
|
|
credentialsEncrypt: (plaintext) => ipcRenderer.invoke("netcatty:credentials:encrypt", plaintext),
|
|
credentialsDecrypt: (value) => ipcRenderer.invoke("netcatty:credentials:decrypt", value),
|
|
|
|
// Auto-update
|
|
checkForUpdate: () => ipcRenderer.invoke("netcatty:update:check"),
|
|
downloadUpdate: () => ipcRenderer.invoke("netcatty:update:download"),
|
|
installUpdate: () => ipcRenderer.invoke("netcatty:update:install"),
|
|
getUpdateStatus: () => ipcRenderer.invoke("netcatty:update:getStatus"),
|
|
setAutoUpdate: (enabled) => ipcRenderer.invoke("netcatty:update:setAutoUpdate", { enabled }),
|
|
getAutoUpdate: () => ipcRenderer.invoke("netcatty:update:getAutoUpdate"),
|
|
onUpdateAvailable: (cb) => {
|
|
updateAvailableListeners.add(cb);
|
|
return () => updateAvailableListeners.delete(cb);
|
|
},
|
|
onUpdateNotAvailable: (cb) => {
|
|
updateNotAvailableListeners.add(cb);
|
|
return () => updateNotAvailableListeners.delete(cb);
|
|
},
|
|
onUpdateDownloadProgress: (cb) => {
|
|
updateDownloadProgressListeners.add(cb);
|
|
return () => updateDownloadProgressListeners.delete(cb);
|
|
},
|
|
onUpdateDownloaded: (cb) => {
|
|
updateDownloadedListeners.add(cb);
|
|
return () => updateDownloadedListeners.delete(cb);
|
|
},
|
|
onUpdateError: (cb) => {
|
|
updateErrorListeners.add(cb);
|
|
return () => updateErrorListeners.delete(cb);
|
|
},
|
|
|
|
// ── AI Bridge ──
|
|
aiSyncProviders: async (providers) => {
|
|
return ipcRenderer.invoke("netcatty:ai:sync-providers", { providers });
|
|
},
|
|
aiSyncWebSearch: async (apiHost, apiKey) => {
|
|
return ipcRenderer.invoke("netcatty:ai:sync-web-search", { apiHost, apiKey });
|
|
},
|
|
aiChatStream: async (requestId, url, headers, body, providerId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:chat:stream", { requestId, url, headers, body, providerId });
|
|
},
|
|
aiChatCancel: async (requestId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:chat:cancel", { requestId });
|
|
},
|
|
aiFetch: async (url, method, headers, body, providerId, skipHostCheck, followRedirects, skipTLSVerify) => {
|
|
return ipcRenderer.invoke("netcatty:ai:fetch", { url, method, headers, body, providerId, skipHostCheck, followRedirects, skipTLSVerify });
|
|
},
|
|
aiAllowlistAddHost: async (baseURL) => {
|
|
return ipcRenderer.invoke("netcatty:ai:allowlist:add-host", { baseURL });
|
|
},
|
|
aiExec: async (sessionId, command, chatSessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:exec", { sessionId, command, chatSessionId });
|
|
},
|
|
aiCattyCancelExec: async (chatSessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:catty:cancel", { chatSessionId });
|
|
},
|
|
aiDiscoverAgents: async () => {
|
|
return ipcRenderer.invoke("netcatty:ai:agents:discover");
|
|
},
|
|
aiResolveCli: async (params) => {
|
|
return ipcRenderer.invoke("netcatty:ai:resolve-cli", params);
|
|
},
|
|
aiCodexGetIntegration: async (options) => {
|
|
return ipcRenderer.invoke("netcatty:ai:codex:get-integration", options);
|
|
},
|
|
aiCodexStartLogin: async () => {
|
|
return ipcRenderer.invoke("netcatty:ai:codex:start-login");
|
|
},
|
|
aiCodexGetLoginSession: async (sessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:codex:get-login-session", { sessionId });
|
|
},
|
|
aiCodexCancelLogin: async (sessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:codex:cancel-login", { sessionId });
|
|
},
|
|
aiCodexLogout: async () => {
|
|
return ipcRenderer.invoke("netcatty:ai:codex:logout");
|
|
},
|
|
aiSpawnAgent: async (agentId, command, args, env, options) => {
|
|
return ipcRenderer.invoke("netcatty:ai:agent:spawn", { agentId, command, args, env, closeStdin: options?.closeStdin });
|
|
},
|
|
aiWriteToAgent: async (agentId, data) => {
|
|
return ipcRenderer.invoke("netcatty:ai:agent:write", { agentId, data });
|
|
},
|
|
aiCloseAgentStdin: async (agentId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:agent:close-stdin", { agentId });
|
|
},
|
|
aiKillAgent: async (agentId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:agent:kill", { agentId });
|
|
},
|
|
// MCP Server session metadata
|
|
aiMcpUpdateSessions: async (sessions, chatSessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:mcp:update-sessions", { sessions, chatSessionId });
|
|
},
|
|
aiMcpSetCommandBlocklist: async (blocklist) => {
|
|
return ipcRenderer.invoke("netcatty:ai:mcp:set-command-blocklist", { blocklist });
|
|
},
|
|
aiMcpSetCommandTimeout: async (timeout) => {
|
|
return ipcRenderer.invoke("netcatty:ai:mcp:set-command-timeout", { timeout });
|
|
},
|
|
aiMcpSetMaxIterations: async (maxIterations) => {
|
|
return ipcRenderer.invoke("netcatty:ai:mcp:set-max-iterations", { maxIterations });
|
|
},
|
|
aiMcpSetPermissionMode: async (mode) => {
|
|
return ipcRenderer.invoke("netcatty:ai:mcp:set-permission-mode", { mode });
|
|
},
|
|
aiMcpSetToolIntegrationMode: async (mode) => {
|
|
return ipcRenderer.invoke("netcatty:ai:mcp:set-tool-integration-mode", { mode });
|
|
},
|
|
aiUserSkillsGetStatus: async () => {
|
|
return ipcRenderer.invoke("netcatty:ai:user-skills:status");
|
|
},
|
|
aiUserSkillsOpenFolder: async () => {
|
|
return ipcRenderer.invoke("netcatty:ai:user-skills:open");
|
|
},
|
|
aiUserSkillsBuildContext: async (prompt, selectedSkillSlugs) => {
|
|
return ipcRenderer.invoke("netcatty:ai:user-skills:build-context", { prompt, selectedSkillSlugs });
|
|
},
|
|
// MCP approval gate: renderer receives approval requests from main process
|
|
onMcpApprovalRequest: (cb) => {
|
|
const handler = (_event, payload) => cb(payload);
|
|
ipcRenderer.on("netcatty:ai:mcp:approval-request", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:mcp:approval-request", handler);
|
|
},
|
|
respondMcpApproval: async (approvalId, approved) => {
|
|
return ipcRenderer.invoke("netcatty:ai:mcp:approval-response", { approvalId, approved });
|
|
},
|
|
// MCP approval cleared: main process timed out or cancelled an approval
|
|
onMcpApprovalCleared: (cb) => {
|
|
const handler = (_event, payload) => cb(payload);
|
|
ipcRenderer.on("netcatty:ai:mcp:approval-cleared", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:mcp:approval-cleared", handler);
|
|
},
|
|
// ACP streaming
|
|
aiAcpStream: async (requestId, chatSessionId, acpCommand, acpArgs, prompt, cwd, providerId, model, existingSessionId, historyMessages, images, toolIntegrationMode, defaultTargetSession, userSkillsContext) => {
|
|
return ipcRenderer.invoke("netcatty:ai:acp:stream", { requestId, chatSessionId, acpCommand, acpArgs, prompt, cwd, providerId, model, existingSessionId, historyMessages, images, toolIntegrationMode, defaultTargetSession, userSkillsContext });
|
|
},
|
|
aiAcpListModels: async (acpCommand, acpArgs, cwd, providerId, chatSessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:acp:list-models", { acpCommand, acpArgs, cwd, providerId, chatSessionId });
|
|
},
|
|
aiAcpCancel: async (requestId, chatSessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:acp:cancel", { requestId, chatSessionId });
|
|
},
|
|
aiAcpCleanup: async (chatSessionId) => {
|
|
return ipcRenderer.invoke("netcatty:ai:acp:cleanup", { chatSessionId });
|
|
},
|
|
onAiAcpEvent: (requestId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.requestId === requestId) cb(payload.event);
|
|
};
|
|
ipcRenderer.on("netcatty:ai:acp:event", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:acp:event", handler);
|
|
},
|
|
onAiAcpDone: (requestId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.requestId === requestId) cb();
|
|
};
|
|
ipcRenderer.on("netcatty:ai:acp:done", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:acp:done", handler);
|
|
},
|
|
onAiAcpError: (requestId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.requestId === requestId) cb(payload.error);
|
|
};
|
|
ipcRenderer.on("netcatty:ai:acp:error", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:acp:error", handler);
|
|
},
|
|
onAiStreamData: (requestId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.requestId === requestId) cb(payload.data);
|
|
};
|
|
ipcRenderer.on("netcatty:ai:stream:data", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:stream:data", handler);
|
|
},
|
|
onAiStreamEnd: (requestId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.requestId === requestId) cb();
|
|
};
|
|
ipcRenderer.on("netcatty:ai:stream:end", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:stream:end", handler);
|
|
},
|
|
onAiStreamError: (requestId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.requestId === requestId) cb(payload.error);
|
|
};
|
|
ipcRenderer.on("netcatty:ai:stream:error", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:stream:error", handler);
|
|
},
|
|
onAiAgentStdout: (agentId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.agentId === agentId) cb(payload.data);
|
|
};
|
|
ipcRenderer.on("netcatty:ai:agent:stdout", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:agent:stdout", handler);
|
|
},
|
|
onAiAgentStderr: (agentId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.agentId === agentId) cb(payload.data);
|
|
};
|
|
ipcRenderer.on("netcatty:ai:agent:stderr", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:agent:stderr", handler);
|
|
},
|
|
onAiAgentExit: (agentId, cb) => {
|
|
const handler = (_event, payload) => {
|
|
if (payload.agentId === agentId) cb(payload.code);
|
|
};
|
|
ipcRenderer.on("netcatty:ai:agent:exit", handler);
|
|
return () => ipcRenderer.removeListener("netcatty:ai:agent:exit", handler);
|
|
},
|
|
};
|
|
|
|
// Fig autocomplete spec loading via main process
|
|
const figSpecApi = {
|
|
listFigSpecs: () => ipcRenderer.invoke("netcatty:figspec:list"),
|
|
loadFigSpec: (commandName) => ipcRenderer.invoke("netcatty:figspec:load", commandName),
|
|
listAutocompleteRemoteDir: (sessionId, dirPath, foldersOnly, filterPrefix, limit) => ipcRenderer.invoke("netcatty:ssh:listdir", {
|
|
sessionId,
|
|
path: dirPath,
|
|
foldersOnly,
|
|
filterPrefix,
|
|
limit,
|
|
}),
|
|
listAutocompleteLocalDir: (dirPath, foldersOnly, filterPrefix, limit) => ipcRenderer.invoke("netcatty:local:listdir", {
|
|
path: dirPath,
|
|
foldersOnly,
|
|
filterPrefix,
|
|
limit,
|
|
}),
|
|
};
|
|
|
|
// Merge with existing netcatty (if any) to avoid stale objects on hot reload
|
|
const existing = (typeof window !== "undefined" && window.netcatty) ? window.netcatty : {};
|
|
|
|
function getAllowedRendererOrigins() {
|
|
const origins = new Set(["app://netcatty"]);
|
|
const devServerUrl = process.env.VITE_DEV_SERVER_URL;
|
|
if (typeof devServerUrl === "string" && devServerUrl.length > 0) {
|
|
try {
|
|
const u = new URL(devServerUrl);
|
|
origins.add(u.origin);
|
|
// Vite often binds to 0.0.0.0, but Chromium navigates via localhost.
|
|
if (
|
|
u.hostname === "0.0.0.0" ||
|
|
u.hostname === "127.0.0.1" ||
|
|
u.hostname === "::1" ||
|
|
u.hostname === "[::1]" ||
|
|
u.hostname === "::" ||
|
|
u.hostname === "[::]"
|
|
) {
|
|
u.hostname = "localhost";
|
|
origins.add(u.origin);
|
|
}
|
|
} catch {
|
|
// ignore invalid dev URL
|
|
}
|
|
}
|
|
return origins;
|
|
}
|
|
|
|
function isTrustedRendererLocation(allowedOrigins) {
|
|
try {
|
|
const origin = window?.location?.origin;
|
|
return typeof origin === "string" && allowedOrigins.has(origin);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
const allowedOrigins = getAllowedRendererOrigins();
|
|
if (isTrustedRendererLocation(allowedOrigins)) {
|
|
contextBridge.exposeInMainWorld("netcatty", { ...existing, ...api, ...figSpecApi });
|
|
} else {
|
|
// If a window navigates to an untrusted origin, do NOT expose the bridge.
|
|
try {
|
|
console.warn("[Preload] Refusing to expose netcatty bridge to untrusted origin:", window?.location?.origin);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}
|