Files
Netcatty/domain/models/portForwarding.ts
T
8ee55963d8 feat(portforward): make main process authoritative for runtime state (#2288) (#2819)
* feat(portforward): make main process authoritative for runtime state

Phase 1 of #2288: add snapshot/runtime event protocol with epoch+revision,
stop persisting active/connecting/error into localStorage, migrate legacy
stored phases on read, and project unknown when snapshots are unavailable.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(portforward): access runtime bridge via netcattyBridge

Satisfy the no-restricted-properties lint rule for window.netcatty.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(portforward): honor snapshot authority and prune on resync

Default runtime projection to unknown until a successful snapshot,
reconcile (not sync-only) on epoch/revision gaps, serialize runtime
event handling, clear worker runtime subscribers on window destroy,
and align tray unknown UX with RuleCard.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
2026-08-08 02:50:41 +00:00

40 lines
1.1 KiB
TypeScript

// Port Forwarding Types
export type PortForwardingType = 'local' | 'remote' | 'dynamic';
/**
* Display / projection status for a port-forwarding rule.
* `unknown` means the authoritative main-process snapshot could not be read;
* it must never be persisted to localStorage.
*/
export type PortForwardingStatus =
| 'inactive'
| 'connecting'
| 'active'
| 'error'
| 'unknown';
export interface PortForwardingRule {
id: string;
label: string;
order?: number;
type: PortForwardingType;
// Common fields
localPort: number;
bindAddress: string; // e.g., '127.0.0.1', '0.0.0.0'
// For local and remote forwarding
remoteHost?: string;
remotePort?: number;
// Host to tunnel through
hostId?: string;
// Auto-start: if true, this rule will automatically start when the app launches
autoStart?: boolean;
/**
* Runtime projection for the UI. Authoritative phase lives in the Electron
* main-process registry; this field is rebuilt from snapshots / events and
* must not be treated as durable configuration.
*/
status: PortForwardingStatus;
error?: string;
createdAt: number;
lastUsedAt?: number;
}