Compare commits

...

112 Commits

Author SHA1 Message Date
陈大猫
cb5333e336 Merge pull request #320 from binaricat/codex/sftpmodal-parent-entry
Some checks failed
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
Fix SFTP modal parent navigation in empty directories
2026-03-12 19:00:41 +08:00
bincxz
d3153148c8 Fix SFTP modal empty directory parent navigation 2026-03-12 18:57:19 +08:00
陈大猫
899cb109b4 Merge pull request #319 from binaricat/codex/fix-sftp-drop-target-race
fix: keep terminal drag-drop uploads on the resolved SFTP path
2026-03-12 18:47:15 +08:00
bincxz
d031bf355d fix: use resolved sftp path for initial auto upload 2026-03-12 18:40:24 +08:00
bincxz
489b7711f5 fix: pin terminal drop uploads to the resolved sftp path 2026-03-12 18:07:10 +08:00
陈大猫
65877fd912 feat(sync): include snippetPackages in cloud sync payload (#318)
* feat(sync): include snippetPackages in cloud sync payload (#315)

Snippet packages (the grouping tree for code snippets) were not included
in the cloud sync payload, causing them to be lost when syncing across
devices. This adds snippetPackages as an optional field following the
same backward-compatible pattern used by knownHosts and
portForwardingRules: old payloads that lack the field leave local
packages untouched.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: make snippetPackages optional in SyncableVaultData for consistency

Aligns with the pattern used by knownHosts — optional in both
SyncableVaultData and SyncPayload so that legacy data without the field
is handled gracefully. Also updates the SyncPayloadImporters docstring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 17:02:52 +08:00
陈大猫
117ec260b6 fix: address issue #294 follow-up regressions (#316)
* fix: address issue 294 regressions

* fix: scope sftp hidden files toggle per pane

* fix: restore terminal auto-follow behaviors

* fix: keep keypress auto-scroll scoped to keypress

* feat: add hidden files toggle to sftp modal

* fix: tighten sftp and terminal review findings
2026-03-12 16:19:22 +08:00
陈大猫
c76ff7ac9a Merge pull request #317 from yuzifu/feat-support-almalinux
feat: support almalinux distro
2026-03-12 15:37:21 +08:00
yuzifu
17da21b1cd feat: support almalinux distro 2026-03-12 14:49:54 +08:00
陈大猫
733e36a728 Merge pull request #314 from penguinway/feat/auto-update-unified
Some checks failed
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
LGTM! 经过多轮 review 和修复,代码质量已经很好。

核心改进:
- 统一 useUpdateCheck 作为跨窗口的单一更新状态源
- 多窗口 IPC 广播(broadcastToAllWindows)
- 启动检查竞态缓解(8s delay + onUpdateAvailable/NotAvailable 取消)
- dismissed version 在 renderer 侧完整支持
- electron-updater fallback(GitHub API 不可用时)
- _isChecking 标记防止并发 checkForUpdates 调用

感谢合并!
2026-03-11 20:34:20 +08:00
bincxz
35174246cc fix(update): handle checking sentinel, restore dismiss for unsupported platforms
- Handle { checking: true } response from bridge.checkForUpdate()
  separately instead of treating it as "no update" — an in-flight
  check will resolve via IPC events
- Restore dismissUpdate() in "View in Settings" toast onClick so
  unsupported-platform users can suppress the notification; on
  supported platforms the Settings window picks up download state
  via IPC events independently

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 20:24:54 +08:00
bincxz
ab13670eaa fix(update): sync dismissed ref for late windows, clear error on fallback success
- Set dismissedAutoDownloadRef when hydration skips a dismissed version
  so subsequent IPC events (progress/downloaded) are also suppressed
- When GitHub API fails but electron-updater fallback finds no update,
  clear manualCheckStatus from 'error' to 'up-to-date' instead of
  leaving Settings stuck in error state

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 20:18:50 +08:00
bincxz
4f3e39e378 fix(update): fall back to electron-updater when GitHub API fails
When checkNow's GitHub API call fails (blocked/rate-limited), still
trigger electron-updater's checkForUpdate as a fallback. This restores
the update path for environments where api.github.com is unreachable
but the updater feed is still accessible.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 20:12:18 +08:00
bincxz
2281d1df68 fix(update): don't throttle GitHub fallback from updater not-available
Remove STORAGE_KEY_UPDATE_LAST_CHECK write from onUpdateNotAvailable
handler — it would prevent the GitHub API fallback from running on app
restart, hiding releases that exist on GitHub but aren't yet in the
electron-updater feed. Let performCheck write the timestamp instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 20:05:47 +08:00
bincxz
e570185e2f fix(update): don't dismiss when navigating to Settings from toast
- Remove dismissUpdate() from "View in Settings" toast onClick — writing
  to STORAGE_KEY_UPDATE_DISMISSED_VERSION would cause the Settings window
  hydration to skip download state, making it appear idle
- Remove unused dismissUpdate import from App.tsx

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:58:33 +08:00
bincxz
12884165b5 fix(update): preserve GitHub fallback on not-available, recheck on reschedule
- Don't cancel startup GitHub API fallback when electron-updater says
  not-available — the GitHub release may exist before updater feed
  assets are published, and the fallback provides manual download link
- Rescheduled fallback now re-queries getUpdateStatus to avoid duplicate
  notifications on very slow networks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:52:04 +08:00
bincxz
11f82defc3 fix(update): use dismissed ref instead of idle check, preserve GitHub fallback
- Replace autoDownloadStatus==='idle' guard in progress/downloaded/error
  callbacks with a dedicated dismissedAutoDownloadRef to distinguish
  "dismissed version" from "not hydrated yet" in late-opening windows
- Don't clear hasUpdate on update-not-available — GitHub release may
  exist even when electron-updater feed says no compatible update,
  preserving the manual download fallback path
- Reset dismissedAutoDownloadRef on manual retry via checkNow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:45:24 +08:00
bincxz
ac9175b770 fix(update): reschedule fallback on in-flight check, clear stale state
- When the startup fallback sees the main process check still in flight,
  reschedule after 5s instead of permanently skipping — handles the case
  where the auto-check fails silently (check-phase errors not broadcast)
- onUpdateNotAvailable: clear hasUpdate and manualCheckStatus to remove
  stale "update available" state from earlier GitHub API checks, since
  the updater feed is authoritative on supported platforms

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:38:02 +08:00
bincxz
71c6f68934 fix(update): honor dismissed version in manual check, clear isChecking safely
- checkNow: check dismissed version before marking status as 'available'
  to prevent re-downloading a release the user explicitly skipped
- startAutoCheck: verify updater exists before setting _isChecking flag
  to avoid permanent stuck state when electron-updater fails to load
- Clear _isChecking in all catch paths to prevent stuck state

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:32:57 +08:00
bincxz
01bee794ee fix(update): track in-flight check state to prevent concurrent races
- Add _isChecking flag in autoUpdateBridge to track whether
  checkForUpdates is in flight; return sentinel when manual check
  arrives during an active auto-check instead of starting a concurrent
  call that electron-updater would reject
- Include isChecking in getUpdateStatus snapshot so the renderer can
  query it before starting the GitHub API fallback
- Startup fallback now checks getUpdateStatus().isChecking to skip
  when electron-updater is still checking on slow networks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:23:53 +08:00
bincxz
29dc01306d fix(update): make auto-check cancellable, persist no-update check time
- Store startAutoCheck timer ID so it can be cancelled; cancel it when
  the renderer triggers a manual checkForUpdate to avoid concurrent
  electron-updater calls that produce false errors
- Record lastCheckedAt and STORAGE_KEY_UPDATE_LAST_CHECK when
  update-not-available fires so the throttle works on the common
  no-update path and "Last checked" UI shows correctly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:17:53 +08:00
bincxz
0dcfd1489b fix(update): eliminate redundant startup check, serialize manual checks
- Broadcast 'update-not-available' from electron-updater to renderer so
  the startup GitHub API check is cancelled when no update exists
- Cancel pending startup timeout in checkNow() to prevent racing with
  electron-updater's startAutoCheck (concurrent calls cause false errors)
- Add onUpdateNotAvailable bridge event (preload + global.d.ts types)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:09:48 +08:00
bincxz
72f61141c4 fix(update): respect dismissed version in hydration, don't cache failed checks
- getUpdateStatus hydration: skip restoring download state for dismissed
  versions so late-opening windows don't show dismissed release UI
- performCheck: only advance lastCheck timestamp and cache release data
  on successful checks — failed checks no longer suppress re-checks for
  an hour while leaving stale cached release visible

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:03:15 +08:00
bincxz
37150ea379 fix(update): suppress download UI for dismissed versions, cancel racy startup check
- onUpdateAvailable: skip autoDownloadStatus→'downloading' transition when
  version is dismissed, preventing download progress/ready toasts
- onUpdateAvailable: cancel pending startup GitHub API check timeout to
  eliminate race where electron-updater is still checking at 8s
- onUpdateDownloadProgress/Downloaded/Error: suppress state transitions
  when autoDownloadStatus is 'idle' (dismissed version background download)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:55:51 +08:00
bincxz
5706af3f33 fix(update): don't falsely report up-to-date, fix stale hydration
- Return idle instead of up-to-date for dev/invalid builds in
  checkNow to avoid false positive status
- Replace stale cached release in getUpdateStatus hydration when
  the snapshot reports a different version

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:45:18 +08:00
bincxz
6871c82ab8 fix(update): semantic version compare, restore dismiss, show fallback on error
- Use semantic version comparison for cached release hydration to
  avoid false positives when running a newer build than latest release
- Restore dismissUpdate() in startup toast so unsupported-platform
  users can silence repeated notifications
- Remove dismissed-version check from ready-to-install toast since
  dismissing availability should not block the install prompt
- Show manual download link in Settings on check errors too

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:38:10 +08:00
bincxz
b90ff692eb fix(update): hydrate cached release for late windows, fix dismiss flow
- Persist latestRelease to localStorage so windows opened after the
  initial check can hydrate release info without re-fetching
- Remove dismissUpdate() from "View in Settings" toast click — the
  dismissed version key was preventing the later install-ready toast
- Hydrate cached release data when startup check is throttled so
  Settings windows show the already-found update

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:31:23 +08:00
bincxz
ce71725dba fix(update): handle unsupported platforms, remove auto-check, update badge
- Don't treat unsupported auto-update platforms as download errors;
  keep autoDownloadStatus at idle so manual download link shows
- Remove auto-check on SettingsApplicationTab mount to avoid
  implicitly triggering downloads when opening Settings
- Update Application tab badge to reflect download/ready state
  instead of always showing "Download Now"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:25:32 +08:00
bincxz
fb5c4aaa58 fix(update): update latestRelease on version mismatch, surface check failures
- Replace stale latestRelease when electron-updater reports a different
  version than the cached GitHub API result
- Surface checkForUpdate() failures by setting autoDownloadStatus to
  error instead of silently dropping them

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:15:34 +08:00
bincxz
45c059ae53 fix(update): suppress install toast for dismissed releases, reset stale status
- Check dismissed version before showing ready-to-install toast so
  users who skipped a release are not re-prompted after restart
- Reset _lastStatus on update-not-available so late-opening windows
  don't hydrate stale error/ready state from a previous check cycle

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:09:23 +08:00
bincxz
1d67eb40c4 fix(update): remove stale autoDownloadStatus check from manual update handler
The autoDownloadStatus read from updateState was captured at render
time, so after checkNow() resolves it still shows 'idle' even when
electron-updater has already started downloading. Remove the
openReleasePage() call entirely — checkNow() already triggers
electron-updater on supported platforms, and SettingsSystemTab shows
a manual download link on unsupported platforms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 18:02:12 +08:00
bincxz
c6e3989a1b fix(auto-update): restrict error broadcasts to download phase only
- Remove hasUpdate gate from ready-to-install toast so dismissing
  availability notification doesn't prevent restart prompt
- Only open releases page on platforms without auto-download
- Increase startup check delay to 8s to let electron-updater fire first

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 17:57:35 +08:00
bincxz
ace081414f fix(review): skip redundant startup check, honor dismissed version in toasts
- Skip renderer's GitHub API startup check if electron-updater's
  auto-download has already started, preventing duplicate toast
  notifications for the same release
- Set hasUpdate in onUpdateAvailable IPC handler, checking dismissed
  version so that dismissed releases don't trigger the persistent
  "restart now" toast after auto-download completes
- Guard "ready to install" toast with hasUpdate check

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 17:49:25 +08:00
bincxz
049a609bca fix(review): fix retry path, consolidate useUpdateCheck, show startup updates
- Fix autoDownloadStatusRef stale read during checkNow retry: eagerly
  sync the ref when resetting error->idle so checkForUpdate() fires
- Refactor SettingsApplicationTab to accept update props instead of
  creating its own useUpdateCheck instance, preventing duplicate checks
  and inconsistent state between Application and System tabs
- Show startup-detected updates (hasUpdate) in System tab, not only
  manualCheckStatus=available, so Linux/unsupported platforms see the
  update and manual download button

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 17:43:34 +08:00
bincxz
44409e6d32 fix(review): hydrate update status for late-opening windows, fix toast race
- Add getUpdateStatus IPC handler so windows opened after download started
  can immediately reflect the current state instead of showing stale 'idle'
- Track _lastStatus in main process across all updater events
- Hydrate autoDownloadStatus on useUpdateCheck mount via getUpdateStatus()
- Fix toast race: use ref to track previous autoDownloadStatus so ready/error
  toasts only fire on actual status transitions, not when unrelated callback
  references change

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 17:37:15 +08:00
bincxz
5246489ef9 fix(review): remove stale getSenderWindow reference from JSDoc
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 17:26:14 +08:00
bincxz
83d0d917ad fix(review): guard formatLastChecked against negative timestamps
Handle clock skew (timestamp in the future) by treating negative
diff as "just now" instead of displaying negative time values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 17:25:43 +08:00
bincxz
73557d0af1 fix(review): remove dead code, fix gitignore pattern, correct changelog
- Remove unused getSenderWindow() from autoUpdateBridge (replaced by broadcastToAllWindows)
- Fix .gitignore: /CLAUDE.md instead of CLAUDE.md to only match root
- Merge duplicate [Unreleased] sections in CHANGELOG.md
- Correct checkNow description: uses GitHub API, then triggers electron-updater async

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 17:23:47 +08:00
penguinway
aa67455c8c fix(auto-update): restrict error broadcasts to download phase only
Add _isDownloading flag to track whether a download is in progress.
Set true on update-available (autoDownload=true starts download immediately),
reset on update-downloaded or error.

In the error handler, only broadcast netcatty:update:error when _isDownloading
is true — check-phase errors (e.g. startup network failures) are logged to
console only and do not set autoDownloadStatus in the renderer, preventing
false 'download failed' states when no download was ever attempted.
2026-03-11 17:09:31 +08:00
penguinway
c7d2482996 fix(update): classify checkNow error when result.error is set
performCheck returns a non-null UpdateCheckResult with error populated
on GitHub API/network failures. Extend the status derivation to treat
result.error as an error state instead of falling through to up-to-date.
2026-03-11 17:08:31 +08:00
penguinway
d2391f5472 fix(update): restore checkNow return type and add error state retry
P1: change checkNow return type from Promise<null> to Promise<UpdateCheckResult | null>
and return actual result so callers can read hasUpdate/latestRelease.

P2: reset autoDownloadStatus from 'error' to 'idle' when user triggers manual
check, enabling a retry path; also show Check for Updates button in error state.
2026-03-11 16:58:21 +08:00
penguinway
9be84c71f5 feat(auto-update): improve UX — auto-reset badge, trigger download, show last checked time
- Fix 1: when manual check finds update and electron-updater hasn't started
  downloading yet (autoDownloadStatus=idle), fire-and-forget checkForUpdate()
  to kick off the auto-download pipeline without blocking the UI

- Fix 2: manualCheckStatus='up-to-date' now auto-resets to 'idle' after 5s
  so the badge doesn't stay stale until the next check; any new check cancels
  the pending timer first

- Fix 3: SettingsSystemTab shows "last checked: X min ago" below the update
  section using lastCheckedAt from updateState; new i18n keys added for both
  zh-CN and en locales (lastCheckedJustNow, lastCheckedMinutesAgo,
  lastCheckedHoursAgo, lastCheckedPrefix)

Internal: add autoDownloadStatusRef and manualCheckResetTimeoutRef to
useUpdateCheck for reliable cross-closure state access and timer lifecycle.
2026-03-11 16:08:32 +08:00
penguinway
effb98b91a chore: gitignore local dev files (.serena/, VS build scripts, Directory.Build.*) 2026-03-11 16:06:05 +08:00
陈大猫
77fd7a42a8 fix(sftp): drag-upload goes to wrong directory after navigation (#311)
Some checks failed
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
* fix(sftp): update currentPath immediately on navigation to prevent stale upload target

When navigating directories without a cache hit, currentPath was only
updated after the async file listing completed. If a drag-and-drop upload
occurred during or shortly after this window, getActivePane would return
the old currentPath, causing files to upload to the previous directory.

Now currentPath is updated immediately when loading begins, ensuring
upload operations always target the correct directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): revert currentPath to previous value when navigation fails

Address review feedback: if the directory listing throws a non-session
error, restore currentPath to its previous value so later operations
(e.g. uploads) don't target a path that was never successfully loaded.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): clear files when entering loading state to prevent stale interactions

Address P1 review: the loading overlay is pointer-events-none, so users
could still interact with old files during navigation. Since currentPath
is now updated immediately, actions like delete/rename would resolve
against the new path but display old files. Clear files and selection
when loading begins to eliminate this inconsistency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): restore previous files when reverting path on navigation error

Address P2 review: since files are now cleared when loading begins,
a failed navigation would leave the pane with the old path but an
empty file list. Save and restore the previous files alongside the
previous path in the error handler.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): restore selected files when reverting on navigation error

Address P2 review: save and restore selectedFiles alongside path and
files in the error handler so users don't lose their selection when
a navigation attempt fails.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): restore tab state when navigation is superseded by another request

Address P1 review: navSeqRef is tracked per-side not per-tab, so a
navigation from a different tab on the same side can invalidate this
request. When the sequence check causes an early return, restore this
tab's previous path, files, and selection instead of leaving it with
cleared files and a stale loading state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): avoid overwriting newer navigation state when superseded

When a navigation request is superseded by a newer one on the same tab
(e.g., fast A→B→C), the completing request should not blindly restore
its previous state, as that would overwrite the latest navigation's
optimistic update. Now we check if the tab's current path still matches
what this request set before restoring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): use per-tab request ID to guard superseded navigation restores

Replace the ambiguous currentPath equality check with a per-tab
navigation request ID (tabNavSeqRef). The old check failed when
refresh() triggered a navigation to the same path — the stale request
would incorrectly match and restore previous state.

The new approach tracks the latest requestId per tab, so:
- Same-tab superseded navigations (including same-path refreshes)
  correctly skip the restore.
- Cross-tab superseded navigations (different tab on the same side)
  correctly restore the orphaned tab's state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): track per-tab nav sequence to prevent cache-hit state overwrite

When a cache-miss request (A) is pending and a cache-hit request (B) runs
on the same tab, A's superseded handler could overwrite B's result because
it only checked path equality. Add tabNavSeqRef to track the latest
requestId per tab, so superseded requests correctly skip restore when
a newer navigation (including cache hits) has already handled the tab.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: remove leftover merge conflict markers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): restore to last confirmed state instead of optimistic state

When multiple navigations are in flight (A→B→C), the second navigation
would snapshot the optimistic state (path=B, files=[]) as its "previous"
state. If it then failed or was superseded, it would restore to an empty
file list instead of the last successfully loaded directory.

Introduce lastConfirmedRef to track the last known-good state per tab,
updated only on successful navigation (cache hit or listing success).
Restore-on-error and restore-on-supersede now always revert to this
confirmed state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): guard restores against stale connection after reconnect/disconnect

connect() and disconnect() reuse the same tab ID but bump navSeqRef
without updating tabNavSeqRef, so a pending navigation could restore
stale state from a previous host into a freshly reconnected tab.

Fix by:
- Capturing connectionId at navigation start and checking it in every
  updateTab restore callback (prev.connection?.id !== connectionId)
- Storing connectionId in lastConfirmedRef and re-seeding confirmed
  state when the connection changes, preventing old host data from
  being used as the restore target

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): keep files visible during loading and re-seed confirmed state

Two UI regressions fixed:

1. After a file mutation (delete/create/rename), lastConfirmedRef still
   held the pre-mutation snapshot. If the subsequent refresh failed, the
   error handler would restore stale files (e.g. resurrecting deleted
   items). Fix: re-seed confirmed state from the pane whenever it is
   settled (not loading), capturing any optimistic mutation updates.

2. Clearing files to [] on navigation start left a tab blank when
   superseded by another tab navigating on the same side. Fix: keep
   existing files visible during loading — the loading overlay already
   has pointer-events-none to prevent interaction. Files are replaced
   on success or restored from lastConfirmedRef on error/supersede.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(sftp): block interaction with stale files during directory loading

The loading overlay used pointer-events-none, allowing clicks to pass
through to stale file rows underneath. Since currentPath is updated
immediately on navigation, interacting with old filenames during a slow
load would resolve paths against the new directory.

Remove pointer-events-none from the loading overlay so it properly
blocks all interaction with the stale file list while loading.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: ignore .claude/ directory in eslint config

The .claude/worktrees/ directory contains full repo copies from agent
worktrees. ESLint was scanning these, causing 621 pre-existing errors
(no-undef for Node.js globals in .cjs files) that blocked npm run dev.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 16:05:41 +08:00
penguinway
a86a5e6839 fix(auto-update): revert checkNow to use performCheck (GitHub API) instead of electron-updater IPC
checkNow was calling bridge.checkForUpdate() which invokes updater.checkForUpdates()
via IPC. startAutoCheck() in the main process already calls checkForUpdates() on a
5s timer, and if that network request is still pending, the concurrent IPC call from
checkNow hangs indefinitely, causing the UI to be stuck in "checking" state forever.

Per the original design spec, checkNow should use performCheck() (GitHub API) directly.
This is completely independent of electron-updater's internal state machine, so it
never conflicts with the background startAutoCheck(). performCheck handles isCheckingRef,
isChecking, hasUpdate, and latestRelease; checkNow only manages manualCheckStatus.
2026-03-11 15:46:05 +08:00
penguinway
7ed4940e18 docs: update CHANGELOG for auto-update unification 2026-03-11 15:32:39 +08:00
penguinway
410d1ef097 feat(settings): pass unified updateState and update actions to SettingsSystemTab 2026-03-11 15:28:41 +08:00
penguinway
c386ee2e2e refactor(settings): remove local update state from SettingsSystemTab, use unified updateState props 2026-03-11 15:26:16 +08:00
penguinway
4c08888b60 fix(auto-update): fix isCheckingRef conflict in checkNow fallback path and stale version closure
- Critical: In Linux fallback path, temporarily reset isCheckingRef before calling
  performCheck so its own guard can run (was silently returning null due to double-set)
- Critical: Replace updateState.currentVersion closure in checkNow with currentVersionRef
  to avoid reading stale '' version on early user click; remove from useCallback deps
- Important: Add explicit !result guard when bridge is unavailable, returning 'error'
  status instead of silently falling through to 'up-to-date'
2026-03-11 15:20:27 +08:00
penguinway
2ea4c88680 feat(auto-update): add manualCheckStatus to UpdateState, rewrite checkNow to use electron-updater IPC 2026-03-11 15:13:54 +08:00
penguinway
0ba75f9af0 fix(auto-update): broadcast IPC events to all windows instead of single window 2026-03-11 15:09:29 +08:00
penguinway
4610348b0d Merge branch 'feat/auto-update' 2026-03-11 14:39:22 +08:00
penguinway
8d11b71bc1 Merge branch 'main' of github.com:penguinway/Netcatty 2026-03-11 14:39:08 +08:00
penguinway
6683001032 chore: exclude tests/ and CLAUDE.md from eslint and gitignore 2026-03-11 14:28:46 +08:00
penguinway
3b313ff933 chore: gitignore local test suite (tests/, vitest.config.ts) 2026-03-11 14:08:06 +08:00
penguinway
eaa27461fa docs: add CHANGELOG for auto-update feature 2026-03-11 13:16:39 +08:00
penguinway
20b65366be chore: ignore dev-app-update.yml, revert forceDevUpdateConfig test flag 2026-03-11 13:12:39 +08:00
penguinway
b8c08ba3ca chore: ignore AI-generated docs (docs/superpowers/) 2026-03-11 12:54:11 +08:00
陈大猫
981c5de90d Merge pull request #310 from binaricat/fix/windows-auto-update-signing
fix: prevent macOS signing credentials from leaking to Windows builds
2026-03-11 11:40:58 +08:00
bincxz
0097d65a6e fix: prevent macOS signing credentials from leaking to Windows builds
Only pass CSC_LINK, CSC_KEY_PASSWORD, and Apple notarization secrets
to the macOS matrix job. Previously these were passed to all matrix
jobs, causing electron-builder to sign Windows .exe with the Apple
Developer ID certificate. Windows doesn't trust Apple's certificate
chain, so electron-updater's signature verification failed during
auto-update.

Closes #309
2026-03-11 11:15:04 +08:00
penguinway
e4aa03c474 fix(auto-update): use duration:0 for persistent toast, remove stale comment 2026-03-11 02:44:44 +08:00
penguinway
b94386236c feat(auto-update): add ready-to-install and download-failed toast notifications 2026-03-11 02:40:10 +08:00
penguinway
0883585704 feat(auto-update): add autoDownloadStatus state and IPC subscriptions to useUpdateCheck 2026-03-11 02:35:45 +08:00
penguinway
5b38f4663d feat(auto-update): add i18n keys for ready-to-install and download-failed toasts 2026-03-11 02:35:18 +08:00
penguinway
a6a6dd1aac feat(auto-update): expose onUpdateAvailable in preload bridge 2026-03-11 02:32:20 +08:00
penguinway
506c60ea44 feat(auto-update): trigger startAutoCheck after main window ready 2026-03-11 02:32:09 +08:00
penguinway
9d9b24fe7b feat(auto-update): add onUpdateAvailable type to NetcattyBridge 2026-03-11 02:32:06 +08:00
penguinway
584b9859ef fix(auto-update): guard setupGlobalListeners against duplicate registration 2026-03-11 02:30:52 +08:00
penguinway
b005065949 feat(auto-update): enable autoDownload and global IPC event listeners 2026-03-11 02:27:59 +08:00
penguinway
a4fdb6758d docs: add auto-update implementation plan
Detailed step-by-step plan for feat/auto-update branch. Addresses
reviewer feedback: specific line anchors, SettingsSystemTab props
pattern, removeAllListeners risk, i18n key conflict notes, and
hasUpdate toast suppression when auto-download is active.
2026-03-11 02:23:20 +08:00
penguinway
a2b5c9d067 docs: add auto-update design spec
Spec for changing update flow from manual to auto-download + prompt
install: autoDownload=true in main process, renderer subscribes to
electron-updater IPC events, toast notification on download complete.
2026-03-11 02:11:39 +08:00
陈大猫
a451fd8811 Merge pull request #308 from binaricat/fix/issue-307-display-upload-path
Some checks failed
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
fix(sftp): display upload destination path on completed task items (#307)
2026-03-10 21:26:06 +08:00
bincxz
49cef792a8 fix(sftp): display upload destination path on completed task items (#307)
Show the remote target path inline on completed upload task items
(e.g. "Completed - 1.2 MB → /home/user/dir") so users know exactly
where their files were uploaded after drag-and-drop to terminal.

- Add `targetPath` field to modal's TransferTask type
- Populate targetPath from currentPath in onTaskCreated callback
- Display targetPath on completed upload items in SftpModalUploadTasks
- Add i18n key `sftp.upload.completedToPath` (en/zh-CN)
2026-03-10 21:14:25 +08:00
陈大猫
62511ceb21 Merge pull request #305 from binaricat/fix/sftp-mfa-auth-304
fix(sftp): handle non-fatal agent auth errors for MFA/keyboard-interactive (#304)
2026-03-10 10:54:37 +08:00
bincxz
00cbb05d71 fix(sftp): handle end/close events during SSH connect phase
Address code review feedback: the direct ssh2.Client connect path
was missing end/close event handlers. If the server closes the
connection before 'ready' (e.g. rejected handshake, hop drops),
the promise now properly rejects instead of hanging forever.

Uses a settle/cleanup pattern to ensure listeners are removed and
the promise is resolved/rejected exactly once.
2026-03-10 10:40:47 +08:00
bincxz
3497614165 fix(sftp): fallback to standard SFTP when sudo sftp-server not found
When sudo SFTP fails with exit code 127 (sftp-server binary not found,
e.g. on ESXi), automatically fall back to the standard SFTP subsystem
channel instead of failing the entire connection. This avoids requiring
users to manually disable sudo mode for hosts that lack sftp-server.
2026-03-10 10:37:47 +08:00
bincxz
b652b836a7 fix(sftp): handle non-fatal agent auth errors for MFA/keyboard-interactive (#304)
Two compounding issues caused SFTP connections to fail when
keyboard-interactive (MFA) authentication was required:

1. ssh2-sftp-client's connect() installs error listeners that reject
   the entire connection on ANY error, including non-fatal agent auth
   failures. This prevents ssh2 from falling through to
   keyboard-interactive. Fix: bypass ssh2-sftp-client's connect() and
   use direct ssh2.Client with err.level === 'agent' filtering.

2. getSshAgentSocket() on Windows unconditionally returned the agent
   pipe path without checking if the SSH Agent service is running.
   Fix: added async getAvailableAgentSocket() that runs
   'sc query ssh-agent' before returning the pipe path.
2026-03-10 10:12:37 +08:00
陈大猫
cd604107ee Merge pull request #303 from binaricat/fix/unify-sync-payload
Some checks failed
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
fix: unify sync payload logic & harden port forwarding lifecycle
2026-03-10 03:10:30 +08:00
bincxz
adc4c25dc9 fix: set cancelled flag in stopPortForward(tunnelId) IPC handler\n\nThe legacy stopPortForward(tunnelId) path also needs to mark\ntunnel.cancelled = true before conn.end() and skip the immediate\ndelete. Otherwise, when a user clicks Stop on a connecting rule,\nconn.on('close') sees no cancelled flag and rejects the Promise,\ncausing a false error toast. 2026-03-10 03:04:29 +08:00
bincxz
eaaf0265f8 fix: preserve cancelled markers in stopAllPortForwards\n\nMark all tunnel entries as cancelled before calling conn.end()\nand remove the .clear() call. Let each conn.on('close') handler\ndelete its own entry so it can read the cancelled flag first.\n\nPreviously, .clear() removed all entries before the async close\nevents fired, so the close handler saw no entry and treated the\nshutdown as an unexpected failure — surfacing error toasts or\ntriggering auto-reconnect for rules the user just cleared. 2026-03-10 02:57:56 +08:00
bincxz
f4d833497d fix: ref-count singleton effects and use only stopPortForwardByRuleId for cleanup\n\n1. Replace boolean guard flags (reconnectCancelListenerActive,\n heartbeatActive) with ref-counting. Resources are created when\n count goes 0→1 and destroyed when count goes 1→0. The previous\n boolean approach broke when React ran child effects before parent\n ones: opening the Port Forwarding page let the child register\n the listener/heartbeat, but navigating away tore them down even\n though the App instance was still mounted.\n\n2. stopAndCleanupRule now uses only stopPortForwardByRuleId (which\n sets tunnel.cancelled = true before conn.end()). The old code\n called stopPortForward(tunnelId) first, which deletes the\n main-process tunnel entry immediately — making the cancelled\n flag invisible to conn.on('close') and causing intentional\n deletions to surface as error toasts. 2026-03-10 02:50:58 +08:00
bincxz
75871717a9 fix: capture cancelled flag before close handler cleanup deletes the entry\n\nstopPortForwardByRuleId previously deleted the tunnel entry from\nportForwardingTunnels before conn.end() fired the async close\nevent. By the time conn.on('close') ran, the entry was gone and\nthe cancelled flag was invisible. The fallback check\n!portForwardingTunnels.has(tunnelId) was ambiguous — it was also\ntrue when conn.on('error') deleted the entry for a real failure.\n\nFix:\n1. Capture tunnel.cancelled BEFORE cleanup deletes the entry.\n2. Don't delete in stopPortForwardByRuleId — let conn.on('close')\n handle deletion so it can read the flag first.\n3. Remove the ambiguous !has() fallback check entirely. 2026-03-10 02:42:08 +08:00
bincxz
f6619c28ed fix: strip lastUsedAt from SettingsSyncTab localStorage fallback\n\nConsistent with the useAutoSync fallback, also clear lastUsedAt\nfrom rules read from localStorage before building the sync payload.\nPreviously, device-local usage timestamps leaked into the cloud\nsnapshot and were replicated to other devices on import. 2026-03-10 02:33:43 +08:00
bincxz
ca77315257 fix: handle cancelled handshakes gracefully and evict stale connecting entries\n\n1. startPortForward now checks result.cancelled for intentional\n cancellations (rule deleted/replaced during SSH handshake).\n Instead of triggering error state or reconnect, it transitions\n to 'inactive' and returns cleanly. Previously, success:false\n from a cancelled handshake would schedule another reconnect,\n resurrecting the tunnel a few seconds later.\n\n2. reconcileWithBackend now evicts 'connecting' entries seeded by\n a previous reconcile (observed from another window's handshake)\n when the backend no longer reports them. Only locally-initiated\n connecting entries (which have an unsubscribe callback from\n their startPortForward call) are preserved. Previously, stale\n connecting entries from failed/cancelled handshakes stayed\n forever, with the rule stuck showing 'connecting' in the UI. 2026-03-10 02:25:53 +08:00
bincxz
3ab681e63b fix: update heartbeat entries on status change and graceful intentional cancellation\n\n1. reconcileWithBackend Case 3: when a tunnel already exists in\n activeConnections but the backend reports a different status\n (e.g. connecting→active after handshake completed in another\n window), update the entry and include it in the 'appeared' set.\n Previously, existing entries were never updated, leaving\n secondary windows stuck on 'connecting' permanently.\n\n2. stopPortForwardByRuleId now marks tunnel.cancelled = true\n before calling conn.end(). The close handler checks this flag:\n intentional cancellations resolve with { cancelled: true }\n instead of rejecting with an Error. This prevents the renderer\n from showing a bogus error toast when a rule is deleted or\n replaced while its SSH handshake is still in progress. 2026-03-10 02:16:44 +08:00
bincxz
2ee7781b82 fix: reconnect stuck state, side-effect guards, and syncWithBackend status\n\n1. scheduleReconnectIfNeeded now returns false when the\n activeConnections entry is missing (deleted by stopAndCleanupRule\n while handshake was in-flight). Previously it returned true\n but never set the timeout, leaving reconnect-enabled rules\n stuck in 'connecting' permanently.\n\n2. Module-level guards (reconnectCancelListenerActive,\n heartbeatActive) prevent duplicate initReconnectCancelListener\n and reconcile heartbeat instances. The hook mounts from both\n App.tsx and PortForwardingNew.tsx, so without guards each\n window gets double listeners and double backend polling.\n\n3. syncWithBackend now uses tunnel.status from the backend\n (connecting or active) instead of hardcoding 'active',\n matching the reconcileWithBackend fix from the previous commit. 2026-03-10 02:09:03 +08:00
bincxz
95780a29dc fix: strip lastUsedAt from sync fallback and use real tunnel status in reconciliation\n\n1. useAutoSync localStorage fallback now also strips lastUsedAt\n (alongside status/error). Without this, the hash computed\n before async init (with lastUsedAt) differs from the hash\n after init (App.tsx strips it), causing a needless sync upload\n on every launch.\n\n2. reconcileWithBackend now uses tunnel.status from the backend\n (connecting or active) instead of hardcoding 'active' when\n seeding activeConnections. This prevents falsely marking a\n handshaking tunnel as active in the renderer. 2026-03-10 02:01:05 +08:00
bincxz
060c35f66a fix: auto-sync localStorage fallback for PF rules and settled Promise in bridge\n\n1. useAutoSync buildPayload/getDataHash now fall back to localStorage\n when portForwardingRules is empty (async init not complete).\n Previously, clicking sync immediately after launch would upload\n portForwardingRules: [] and overwrite the cloud snapshot.\n\n2. SettingsSyncTab localStorage fallback strips transient per-device\n fields (status, error) before building the sync payload.\n\n3. startPortForward Promise now tracks a settled flag across all\n resolve/reject paths. conn.on('close') rejects the Promise when\n it hasn't been settled yet (tunnel killed during SSH handshake\n by stopPortForwardByRuleId), preventing callers from hanging\n indefinitely in pendingOperations. 2026-03-10 01:52:48 +08:00
bincxz
ee5d3827d5 fix: reconnect cancel on clear-all, strip transient sync fields, tunnel connecting status\n\n1. importRules([]) now iterates stored rules calling\n stopAndCleanupRule() for each one, broadcasting per-rule reconnect\n cancellation to other windows. Previously only called\n stopAllPortForwards() which doesn't signal reconnect cancel.\n\n2. SettingsSyncTab localStorage fallback strips transient per-device\n fields (status, error) before feeding rules to buildSyncPayload.\n This prevents uploading stale connection state to the cloud.\n\n3. portForwardingBridge tunnel entries now track status explicitly:\n 'connecting' on early registration, 'active' after server.listen\n or forwardIn succeeds. listPortForwards and getPortForwardStatus\n report the actual status instead of hardcoding 'active'. 2026-03-10 01:42:01 +08:00
bincxz
f06333b95e fix: register tunnel in portForwardingTunnels before SSH handshake\n\nThe previous stopPortForwardByRuleId couldn't catch tunnels during\nSSH handshake because they were only added to portForwardingTunnels\nafter conn.on('ready') + server.listen/forwardIn succeeded.\n\nNow the connection is registered immediately before conn.connect()\nwith server: null. The conn.on('ready') handler updates the entry\nwith the real server object. Error/close handlers already delete\nthe entry, so cleanup is unchanged.\n\nThis closes the last timing window where a deleted rule's tunnel\ncould become orphaned. 2026-03-10 01:33:59 +08:00
bincxz
a07c644ec8 fix: add stopPortForwardByRuleId IPC and fix uninitialized diff baseline\n\nTwo issues:\n\n1. Cross-window cleanup couldn't stop tunnels still in SSH handshake\n because listPortForwards doesn't list them. New approach:\n stopPortForwardByRuleId IPC directly iterates the main process\n portForwardingTunnels map matching by rule ID in the tunnel ID\n string, catching tunnels in ANY state.\n\n - portForwardingBridge.cjs: new stopPortForwardByRuleId function\n - preload.cjs + global.d.ts: expose the new IPC\n - portForwardingService.ts: stopAndCleanupRule and\n initReconnectCancelListener now use stopPortForwardByRuleId\n instead of fragile listPortForwards + match\n\n2. importRules diff loop missed removed/changed rules in a freshly\n opened settings window where globalRules was still empty (async\n initializeStore hadn't finished). Now falls back to reading from\n localStorage as the diff baseline. 2026-03-10 01:28:06 +08:00
bincxz
1d5c40c665 fix: expose stopAllPortForwards via IPC for cross-window tunnel cleanup\n\nThe renderer's stopAllPortForwards only iterated activeConnections\nwhich is empty in a freshly opened settings window. The backend's\nstopAllPortForwards (which iterates portForwardingTunnels in the\nmain process) was only called from will-quit, never via IPC.\n\nChanges:\n- portForwardingBridge.cjs: register netcatty:portforward:stopAll\n- preload.cjs: expose stopAllPortForwards in the bridge API\n- global.d.ts: add type for stopAllPortForwards\n- portForwardingService.ts: after clearing local activeConnections,\n also call bridge.stopAllPortForwards() to stop any backend\n tunnels this renderer doesn't know about 2026-03-10 01:17:55 +08:00
bincxz
ab0c4ede7e fix: handle settings window initialization timing for sync and cleanup\n\nTwo race conditions in the settings window when hooks haven't finished\nasync initialization:\n\n1. clearAllLocalData calls importRules([]) but globalRules is still\n empty, so no stopAndCleanupRule calls are made. Fix: when\n importRules receives an empty array, call stopAllPortForwards()\n on the backend as a safety net.\n\n2. onBuildPayload reads portForwardingRules from hook state which\n starts as [] until initializeStore finishes. Fix: fall back to\n reading directly from localStorage when hook state is empty,\n preventing empty-array upload that would overwrite remote data. 2026-03-10 01:10:07 +08:00
bincxz
cf86c166cf fix: Prevent xterm.js right-click behavior from interfering with tmux/vim popups when mouse tracking is active. 2026-03-10 00:59:44 +08:00
bincxz
686a707fef fix: address Codex round-3 reviews (legacy payload, heartbeat, cross-window reconnect)\n\n1. Preserve local state for legacy payloads: use !== undefined\n checks instead of ?? [] so older cloud snapshots that omit\n knownHosts/portForwardingRules don't wipe local data.\n\n2. Skip connecting tunnels during heartbeat eviction: the backend\n only lists tunnels after SSH handshake completes, so slow\n connections would be falsely evicted.\n\n3. Cross-window reconnect cancellation: stopAndCleanupRule now\n broadcasts via localStorage so other windows cancel pending\n reconnect timers. initReconnectCancelListener listens for\n these events and clears timers + activeConnections entries. 2026-03-10 00:55:07 +08:00
bincxz
159a5eccd2 fix: address Codex round-2 reviews (legacy payload, heartbeat, cross-window)\n\n1. Preserve omitted sync fields for legacy payloads: revert ?? []\n to !== undefined checks so older cloud snapshots that lack\n knownHosts/portForwardingRules don't destructively wipe local data.\n\n2. Exclude connecting tunnels from heartbeat eviction: backend\n doesn't report a tunnel until SSH handshake completes, so slow\n connections (MFA, network latency) were being falsely evicted\n every 4 seconds.\n\n3. Cross-window tunnel cleanup: stopAndCleanupRule now queries\n the backend for the tunnel ID when no local activeConnections\n entry exists (settings window stopping a tunnel started by\n the main window). 2026-03-10 00:46:45 +08:00
bincxz
8a6e915dd7 fix: address Codex review P1 (stale tunnel on config change) and P2 (additive-only sync)\n\nP1: importRules now compares 6 connection-relevant fields\n(type, localPort, remoteHost, remotePort, bindAddress, hostId)\nbetween existing and incoming rules. If any differ, the old\ntunnel is torn down so the UI no longer shows 'active' for\na tunnel pointing at stale parameters.\n\nP2: applySyncPayload now uses ?? [] fallback for\nportForwardingRules and knownHosts. This ensures 'download\nand replace' truly replaces all data, even when the payload\nwas created by an older client that didn't emit these fields. 2026-03-10 00:36:49 +08:00
bincxz
474a8bae87 chore: reduce heartbeat interval from 30s to 4s 2026-03-10 00:23:55 +08:00
bincxz
6c2e902007 feat: add periodic heartbeat to reconcile port forwarding state\n\nAdd a 30-second heartbeat that queries the main process for actual\nactive tunnels and reconciles with the renderer's state. This\nprevents state drift caused by:\n- Tunnel dying without IPC notification reaching renderer\n- Status callbacks being unsubscribed after page navigation\n- Any other edge case where renderer and backend disagree\n\nChanges:\n- Add reconcileWithBackend() to portForwardingService that detects\n gone (renderer has it, backend doesn't) and appeared (backend\n has it, renderer doesn't) tunnels\n- Add 30s heartbeat useEffect in usePortForwardingState that\n auto-corrects rule statuses when drift is detected 2026-03-10 00:18:17 +08:00
bincxz
0e61262bc0 fix: stop active tunnels when rules are deleted or replaced\n\nPreviously, deleteRule() and importRules() only removed port\nforwarding rules from state/UI without stopping the backend SSH\ntunnels. This left orphaned tunnels listening on ports with no\nUI control to shut them down.\n\nChanges:\n- Add stopAndCleanupRule() to portForwardingService for fire-and-\n forget tunnel teardown (clears reconnect timers, unsubscribes\n status events, sends IPC stop to main process)\n- deleteRule() now calls stopAndCleanupRule() before removing\n- importRules() now diffs old vs new rule IDs and stops tunnels\n for any rules being removed (covers cloud sync download and\n Clear Local Data scenarios) 2026-03-10 00:12:18 +08:00
bincxz
200d710cc9 fix: clear port forwarding rules when clearing local data
Address Codex review: since the sync payload now includes
portForwardingRules, "Clear Local Data" must also reset them
to prevent stale rules from being re-uploaded on the next sync.
2026-03-09 23:55:04 +08:00
bincxz
a7873fc457 fix: unify sync payload build/apply logic to prevent data loss\n\nThe settings window was building sync payloads with customGroups\nhardcoded to [] and missing portForwardingRules/knownHosts entirely.\nThis caused data loss when syncing from the settings window.\n\nChanges:\n- Add domain/syncPayload.ts with buildSyncPayload/applySyncPayload\n pure functions as the single source of truth\n- Update App.tsx to use applySyncPayload instead of inline logic\n- Rewrite SettingsSyncTab.tsx to use unified domain functions\n- Wire portForwardingRules through SettingsPage.tsx to the sync tab\n- Fix useAutoSync getDataHash to include customGroups and knownHosts\n so their changes trigger auto-sync 2026-03-09 23:40:07 +08:00
陈大猫
1286975a4b fix: improve URL highlighting precision (#302)
* fix: improve URL highlighting precision

* fix: tighten ipv4 highlight boundaries

* fix: narrow version prefix exclusion

* fix: trim trailing URL delimiters

* fix: preserve bracketed ipv6 urls
2026-03-09 23:07:10 +08:00
陈大猫
2933e108bc feat: support system theme auto-switching (#301)
* feat: support system theme auto-switching\n\nAdd 'system' as a third theme option alongside 'light' and 'dark'.\nWhen set to 'system', the UI theme automatically follows the OS\ncolor scheme preference and switches in real-time when the system\nappearance changes.\n\nChanges:\n- useSettingsState.ts: Add resolvedTheme state derived from\n  matchMedia('prefers-color-scheme: dark'), add listener for\n  system preference changes, update applyThemeTokens to use\n  resolvedTheme instead of theme directly\n- SettingsAppearanceTab.tsx: Replace dark mode Toggle with\n  3-segment selector (Light / System / Dark) using Sun/Monitor/Moon\n  icons\n- en.ts/zh-CN.ts: Replace darkMode i18n keys with new theme keys\n  including 'system' option\n- Default theme changed from 'light' to 'system' for new users\n\nPartially addresses #294

* fix: derive resolvedTheme synchronously and guard matchMedia\n\nAddress Codex review feedback:\n1. Replace resolvedTheme useState+useEffect with synchronous\n   derivation from systemPreference state. This eliminates the\n   one-frame stale render where useLayoutEffect could apply\n   tokens from the old palette before useEffect updated\n   resolvedTheme.\n2. Add window.matchMedia guard in the system preference listener\n   to prevent crashes in jsdom tests or constrained webviews.\n3. Make the matchMedia listener unconditional (always tracks OS\n   preference) to avoid setup/teardown churn when toggling modes.

* fix: resolve 'system' theme in pre-hydration bootstrap to prevent flash

The index.html bootstrap script only handled 'dark'/'light' stored
values. Since DEFAULT_THEME is now 'system', new users (or users who
chose system mode) would get a wrong-theme first paint until React
mounted. Now resolve 'system' via matchMedia('(prefers-color-scheme:
dark)') before applying the CSS class, eliminating the visible flash.

Also use the resolved theme (not raw stored value) for accent foreground
calculation to ensure correct contrast on first paint.

Addresses Codex review on PR #301.

* fix: use resolvedTheme for top-bar toggle to avoid no-op in system mode

When theme preference is 'system' and the OS is dark, the toggle button
showed a moon icon and clicking it just switched from 'system' to 'dark'
— visually a no-op. Now we:

1. Pass resolvedTheme (always 'light'|'dark') to TopTabs for icon display
2. Toggle based on resolvedTheme so the first click always produces a
   visible change (e.g. system+dark → light, system+light → dark)

Addresses Codex review on PR #301.
2026-03-09 21:49:00 +08:00
陈大猫
8278bfde0f feat: show hidden files (dotfiles) on local filesystem browser\n\nPreviously, the showHiddenFiles setting only hid dotfiles on remote\nconnections. Local filesystem panes always showed dotfiles like\n.gitignore, .env, etc. regardless of the setting.\n\nNow the setting consistently hides/shows dotfiles on both local and\nremote connections. Also updated the i18n descriptions in EN and\nzh-CN to remove outdated Windows-only references.\n\nChanges:\n- utils.ts: Remove isLocal bypass from isHiddenFile/filterHiddenFiles\n- useSftpPaneFiles.ts: Remove isLocal from filterHiddenFiles call\n- useSftpKeyboardShortcuts.ts: Remove isLocal from filterHiddenFiles\n- SFTPModal.tsx: Remove isLocalSession from filterHiddenFiles call\n- en.ts/zh-CN.ts: Update descriptions to be platform-agnostic\n\nPartially addresses #294 (#299) 2026-03-09 19:12:43 +08:00
陈大猫
d0b941eabf docs: add Shift+Drag hint for tmux/vim in copy-on-select setting\n\nUpdate the copy-on-select setting description in both EN and zh-CN\nlocales to guide users on how to select text when tmux or vim has\nmouse mode enabled: hold Shift while dragging.\n\nPartially addresses #294 (#298) 2026-03-09 19:00:52 +08:00
陈大猫
a98821acb7 fix: re-run startup command on Start Over after SSH disconnect (#297)
* fix: re-run startup command on Start Over after SSH disconnect\n\nThe hasRunStartupCommandRef was set to true on first connection but\nnever reset when the user clicked Start Over (handleRetry). This\ncaused the startup command to be skipped on all subsequent retries.\n\nReset the ref to false in handleRetry so the startup command\nexecutes again on reconnection.\n\nPartially addresses #294

* fix: guard startup-command timer against stale sessions\n\nCapture the session ID when scheduling the startup command timer\nand verify it still matches sessionRef.current when the timer fires.\n\nThis prevents double execution when the user clicks Start Over\nquickly: the old timer detects the session ID mismatch and bails\nout, so only the new connection's timer runs the startup command.\n\nApplied to both SSH and Mosh startup command paths.
2026-03-09 18:20:03 +08:00
陈大猫
4edc28113e fix: scroll terminal to bottom on paste when scrollOnPaste is enabled\n\nThe scrollOnPaste setting only affected xterm.js native paste events.\nWhen pasting via Netcatty's context menu or keyboard shortcut, the\nterminal did not scroll to bottom because the custom paste path uses\nwriteToSession() which bypasses xterm's built-in scroll-on-paste.\n\nNow explicitly calls term.scrollToBottom() after writing paste data\nwhen the scrollOnPaste setting is enabled (default: true).\n\nPartially addresses #294 (#296) 2026-03-09 18:07:42 +08:00
陈大猫
adc712e121 fix: disable context menu in alternate screen to prevent tmux double menu (#295)
* fix: disable context menu in alternate screen to prevent tmux double menu\n\nWhen applications like tmux enable mouse mode in xterm's alternate\nscreen buffer, right-clicking would show both tmux's context menu\nand Netcatty's context menu simultaneously.\n\nThis fix detects alternate screen mode via xterm.js buffer.onBufferChange\nand disables Netcatty's context menu, letting the terminal application\nhandle mouse events natively.\n\nFixes #294 (Bug 1: Tmux duplicate context menus)

* refactor: use mouse tracking mode detection instead of alternate screen\n\nReplace alternate screen detection with mouseTrackingMode check.\nThis is more precise: context menu is only disabled when the terminal\napplication is actively capturing mouse events (e.g. tmux with\n`set -g mouse on`, vim with `set mouse=a`).\n\nPrograms that use alternate screen without mouse tracking (e.g.\nless, man, vim without mouse) will still show Netcatty's context menu.
2026-03-09 17:50:19 +08:00
陈大猫
81d1b4602d feat: add auto-update support via electron-updater (#289) (#293)
* feat: add auto-update support via electron-updater (#289)

- Add autoUpdateBridge.cjs wrapping electron-updater for check/download/install
- Register bridge in main.cjs, expose IPC in preload.cjs
- Add auto-update methods to NetcattyBridge type in global.d.ts
- Extend updateService.ts with electron-updater bridge functions
- Add Software Update section in Settings > System tab with state machine UI
- Add i18n keys for update UI (en + zh-CN)
- Add publish config for GitHub Releases in electron-builder.config.cjs
- Update CI workflow to upload update metadata (*.yml, *.blockmap, *.zip)
- Fallback to manual GitHub download for unsupported platforms or errors

* fix: address Codex review - guard bridge call and pin sender window

- Guard optional bridge call in SettingsSystemTab to prevent TypeError
  when getAppInfo is unavailable (e.g. browser/dev/test rendering)
- Capture senderWindow at download initiation in autoUpdateBridge so
  progress/downloaded/error events always go to the requesting renderer,
  even if focus changes during download

* fix: use semver ordering for version check and clean up listeners on rejection

- Replace strict equality (===) with localeCompare for version comparison
  to avoid false positives on pre-release/nightly builds
- Clean up download-progress/update-downloaded/error listeners in the
  catch path when downloadUpdate() rejects before emitting events

* feat: redirect update toast to Settings window for in-app update

- Update toast notification now opens Settings window instead of
  GitHub Releases page, enabling the in-app download/install flow
- Add 'update.viewInSettings' i18n key (en + zh-CN)
- Remove unused openReleasePage from App.tsx destructuring
- Move useWindowControls() before the update effect to fix declaration order
2026-03-09 13:34:05 +08:00
陈大猫
540aabb676 fix: skip invalid ssh agent sockets (#292) 2026-03-09 11:59:42 +08:00
陈大猫
8d014193ca Remove dead code and unused components (#288) 2026-03-08 10:55:17 +08:00
93 changed files with 2960 additions and 2441 deletions

View File

@@ -59,12 +59,12 @@ jobs:
- name: Build package
env:
ELECTRON_BUILDER_PUBLISH: "never"
# macOS code signing & notarization (ignored on other platforms)
CSC_LINK: ${{ secrets.MAC_CSC_LINK }}
CSC_KEY_PASSWORD: ${{ secrets.MAC_CSC_KEY_PASSWORD }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
# macOS code signing & notarization (only for macOS builds)
CSC_LINK: ${{ matrix.name == 'macos' && secrets.MAC_CSC_LINK || '' }}
CSC_KEY_PASSWORD: ${{ matrix.name == 'macos' && secrets.MAC_CSC_KEY_PASSWORD || '' }}
APPLE_ID: ${{ matrix.name == 'macos' && secrets.APPLE_ID || '' }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ matrix.name == 'macos' && secrets.APPLE_APP_SPECIFIC_PASSWORD || '' }}
APPLE_TEAM_ID: ${{ matrix.name == 'macos' && secrets.APPLE_TEAM_ID || '' }}
run: npm run ${{ matrix.pack_script }}
- name: Upload artifacts
@@ -73,12 +73,15 @@ jobs:
name: netcatty-${{ matrix.name }}
path: |
release/*.dmg
release/*.zip
release/*.exe
release/*.msi
release/*.AppImage
release/*.deb
release/*.rpm
release/*.tar.gz
release/*.yml
release/*.blockmap
if-no-files-found: ignore
# Linux x64 — builds directly on ubuntu-latest (no container).
@@ -130,6 +133,8 @@ jobs:
release/*.AppImage
release/*.deb
release/*.rpm
release/*.yml
release/*.blockmap
if-no-files-found: ignore
# Dedicated job for Linux ARM64 — builds inside Debian Bullseye (GLIBC 2.31)
@@ -184,6 +189,8 @@ jobs:
release/*.AppImage
release/*.deb
release/*.rpm
release/*.yml
release/*.blockmap
if-no-files-found: ignore
release:
@@ -219,10 +226,13 @@ jobs:
body_path: release_notes.md
files: |
artifacts/*.dmg
artifacts/*.zip
artifacts/*.exe
artifacts/*.AppImage
artifacts/*.deb
artifacts/*.rpm
artifacts/*.yml
artifacts/*.blockmap
generate_release_notes: true
fail_on_unmatched_files: false
token: ${{ secrets.RELEASE_TOKEN }}

20
.gitignore vendored
View File

@@ -37,3 +37,23 @@ coverage
# Claude Code local settings
/.claude/settings.local.json
/CLAUDE.md
# AI / Superpowers generated docs (local only)
/docs/superpowers/
# Dev-only electron-updater test config (not for production)
/dev-app-update.yml
# Test suite (local only, not committed)
/tests/
/vitest.config.ts
# Serena MCP project config (local only)
/.serena/
# Windows VS Build environment scripts (local dev only)
Directory.Build.props
Directory.Build.targets
build_with_vs.bat
build_with_vs2022.bat

80
App.tsx
View File

@@ -14,6 +14,7 @@ import { initializeUIFonts } from './application/state/uiFontStore';
import { I18nProvider, useI18n } from './application/i18n/I18nProvider';
import { matchesKeyBinding } from './domain/models';
import { resolveHostAuth } from './domain/sshAuth';
import { applySyncPayload } from './domain/syncPayload';
import { getCredentialProtectionAvailability } from './infrastructure/services/credentialProtection';
import { netcattyBridge } from './infrastructure/services/netcattyBridge';
import { TopTabs } from './components/TopTabs';
@@ -167,8 +168,8 @@ function App({ settings }: { settings: SettingsState }) {
const [passphraseQueue, setPassphraseQueue] = useState<PassphraseRequest[]>([]);
const {
theme,
setTheme,
resolvedTheme,
setTerminalThemeId,
currentTerminalTheme,
terminalFontFamilyId,
@@ -282,20 +283,14 @@ function App({ settings }: { settings: SettingsState }) {
identities,
snippets,
customGroups,
snippetPackages,
portForwardingRules: portForwardingRulesForSync,
knownHosts,
onApplyPayload: (payload) => {
importDataFromString(JSON.stringify({
hosts: payload.hosts,
keys: payload.keys,
identities: payload.identities,
snippets: payload.snippets,
customGroups: payload.customGroups,
}));
if (payload.portForwardingRules) {
importPortForwardingRules(payload.portForwardingRules);
}
applySyncPayload(payload, {
importVaultData: importDataFromString,
importPortForwardingRules,
});
},
});
@@ -310,10 +305,15 @@ function App({ settings }: { settings: SettingsState }) {
}, [handleSyncNow]);
// Update check hook - checks for new versions on startup
const { updateState, openReleasePage, dismissUpdate } = useUpdateCheck();
const { updateState, dismissUpdate, openReleasePage, installUpdate } = useUpdateCheck();
// Show toast notification when update is available
// Window controls - must be before update toast effect which uses openSettingsWindow
const { openSettingsWindow } = useWindowControls();
// Show toast notification when update is available (only when auto-download is idle)
useEffect(() => {
// Skip "update available" toast if auto-download has already started or completed
if (updateState.autoDownloadStatus !== 'idle') return;
if (updateState.hasUpdate && updateState.latestRelease) {
const version = updateState.latestRelease.version;
toast.info(
@@ -322,14 +322,51 @@ function App({ settings }: { settings: SettingsState }) {
title: t('update.available.title'),
duration: 8000, // Show longer for update notifications
onClick: () => {
openReleasePage();
void openSettingsWindow();
// Dismiss the update so the toast doesn't re-fire on every render.
// On unsupported platforms (where autoDownloadStatus stays 'idle')
// this is the only way to suppress the notification for this version.
// On supported platforms this toast only shows before auto-download
// starts, and the Settings window's own useUpdateCheck will pick up
// the download state via IPC events independently of the dismiss.
dismissUpdate();
},
actionLabel: t('update.downloadNow'),
actionLabel: t('update.viewInSettings'),
}
);
}
}, [updateState.hasUpdate, updateState.latestRelease, t, openReleasePage, dismissUpdate]);
}, [updateState.hasUpdate, updateState.latestRelease, updateState.autoDownloadStatus, t, openSettingsWindow, dismissUpdate]);
// Track previous autoDownloadStatus so toast effects fire only on actual transitions,
// not when unrelated deps (openReleasePage, installUpdate) change their reference.
const prevAutoDownloadStatusRef = useRef(updateState.autoDownloadStatus);
useEffect(() => {
const prev = prevAutoDownloadStatusRef.current;
prevAutoDownloadStatusRef.current = updateState.autoDownloadStatus;
if (prev === updateState.autoDownloadStatus) return;
if (updateState.autoDownloadStatus === 'ready') {
const version = updateState.latestRelease?.version ?? '';
toast.info(
t('update.readyToInstall.message', { version }),
{
title: t('update.readyToInstall.title'),
duration: 0,
actionLabel: t('update.restartNow'),
onClick: () => installUpdate(),
}
);
} else if (updateState.autoDownloadStatus === 'error') {
toast.error(
t('update.downloadFailed.message'),
{
title: t('update.downloadFailed.title'),
actionLabel: t('update.openReleases'),
onClick: () => openReleasePage(),
}
);
}
}, [updateState.autoDownloadStatus, updateState.latestRelease?.version, t, installUpdate, openReleasePage]);
// Memoize keys for port forwarding to prevent unnecessary re-renders
const portForwardingKeys = useMemo(
@@ -1087,14 +1124,15 @@ function App({ settings }: { settings: SettingsState }) {
}, [protocolSelectHost, handleConnectToHost]);
const handleToggleTheme = useCallback(() => {
setTheme(prev => prev === 'dark' ? 'light' : 'dark');
}, [setTheme]);
// Toggle based on the actual rendered theme so clicking always produces a visible change,
// even when the stored preference is 'system'.
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');
}, [resolvedTheme, setTheme]);
const handleOpenQuickSwitcher = useCallback(() => {
setIsQuickSwitcherOpen(true);
}, []);
const { openSettingsWindow } = useWindowControls();
const handleOpenSettings = useCallback(() => {
void (async () => {
@@ -1162,7 +1200,7 @@ function App({ settings }: { settings: SettingsState }) {
return (
<div className="flex flex-col h-screen text-foreground font-sans netcatty-shell" onContextMenu={handleRootContextMenu}>
<TopTabs
theme={theme}
theme={resolvedTheme}
sessions={sessions}
orphanSessions={orphanSessions}
workspaces={workspaces}

32
CHANGELOG.md Normal file
View File

@@ -0,0 +1,32 @@
# Changelog
## [Unreleased] - 2026-03-11
### 功能
- 修复自动更新 IPC 事件仅发送到单个窗口的问题,改为广播所有窗口(主窗口 + 设置窗口均可收到)
- 统一手动检查更新与自动更新的状态机,消除三套并行状态
- 手动"检查更新"通过 GitHub API 检测版本,发现更新后异步触发 electron-updater 下载
- 设置窗口中点击"检查更新"后,下载进度可实时反映在 UI 中
- 应用启动后 5 秒自动触发 `electron-updater` 检查更新,无需用户手动点击
- 发现新版本后自动开始下载(`autoDownload=true`
- 下载完成后弹出持久 toast 通知,用户点击"立即重启"即可安装
- 下载失败时弹出错误 toast提供"打开 Releases"降级入口
- Settings > System 进度条实时展示自动下载进度,由 `useUpdateCheck` 统一驱动
- Linux deb/rpm/snap 等不支持 electron-updater 的平台自动跳过,保持原有 GitHub API 通知行为
### 设计原理
- `broadcastToAllWindows` 替换 `getSenderWindow` 单点发送,保证所有窗口都能收到 IPC 事件
- `manualCheckStatus` 字段追踪手动检查 UI 状态idle/checking/available/up-to-date/error`autoDownloadStatus` 在 UI 层按优先级渲染
- `SettingsSystemTab` 不再持有本地 update state单向接收 `useUpdateCheck` 统一数据
- 将原有两套独立系统GitHub API 通知 + electron-updater 手动下载)合并为统一状态机:`useUpdateCheck` 作为唯一事实来源,同时驱动 `App.tsx` toast 和 `SettingsSystemTab` 进度条
- 全局持久化 IPC 监听器在 `autoUpdateBridge.init()` 时一次性注册,避免每次手动下载请求重复注册/清理监听器
- `autoInstallOnAppQuit=false`,不做静默安装,由用户主动触发重启
### 接口变更SettingsSystemTabProps
- 移除:`autoDownloadStatus``downloadPercent`
- 新增:`updateState`(完整 UpdateState`checkNow``installUpdate``openReleasePage`
### 注意事项
- `checkNow` 语义:使用 GitHub API`performCheck`)检测是否有新版本,若发现更新且 electron-updater 尚未开始下载,则异步触发 `bridge.checkForUpdate()` 启动自动下载流程
- 此功能仅对打包后的应用Windows NSIS、macOS dmg/zip、Linux AppImage生效dev 模式需配合 `forceDevUpdateConfig=true` + `dev-app-update.yml` 测试(见 `.gitignore`
- `hasUpdate` 旧 toast 在 `autoDownloadStatus !== 'idle'` 时自动抑制,避免与新 toast 重复

View File

@@ -93,6 +93,27 @@ const en: Messages = {
'settings.system.credentials.unavailableHint': 'Credentials encrypted on another user profile or machine cannot be decrypted here. Re-enter and save credentials on this device.',
'settings.system.credentials.portabilityHint': 'Cloud Sync is portable because it uses your master key encryption. Local safeStorage encryption is device/user scoped.',
// Settings > System > Software Update
'settings.update.title': 'Software Update',
'settings.update.currentVersion': 'Current version',
'settings.update.checkForUpdates': 'Check for Updates',
'settings.update.checking': 'Checking...',
'settings.update.upToDate': 'You are using the latest version.',
'settings.update.available': 'New version {version} is available.',
'settings.update.download': 'Download Update',
'settings.update.downloading': 'Downloading... {percent}%',
'settings.update.readyToInstall': 'Update downloaded and ready to install.',
'settings.update.restartNow': 'Restart to Update',
'settings.update.error': 'Failed to check for updates.',
'settings.update.downloadError': 'Download failed.',
'settings.update.manualDownload': 'Download from GitHub',
'settings.update.manualDownloadHint': 'Auto-update is not available on this platform. Download the latest version from GitHub.',
'settings.update.hint': 'Netcatty checks for updates from GitHub Releases.',
'settings.update.lastCheckedJustNow': 'just now',
'settings.update.lastCheckedMinutesAgo': '{n} min ago',
'settings.update.lastCheckedHoursAgo': '{n} hr ago',
'settings.update.lastCheckedPrefix': 'Last checked: ',
// Settings > Session Logs
'settings.sessionLogs.title': 'Session Logs',
'settings.sessionLogs.description': 'Configure session log export and auto-save settings.',
@@ -159,13 +180,23 @@ const en: Messages = {
'update.upToDate.message': 'You are running the latest version ({version}).',
'update.error': 'Failed to check for updates',
'update.downloadNow': 'Download Now',
'update.viewInSettings': 'View in Settings',
'update.readyToInstall.title': 'Update Ready',
'update.readyToInstall.message': 'Version {version} downloaded and ready to install.',
'update.restartNow': 'Restart Now',
'update.downloadFailed.title': 'Update Failed',
'update.downloadFailed.message': 'Failed to download update. You can download it manually.',
'update.openReleases': 'Open Releases',
'update.remindLater': 'Remind Later',
'update.skipVersion': 'Skip This Version',
// Settings > Appearance
'settings.appearance.uiTheme': 'UI Theme',
'settings.appearance.darkMode': 'Dark Mode',
'settings.appearance.darkMode.desc': 'Toggle between light and dark theme',
'settings.appearance.theme': 'Theme',
'settings.appearance.theme.desc': 'Choose light, dark, or follow system preference',
'settings.appearance.theme.light': 'Light',
'settings.appearance.theme.dark': 'Dark',
'settings.appearance.theme.system': 'System',
'settings.appearance.accentColor': 'Accent Color',
'settings.appearance.customColor': 'Custom color',
'settings.appearance.accentColor.mode': 'Use custom accent',
@@ -226,7 +257,7 @@ const en: Messages = {
'settings.terminal.behavior.rightClick.paste': 'Paste',
'settings.terminal.behavior.rightClick.selectWord': 'Select word',
'settings.terminal.behavior.copyOnSelect': 'Copy on select',
'settings.terminal.behavior.copyOnSelect.desc': 'Automatically copy selected text',
'settings.terminal.behavior.copyOnSelect.desc': 'Automatically copy selected text. In tmux/vim with mouse mode, hold Option on macOS or Shift on Windows/Linux to select',
'settings.terminal.behavior.middleClickPaste': 'Middle-click paste',
'settings.terminal.behavior.middleClickPaste.desc':
'Paste clipboard content on middle-click',
@@ -707,6 +738,7 @@ const en: Messages = {
'sftp.upload.currentFile': 'Current: {fileName}',
'sftp.upload.cancelled': 'Upload cancelled',
'sftp.upload.cancel': 'Cancel',
'sftp.upload.completedToPath': 'Uploaded to {path}',
// SFTP Download
'sftp.download.completed': 'Downloaded',
@@ -723,9 +755,9 @@ const en: Messages = {
// Settings > SFTP Show Hidden Files
'settings.sftp.showHiddenFiles': 'Show hidden files',
'settings.sftp.showHiddenFiles.desc': 'Display files with the Windows hidden attribute in the SFTP file browser when browsing local Windows filesystem.',
'settings.sftp.showHiddenFiles.desc': 'Display hidden files (dotfiles on Unix/macOS and files with the hidden attribute on Windows) in the SFTP file browser.',
'settings.sftp.showHiddenFiles.enable': 'Show hidden files',
'settings.sftp.showHiddenFiles.enableDesc': 'Display Windows hidden files when browsing local filesystem',
'settings.sftp.showHiddenFiles.enableDesc': 'Display hidden files when browsing both local and remote filesystems',
// Settings > SFTP Compressed Upload
'settings.sftp.compressedUpload': 'Folder Compression Transfer',

View File

@@ -77,6 +77,27 @@ const zhCN: Messages = {
'settings.system.credentials.unavailableHint': '在其他用户或机器上加密的凭据无法在此处解密。请在当前设备重新输入并保存凭据。',
'settings.system.credentials.portabilityHint': '云同步可跨设备,因为使用主密钥加密;本地 safeStorage 加密仅绑定当前系统用户/设备。',
// Settings > System > Software Update
'settings.update.title': '软件更新',
'settings.update.currentVersion': '当前版本',
'settings.update.checkForUpdates': '检查更新',
'settings.update.checking': '检查中...',
'settings.update.upToDate': '当前已是最新版本。',
'settings.update.available': '新版本 {version} 已发布。',
'settings.update.download': '下载更新',
'settings.update.downloading': '正在下载... {percent}%',
'settings.update.readyToInstall': '更新已下载,准备安装。',
'settings.update.restartNow': '重启并更新',
'settings.update.error': '检查更新失败。',
'settings.update.downloadError': '下载失败。',
'settings.update.manualDownload': '前往 GitHub 下载',
'settings.update.manualDownloadHint': '当前平台不支持自动更新,请前往 GitHub 下载最新版本。',
'settings.update.hint': 'Netcatty 从 GitHub Releases 检查更新。',
'settings.update.lastCheckedJustNow': '刚刚',
'settings.update.lastCheckedMinutesAgo': '{n} 分钟前',
'settings.update.lastCheckedHoursAgo': '{n} 小时前',
'settings.update.lastCheckedPrefix': '上次检查:',
// Settings > Session Logs
'settings.sessionLogs.title': '会话日志',
'settings.sessionLogs.description': '配置会话日志导出和自动保存设置。',
@@ -143,13 +164,23 @@ const zhCN: Messages = {
'update.upToDate.message': '当前版本 ({version}) 已是最新。',
'update.error': '检查更新失败',
'update.downloadNow': '立即下载',
'update.viewInSettings': '在设置中查看',
'update.readyToInstall.title': '更新已就绪',
'update.readyToInstall.message': '版本 {version} 已下载完成,准备安装。',
'update.restartNow': '立即重启',
'update.downloadFailed.title': '更新失败',
'update.downloadFailed.message': '下载更新失败,可前往 GitHub 手动下载。',
'update.openReleases': '打开 Releases',
'update.remindLater': '稍后提醒',
'update.skipVersion': '跳过此版本',
// Settings > Appearance
'settings.appearance.uiTheme': '界面主题',
'settings.appearance.darkMode': '深色模式',
'settings.appearance.darkMode.desc': '浅色深色主题之间切换',
'settings.appearance.theme': '主题',
'settings.appearance.theme.desc': '选择浅色深色或跟随系统设置',
'settings.appearance.theme.light': '浅色',
'settings.appearance.theme.dark': '深色',
'settings.appearance.theme.system': '系统',
'settings.appearance.accentColor': '强调色',
'settings.appearance.customColor': '自定义颜色',
'settings.appearance.accentColor.mode': '使用自定义强调色',
@@ -1032,6 +1063,7 @@ const zhCN: Messages = {
'sftp.upload.currentFile': '当前: {fileName}',
'sftp.upload.cancelled': '上传已取消',
'sftp.upload.cancel': '取消',
'sftp.upload.completedToPath': '已上传至 {path}',
// SFTP Download
'sftp.download.completed': '已下载',
@@ -1048,9 +1080,9 @@ const zhCN: Messages = {
// Settings > SFTP Show Hidden Files
'settings.sftp.showHiddenFiles': '显示隐藏文件',
'settings.sftp.showHiddenFiles.desc': '在浏览本地 Windows 文件系统时,显示具有 Windows 隐藏属性文件。',
'settings.sftp.showHiddenFiles.desc': '在 SFTP 文件浏览器中显示隐藏文件Unix/macOS 点文件和 Windows 隐藏属性文件。',
'settings.sftp.showHiddenFiles.enable': '显示隐藏文件',
'settings.sftp.showHiddenFiles.enableDesc': '浏览本地文件系统时显示 Windows 隐藏文件',
'settings.sftp.showHiddenFiles.enableDesc': '浏览本地和远程文件系统时显示隐藏文件',
// Settings > SFTP Compressed Upload
'settings.sftp.compressedUpload': '文件夹压缩传输',
@@ -1097,7 +1129,7 @@ const zhCN: Messages = {
'settings.terminal.behavior.rightClick.paste': '粘贴',
'settings.terminal.behavior.rightClick.selectWord': '选择单词',
'settings.terminal.behavior.copyOnSelect': '选择即复制',
'settings.terminal.behavior.copyOnSelect.desc': '自动复制选中的文本',
'settings.terminal.behavior.copyOnSelect.desc': '自动复制选中的文本。在 tmux/vim 鼠标模式下macOS 按住 OptionWindows/Linux 按住 Shift 拖选即可选中文本',
'settings.terminal.behavior.middleClickPaste': '中键粘贴',
'settings.terminal.behavior.middleClickPaste.desc': '中键点击时粘贴剪贴板内容',
'settings.terminal.behavior.bracketedPaste': '括号粘贴模式',

View File

@@ -22,7 +22,6 @@ type Listener = () => void;
class CustomThemeStore {
private themes: TerminalTheme[] = [];
private listeners = new Set<Listener>();
private loaded = false;
/** Cached merged array for stable useSyncExternalStore snapshots */
private cachedAllThemes: TerminalTheme[] | null = null;
@@ -40,7 +39,6 @@ class CustomThemeStore {
} catch {
// ignore corrupt data
}
this.loaded = true;
this.cachedAllThemes = null; // invalidate cache
};

View File

@@ -10,6 +10,7 @@ export interface SftpPane {
selectedFiles: Set<string>;
filter: string;
filenameEncoding: SftpFilenameEncoding;
showHiddenFiles: boolean;
}
// Multi-tab state for left and right sides
@@ -22,7 +23,10 @@ export interface SftpSideTabs {
export const EMPTY_LEFT_PANE_ID = "__empty_left__";
export const EMPTY_RIGHT_PANE_ID = "__empty_right__";
export const createEmptyPane = (id?: string): SftpPane => ({
export const createEmptyPane = (
id?: string,
showHiddenFiles = false,
): SftpPane => ({
id: id || crypto.randomUUID(),
connection: null,
files: [],
@@ -32,6 +36,7 @@ export const createEmptyPane = (id?: string): SftpPane => ({
selectedFiles: new Set(),
filter: "",
filenameEncoding: "auto",
showHiddenFiles,
});
// File watch event types
@@ -53,4 +58,5 @@ export interface SftpStateOptions {
onFileWatchSynced?: (event: FileWatchSyncedEvent) => void;
onFileWatchError?: (event: FileWatchErrorEvent) => void;
useCompressedUpload?: boolean;
defaultShowHiddenFiles?: boolean;
}

View File

@@ -27,7 +27,7 @@ interface UseSftpConnectionsParams {
reconnectingRef: MutableRefObject<{ left: boolean; right: boolean }>;
makeCacheKey: (connectionId: string, path: string, encoding?: SftpFilenameEncoding) => string;
clearCacheForConnection: (connectionId: string) => void;
createEmptyPane: (id?: string) => SftpPane;
createEmptyPane: (id?: string, showHiddenFiles?: boolean) => SftpPane;
}
interface UseSftpConnectionsResult {
@@ -346,6 +346,7 @@ export const useSftpConnections = ({
getActivePane,
updateTab,
clearCacheForConnection,
createEmptyPane,
makeCacheKey,
listLocalFiles,
listRemoteFiles,
@@ -412,7 +413,7 @@ export const useSftpConnections = ({
}
}
updateTab(side, activeTabId, () => createEmptyPane(activeTabId));
updateTab(side, activeTabId, () => createEmptyPane(activeTabId, pane.showHiddenFiles));
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[getActivePane, clearCacheForConnection, updateTab],

View File

@@ -1,4 +1,4 @@
import { useCallback } from "react";
import { useCallback, useRef } from "react";
import type { Host, SftpFileEntry, SftpFilenameEncoding } from "../../../domain/models";
import { netcattyBridge } from "../../../infrastructure/services/netcattyBridge";
import { logger } from "../../../lib/logger";
@@ -68,6 +68,18 @@ export const useSftpPaneActions = ({
isSessionError,
dirCacheTtlMs,
}: UseSftpPaneActionsParams): UseSftpPaneActionsResult => {
// Track the latest navigation request ID per tab, so we can distinguish
// whether a superseded request was superseded by the same tab or a different tab.
const tabNavSeqRef = useRef(new Map<string, number>());
// Track the last confirmed (successfully loaded) state per tab, so that
// restore-on-error/supersede always reverts to a known-good state rather
// than an intermediate optimistic state from another in-flight navigation.
// Includes connectionId so stale entries from a previous host are ignored.
const lastConfirmedRef = useRef(
new Map<string, { connectionId: string; path: string; files: SftpFileEntry[]; selectedFiles: Set<string> }>(),
);
const navigateTo = useCallback(
async (
side: "left" | "right",
@@ -92,8 +104,9 @@ export const useSftpPaneActions = ({
return;
}
const connectionId = pane.connection.id;
const requestId = ++navSeqRef.current[side];
const cacheKey = makeCacheKey(pane.connection.id, path, pane.filenameEncoding);
const cacheKey = makeCacheKey(connectionId, path, pane.filenameEncoding);
const cached = options?.force
? undefined
: dirCacheRef.current.get(cacheKey);
@@ -104,6 +117,13 @@ export const useSftpPaneActions = ({
cached.files
) {
console.log("[SFTP navigateTo] Using cached files for path", { path, cacheKey });
tabNavSeqRef.current.set(activeTabId, requestId);
lastConfirmedRef.current.set(activeTabId, {
connectionId,
path,
files: cached.files,
selectedFiles: new Set(),
});
updateTab(side, activeTabId, (prev) => ({
...prev,
connection: prev.connection
@@ -118,7 +138,36 @@ export const useSftpPaneActions = ({
}
console.log("[SFTP navigateTo] Fetching files from server for path", { path });
updateTab(side, activeTabId, (prev) => ({ ...prev, loading: true, error: null }));
// Re-seed confirmed state whenever the pane is settled (not loading), or
// when the connection has changed. This captures post-mutation state from
// optimistic updates (e.g. deleteFilesAtPath) so that a failed refresh
// doesn't resurrect deleted items.
const existing = lastConfirmedRef.current.get(activeTabId);
if (!existing || existing.connectionId !== connectionId || !pane.loading) {
lastConfirmedRef.current.set(activeTabId, {
connectionId,
path: pane.connection.currentPath,
files: pane.files,
selectedFiles: pane.selectedFiles,
});
}
const confirmed = lastConfirmedRef.current.get(activeTabId)!;
const previousPath = confirmed.path;
const previousFiles = confirmed.files;
const previousSelection = confirmed.selectedFiles;
tabNavSeqRef.current.set(activeTabId, requestId);
// Keep existing files visible during loading — the loading overlay
// (pointer-events-none) prevents interaction. This avoids blanking a tab
// that gets superseded by another tab navigating on the same side.
updateTab(side, activeTabId, (prev) => ({
...prev,
connection: prev.connection
? { ...prev.connection, currentPath: path }
: null,
selectedFiles: new Set(),
loading: true,
error: null,
}));
try {
let files: SftpFileEntry[];
@@ -164,13 +213,42 @@ export const useSftpPaneActions = ({
}
}
if (navSeqRef.current[side] !== requestId) return;
if (navSeqRef.current[side] !== requestId) {
// Another navigation on this side superseded this request.
// Only restore if no newer navigation has occurred on this specific tab
// AND the tab still belongs to the same connection (connect/disconnect
// bump navSeqRef but not tabNavSeqRef).
if (tabNavSeqRef.current.get(activeTabId) !== requestId) {
return;
}
updateTab(side, activeTabId, (prev) => {
if (prev.connection?.id !== connectionId) {
// Tab was reconnected or disconnected; don't restore stale state.
return prev;
}
return {
...prev,
connection: { ...prev.connection, currentPath: previousPath },
files: previousFiles,
selectedFiles: previousSelection,
loading: false,
};
});
return;
}
dirCacheRef.current.set(cacheKey, {
files,
timestamp: Date.now(),
});
lastConfirmedRef.current.set(activeTabId, {
connectionId,
path,
files,
selectedFiles: new Set(),
});
updateTab(side, activeTabId, (prev) => ({
...prev,
connection: prev.connection
@@ -181,13 +259,38 @@ export const useSftpPaneActions = ({
selectedFiles: new Set(),
}));
} catch (err) {
if (navSeqRef.current[side] !== requestId) return;
updateTab(side, activeTabId, (prev) => ({
...prev,
error:
err instanceof Error ? err.message : "Failed to list directory",
loading: false,
}));
if (navSeqRef.current[side] !== requestId) {
if (tabNavSeqRef.current.get(activeTabId) !== requestId) {
return;
}
updateTab(side, activeTabId, (prev) => {
if (prev.connection?.id !== connectionId) {
return prev;
}
return {
...prev,
connection: { ...prev.connection, currentPath: previousPath },
files: previousFiles,
selectedFiles: previousSelection,
loading: false,
};
});
return;
}
updateTab(side, activeTabId, (prev) => {
if (prev.connection?.id !== connectionId) {
return prev;
}
return {
...prev,
connection: { ...prev.connection, currentPath: previousPath },
files: previousFiles,
selectedFiles: previousSelection,
error:
err instanceof Error ? err.message : "Failed to list directory",
loading: false,
};
});
}
},
[

View File

@@ -14,6 +14,7 @@ export interface SftpTabsState {
getActivePane: (side: "left" | "right") => SftpPane | null;
updateTab: (side: "left" | "right", tabId: string, updater: (pane: SftpPane) => SftpPane) => void;
updateActiveTab: (side: "left" | "right", updater: (pane: SftpPane) => SftpPane) => void;
setTabShowHiddenFiles: (side: "left" | "right", tabId: string, showHiddenFiles: boolean) => void;
addTab: (side: "left" | "right") => string;
closeTab: (side: "left" | "right", tabId: string) => void;
selectTab: (side: "left" | "right", tabId: string) => void;
@@ -33,7 +34,11 @@ export interface SftpTabsState {
getActiveTabId: (side: "left" | "right") => string | null;
}
export const useSftpTabsState = (): SftpTabsState => {
export const useSftpTabsState = ({
defaultShowHiddenFiles = false,
}: {
defaultShowHiddenFiles?: boolean;
} = {}): SftpTabsState => {
const [leftTabs, setLeftTabs] = useState<SftpSideTabs>({
tabs: [],
activeTabId: null,
@@ -45,8 +50,10 @@ export const useSftpTabsState = (): SftpTabsState => {
const leftTabsRef = useRef(leftTabs);
const rightTabsRef = useRef(rightTabs);
const defaultShowHiddenFilesRef = useRef(defaultShowHiddenFiles);
leftTabsRef.current = leftTabs;
rightTabsRef.current = rightTabs;
defaultShowHiddenFilesRef.current = defaultShowHiddenFiles;
const getActivePane = useCallback((side: "left" | "right"): SftpPane | null => {
const sideTabs = side === "left" ? leftTabsRef.current : rightTabsRef.current;
@@ -58,14 +65,14 @@ export const useSftpTabsState = (): SftpTabsState => {
const pane = leftTabs.activeTabId
? leftTabs.tabs.find((t) => t.id === leftTabs.activeTabId)
: null;
return pane || createEmptyPane(EMPTY_LEFT_PANE_ID);
return pane || createEmptyPane(EMPTY_LEFT_PANE_ID, defaultShowHiddenFilesRef.current);
}, [leftTabs]);
const rightPane = useMemo(() => {
const pane = rightTabs.activeTabId
? rightTabs.tabs.find((t) => t.id === rightTabs.activeTabId)
: null;
return pane || createEmptyPane(EMPTY_RIGHT_PANE_ID);
return pane || createEmptyPane(EMPTY_RIGHT_PANE_ID, defaultShowHiddenFilesRef.current);
}, [rightTabs]);
const updateTab = useCallback(
@@ -88,9 +95,24 @@ export const useSftpTabsState = (): SftpTabsState => {
[updateTab],
);
const setTabShowHiddenFiles = useCallback(
(side: "left" | "right", tabId: string, showHiddenFiles: boolean) => {
updateTab(side, tabId, (prev) => {
if (prev.showHiddenFiles === showHiddenFiles) {
return prev;
}
return {
...prev,
showHiddenFiles,
};
});
},
[updateTab],
);
const addTab = useCallback(
(side: "left" | "right") => {
const newPane = createEmptyPane();
const newPane = createEmptyPane(undefined, defaultShowHiddenFilesRef.current);
const setTabs = side === "left" ? setLeftTabs : setRightTabs;
setTabs((prev) => ({
tabs: [...prev.tabs, newPane],
@@ -236,6 +258,7 @@ export const useSftpTabsState = (): SftpTabsState => {
getActivePane,
updateTab,
updateActiveTab,
setTabShowHiddenFiles,
addTab,
closeTab,
selectTab,

View File

@@ -15,7 +15,9 @@ import { netcattyBridge } from '../../infrastructure/services/netcattyBridge';
import {
findSyncPayloadEncryptedCredentialPaths,
} from '../../domain/credentials';
import type { SyncPayload } from '../../domain/sync';
import { isProviderReadyForSync, type CloudProvider, type SyncPayload } from '../../domain/sync';
import { STORAGE_KEY_PORT_FORWARDING } from '../../infrastructure/config/storageKeys';
import { localStorageAdapter } from '../../infrastructure/persistence/localStorageAdapter';
import { toast } from '../../components/ui/toast';
interface AutoSyncConfig {
@@ -25,6 +27,7 @@ interface AutoSyncConfig {
identities?: SyncPayload['identities'];
snippets: SyncPayload['snippets'];
customGroups: SyncPayload['customGroups'];
snippetPackages?: SyncPayload['snippetPackages'];
portForwardingRules?: SyncPayload['portForwardingRules'];
knownHosts?: SyncPayload['knownHosts'];
@@ -34,6 +37,7 @@ interface AutoSyncConfig {
// Get manager singleton for direct state access
const manager = getCloudSyncManager();
const AUTO_SYNC_PROVIDER_ORDER: CloudProvider[] = ['github', 'google', 'onedrive', 'webdav', 's3'];
type SyncTrigger = 'auto' | 'manual';
@@ -51,29 +55,65 @@ export const useAutoSync = (config: AutoSyncConfig) => {
// Build sync payload
const buildPayload = useCallback((): SyncPayload => {
// If port-forwarding hook state is still [] (async init in progress),
// fall back to localStorage to avoid uploading an empty array that
// overwrites the cloud snapshot.
let effectivePFRules = config.portForwardingRules;
if (!effectivePFRules || effectivePFRules.length === 0) {
const stored = localStorageAdapter.read<SyncPayload['portForwardingRules']>(
STORAGE_KEY_PORT_FORWARDING,
);
if (stored && Array.isArray(stored) && stored.length > 0) {
effectivePFRules = stored.map((rule) => ({
...rule,
status: 'inactive' as const,
error: undefined,
lastUsedAt: undefined,
}));
}
}
return {
hosts: config.hosts,
keys: config.keys,
identities: config.identities,
snippets: config.snippets,
customGroups: config.customGroups,
portForwardingRules: config.portForwardingRules,
snippetPackages: config.snippetPackages,
portForwardingRules: effectivePFRules,
knownHosts: config.knownHosts,
syncedAt: Date.now(),
};
}, [config.hosts, config.keys, config.identities, config.snippets, config.customGroups, config.portForwardingRules, config.knownHosts]);
}, [config.hosts, config.keys, config.identities, config.snippets, config.customGroups, config.snippetPackages, config.portForwardingRules, config.knownHosts]);
// Create a hash of current data for comparison
const getDataHash = useCallback(() => {
// Same fallback as buildPayload
let effectivePFRules = config.portForwardingRules;
if (!effectivePFRules || effectivePFRules.length === 0) {
const stored = localStorageAdapter.read<SyncPayload['portForwardingRules']>(
STORAGE_KEY_PORT_FORWARDING,
);
if (stored && Array.isArray(stored) && stored.length > 0) {
effectivePFRules = stored.map((rule) => ({
...rule,
status: 'inactive' as const,
error: undefined,
lastUsedAt: undefined,
}));
}
}
const data = {
hosts: config.hosts,
keys: config.keys,
identities: config.identities,
snippets: config.snippets,
portForwardingRules: config.portForwardingRules,
customGroups: config.customGroups,
snippetPackages: config.snippetPackages,
portForwardingRules: effectivePFRules,
knownHosts: config.knownHosts,
};
return JSON.stringify(data);
}, [config.hosts, config.keys, config.identities, config.snippets, config.portForwardingRules]);
}, [config.hosts, config.keys, config.identities, config.snippets, config.customGroups, config.snippetPackages, config.portForwardingRules, config.knownHosts]);
// Sync now handler - get fresh state directly from manager
const syncNow = useCallback(async (options?: SyncNowOptions) => {
@@ -83,7 +123,7 @@ export const useAutoSync = (config: AutoSyncConfig) => {
// Get fresh state directly from CloudSyncManager singleton
let state = manager.getState();
const hasProvider = Object.values(state.providers).some(p => p.status === 'connected');
const hasProvider = Object.values(state.providers).some((provider) => isProviderReadyForSync(provider));
const syncing = state.syncState === 'SYNCING';
if (!hasProvider) {
@@ -145,7 +185,7 @@ export const useAutoSync = (config: AutoSyncConfig) => {
// Check remote version and pull if newer (on startup)
const checkRemoteVersion = useCallback(async () => {
const state = manager.getState();
const hasProvider = Object.values(state.providers).some(p => p.status === 'connected');
const hasProvider = Object.values(state.providers).some((provider) => isProviderReadyForSync(provider));
const unlocked = state.securityState === 'UNLOCKED';
if (!hasProvider || !unlocked || hasCheckedRemoteRef.current) {
@@ -155,12 +195,9 @@ export const useAutoSync = (config: AutoSyncConfig) => {
hasCheckedRemoteRef.current = true;
// Find connected provider
const connectedProvider =
state.providers.github.status === 'connected' ? 'github' :
state.providers.google.status === 'connected' ? 'google' :
state.providers.onedrive.status === 'connected' ? 'onedrive' :
state.providers.webdav.status === 'connected' ? 'webdav' :
state.providers.s3.status === 'connected' ? 's3' : null;
const connectedProvider = AUTO_SYNC_PROVIDER_ORDER.find((provider) =>
isProviderReadyForSync(state.providers[provider]),
) ?? null;
if (!connectedProvider) return;

View File

@@ -21,6 +21,7 @@ import {
type S3Config,
formatLastSync,
getSyncDotColor,
isProviderReadyForSync,
} from '../../domain/sync';
import {
CloudSyncManager,
@@ -181,13 +182,13 @@ export const useCloudSync = (): CloudSyncHook => {
const hasAnyConnectedProvider = useMemo(() => {
return (Object.values(state.providers) as ProviderConnection[]).some(
(p) => p.status === 'connected' || p.status === 'syncing'
(p) => isProviderReadyForSync(p)
);
}, [state.providers]);
const connectedProviderCount = useMemo(() => {
return (Object.values(state.providers) as ProviderConnection[]).filter(
(p) => p.status === 'connected' || p.status === 'syncing'
(p) => isProviderReadyForSync(p)
).length;
}, [state.providers]);
@@ -519,7 +520,7 @@ export const useProviderStatus = (provider: CloudProvider) => {
return {
...connection,
isConnected: connection.status === 'connected',
isConnected: isProviderReadyForSync(connection),
isSyncing: connection.status === 'syncing',
hasError: connection.status === 'error',
dotColor: getSyncDotColor(connection.status),

View File

@@ -135,8 +135,6 @@ export const useGlobalHotkeys = ({
e.stopPropagation();
const currentActions = actionsRef.current;
const _tabs = orderedTabsRef.current;
switch (action) {
case 'switchToTab': {
const num = parseInt(e.key, 10);

View File

@@ -9,12 +9,25 @@ import { localStorageAdapter } from "../../infrastructure/persistence/localStora
import {
clearReconnectTimer,
getActiveConnection,
initReconnectCancelListener,
reconcileWithBackend,
startPortForward,
stopAllPortForwards,
stopAndCleanupRule,
stopPortForward,
syncWithBackend,
} from "../../infrastructure/services/portForwardingService";
import { useStoredViewMode, ViewMode } from "./useStoredViewMode";
// Module-level ref-counts: these side effects must run at most once per
// window, not per hook instance (the hook mounts from both App.tsx
// and PortForwardingNew.tsx). Ref-counting ensures the resources
// stay alive as long as ANY instance is mounted.
let reconnectCancelListenerRefs = 0;
let reconnectCancelCleanup: (() => void) | undefined;
let heartbeatRefs = 0;
let heartbeatIntervalId: ReturnType<typeof setInterval> | undefined;
export type { ViewMode };
export type SortMode = "az" | "za" | "newest" | "oldest";
@@ -177,6 +190,53 @@ export const usePortForwardingState = (): UsePortForwardingStateResult => {
return () => window.removeEventListener("storage", handleStorageChange);
}, []);
// Listen for cross-window reconnect cancellation events.
// Ref-counted so the listener stays alive as long as ANY hook
// instance is mounted (App.tsx outlives PortForwardingNew.tsx).
useEffect(() => {
reconnectCancelListenerRefs++;
let cleanup: (() => void) | undefined;
if (reconnectCancelListenerRefs === 1) {
cleanup = initReconnectCancelListener();
reconnectCancelCleanup = cleanup;
}
return () => {
reconnectCancelListenerRefs--;
if (reconnectCancelListenerRefs === 0 && reconnectCancelCleanup) {
reconnectCancelCleanup();
reconnectCancelCleanup = undefined;
}
};
}, []);
// Periodic heartbeat: reconcile renderer state with the backend every 4s.
// Ref-counted — same pattern as the reconnect cancel listener.
useEffect(() => {
heartbeatRefs++;
let intervalId: ReturnType<typeof setInterval> | undefined;
if (heartbeatRefs === 1) {
const HEARTBEAT_INTERVAL_MS = 4_000;
const tick = async () => {
const { gone, appeared } = await reconcileWithBackend();
if (gone.length === 0 && appeared.length === 0) return;
// Re-derive statuses from the now-updated activeConnections map
setGlobalRules(normalizeRulesWithConnections(globalRules));
};
intervalId = setInterval(tick, HEARTBEAT_INTERVAL_MS);
heartbeatIntervalId = intervalId;
}
return () => {
heartbeatRefs--;
if (heartbeatRefs === 0 && heartbeatIntervalId !== undefined) {
clearInterval(heartbeatIntervalId);
heartbeatIntervalId = undefined;
}
};
}, []);
const addRule = useCallback(
(
rule: Omit<PortForwardingRule, "id" | "createdAt" | "status">,
@@ -207,6 +267,8 @@ export const usePortForwardingState = (): UsePortForwardingStateResult => {
const deleteRule = useCallback(
(id: string) => {
// Stop any active tunnel before removing the rule
stopAndCleanupRule(id);
const updated = globalRules.filter((r) => r.id !== id);
setGlobalRules(updated);
if (selectedRuleId === id) {
@@ -238,6 +300,60 @@ export const usePortForwardingState = (): UsePortForwardingStateResult => {
);
const importRules = useCallback((newRules: PortForwardingRule[]) => {
// When clearing all rules (e.g. "Clear local data"), stop ALL tunnels
// and broadcast per-rule reconnect cancellation. stopAllPortForwards
// handles the backend, but we also need per-rule broadcasts so other
// windows cancel their pending reconnect timers.
if (newRules.length === 0) {
// Read from localStorage since globalRules may be empty (uninitialized)
const storedRules = localStorageAdapter.read<PortForwardingRule[]>(
STORAGE_KEY_PORT_FORWARDING,
);
const rulesToCancel = globalRules.length > 0
? globalRules
: (storedRules && Array.isArray(storedRules) ? storedRules : []);
for (const rule of rulesToCancel) {
stopAndCleanupRule(rule.id);
}
// Safety net: also stop anything the renderer doesn't know about
void stopAllPortForwards();
}
// Stop tunnels for rules that are being removed or whose connection
// config has changed (same ID but different host/port/type means the
// old tunnel is pointing at stale parameters and must be torn down).
//
// Use globalRules as the diff baseline. In a freshly opened settings
// window, globalRules may still be empty because initializeStore is
// async. Fall back to reading directly from localStorage to avoid
// missing tunnels that need to be stopped.
let diffBaseline = globalRules;
if (diffBaseline.length === 0 && newRules.length > 0) {
const stored = localStorageAdapter.read<PortForwardingRule[]>(
STORAGE_KEY_PORT_FORWARDING,
);
if (stored && Array.isArray(stored) && stored.length > 0) {
diffBaseline = stored;
}
}
const newRulesById = new Map(newRules.map((r) => [r.id, r]));
for (const existing of diffBaseline) {
const incoming = newRulesById.get(existing.id);
if (!incoming) {
// Rule removed entirely
stopAndCleanupRule(existing.id);
} else if (
existing.type !== incoming.type ||
existing.localPort !== incoming.localPort ||
existing.remoteHost !== incoming.remoteHost ||
existing.remotePort !== incoming.remotePort ||
existing.bindAddress !== incoming.bindAddress ||
existing.hostId !== incoming.hostId
) {
// Connection-relevant config changed — tear down the old tunnel
stopAndCleanupRule(existing.id);
}
}
setGlobalRules(normalizeRulesWithConnections(newRules));
}, []);

View File

@@ -1,5 +1,5 @@
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type SetStateAction } from 'react';
import { SyncConfig, TerminalSettings, DEFAULT_TERMINAL_SETTINGS, HotkeyScheme, CustomKeyBindings, DEFAULT_KEY_BINDINGS, KeyBinding, UILanguage, SessionLogFormat } from '../../domain/models';
import { SyncConfig, TerminalSettings, HotkeyScheme, CustomKeyBindings, DEFAULT_KEY_BINDINGS, KeyBinding, UILanguage, SessionLogFormat, normalizeTerminalSettings } from '../../domain/models';
import {
STORAGE_KEY_COLOR,
STORAGE_KEY_SYNC,
@@ -39,7 +39,13 @@ import { useAvailableFonts } from './fontStore';
import { localStorageAdapter } from '../../infrastructure/persistence/localStorageAdapter';
import { netcattyBridge } from '../../infrastructure/services/netcattyBridge';
const DEFAULT_THEME: 'light' | 'dark' = 'light';
const DEFAULT_THEME: 'light' | 'dark' | 'system' = 'system';
/** Resolve the current OS color scheme preference. */
const getSystemPreference = (): 'light' | 'dark' =>
typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light';
const DEFAULT_LIGHT_UI_THEME = 'snow';
const DEFAULT_DARK_UI_THEME = 'midnight';
const DEFAULT_ACCENT_MODE: 'theme' | 'custom' = 'theme';
@@ -77,7 +83,7 @@ const readStoredString = (key: string): string | null => {
}
};
const isValidTheme = (value: unknown): value is 'light' | 'dark' => value === 'light' || value === 'dark';
const isValidTheme = (value: unknown): value is 'light' | 'dark' | 'system' => value === 'light' || value === 'dark' || value === 'system';
const isValidHslToken = (value: string): boolean => {
// Expect: "<h> <s>% <l>%", e.g. "221.2 83.2% 53.3%"
@@ -104,14 +110,15 @@ const areTerminalSettingsEqual = (a: TerminalSettings, b: TerminalSettings): boo
serializeTerminalSettings(a) === serializeTerminalSettings(b);
const applyThemeTokens = (
theme: 'light' | 'dark',
themeSource: 'light' | 'dark' | 'system',
resolvedTheme: 'light' | 'dark',
tokens: UiThemeTokens,
accentMode: 'theme' | 'custom',
accentOverride: string,
) => {
const root = window.document.documentElement;
root.classList.remove('light', 'dark');
root.classList.add(theme);
root.classList.add(resolvedTheme);
root.style.setProperty('--background', tokens.background);
root.style.setProperty('--foreground', tokens.foreground);
root.style.setProperty('--card', tokens.card);
@@ -120,7 +127,7 @@ const applyThemeTokens = (
root.style.setProperty('--popover-foreground', tokens.popoverForeground);
const accentToken = accentMode === 'custom' ? accentOverride : tokens.accent;
const accentLightness = parseFloat(accentToken.split(/\s+/)[2]?.replace('%', '') || '');
const computedAccentForeground = theme === 'dark'
const computedAccentForeground = resolvedTheme === 'dark'
? '220 40% 96%'
: (!Number.isNaN(accentLightness) && accentLightness < 55 ? '0 0% 98%' : '222 47% 12%');
@@ -139,17 +146,21 @@ const applyThemeTokens = (
root.style.setProperty('--ring', accentToken);
// Sync with native window title bar (Electron)
netcattyBridge.get()?.setTheme?.(theme);
netcattyBridge.get()?.setTheme?.(themeSource);
netcattyBridge.get()?.setBackgroundColor?.(tokens.background);
};
export const useSettingsState = () => {
const availableFonts = useAvailableFonts();
const uiFontsLoaded = useUIFontsLoaded();
const [theme, setTheme] = useState<'dark' | 'light'>(() => {
const [theme, setTheme] = useState<'dark' | 'light' | 'system'>(() => {
const stored = readStoredString(STORAGE_KEY_THEME);
return stored && isValidTheme(stored) ? stored : DEFAULT_THEME;
});
// Track the OS color scheme preference (updated by matchMedia listener)
const [systemPreference, setSystemPreference] = useState<'light' | 'dark'>(getSystemPreference);
// resolvedTheme is always 'light' or 'dark' — derived synchronously from theme + OS preference
const resolvedTheme: 'light' | 'dark' = theme === 'system' ? systemPreference : theme;
const [lightUiThemeId, setLightUiThemeId] = useState<string>(() => {
const stored = readStoredString(STORAGE_KEY_UI_THEME_LIGHT);
return stored && isValidUiThemeId('light', stored) ? stored : DEFAULT_LIGHT_UI_THEME;
@@ -182,7 +193,7 @@ export const useSettingsState = () => {
});
const [terminalSettings, setTerminalSettingsState] = useState<TerminalSettings>(() => {
const stored = localStorageAdapter.read<TerminalSettings>(STORAGE_KEY_TERM_SETTINGS);
return stored ? { ...DEFAULT_TERMINAL_SETTINGS, ...stored } : DEFAULT_TERMINAL_SETTINGS;
return normalizeTerminalSettings(stored);
});
const [hotkeyScheme, setHotkeyScheme] = useState<HotkeyScheme>(() => {
const stored = localStorageAdapter.readString(STORAGE_KEY_HOTKEY_SCHEME);
@@ -260,9 +271,10 @@ export const useSettingsState = () => {
const setTerminalSettings = useCallback((nextValue: SetStateAction<TerminalSettings>) => {
setTerminalSettingsState((prev) => {
const next = typeof nextValue === 'function'
const candidate = typeof nextValue === 'function'
? (nextValue as (prevState: TerminalSettings) => TerminalSettings)(prev)
: nextValue;
const next = normalizeTerminalSettings(candidate);
if (areTerminalSettingsEqual(prev, next)) {
return prev;
}
@@ -273,7 +285,7 @@ export const useSettingsState = () => {
const mergeIncomingTerminalSettings = useCallback((incoming: Partial<TerminalSettings>) => {
setTerminalSettingsState((prev) => {
const next = { ...prev, ...incoming };
const next = normalizeTerminalSettings({ ...prev, ...incoming });
if (areTerminalSettingsEqual(prev, next)) {
return prev;
}
@@ -310,8 +322,9 @@ export const useSettingsState = () => {
setAccentMode(nextAccentMode);
setCustomAccent(nextAccent);
const tokens = getUiThemeById(nextTheme, nextTheme === 'dark' ? nextDarkId : nextLightId).tokens;
applyThemeTokens(nextTheme, tokens, nextAccentMode, nextAccent);
const effective = nextTheme === 'system' ? getSystemPreference() : nextTheme;
const tokens = getUiThemeById(effective, effective === 'dark' ? nextDarkId : nextLightId).tokens;
applyThemeTokens(nextTheme, effective, tokens, nextAccentMode, nextAccent);
}, [theme, lightUiThemeId, darkUiThemeId, accentMode, customAccent]);
const syncCustomCssFromStorage = useCallback(() => {
@@ -320,8 +333,8 @@ export const useSettingsState = () => {
}, []);
useLayoutEffect(() => {
const tokens = getUiThemeById(theme, theme === 'dark' ? darkUiThemeId : lightUiThemeId).tokens;
applyThemeTokens(theme, tokens, accentMode, customAccent);
const tokens = getUiThemeById(resolvedTheme, resolvedTheme === 'dark' ? darkUiThemeId : lightUiThemeId).tokens;
applyThemeTokens(theme, resolvedTheme, tokens, accentMode, customAccent);
localStorageAdapter.writeString(STORAGE_KEY_THEME, theme);
localStorageAdapter.writeString(STORAGE_KEY_UI_THEME_LIGHT, lightUiThemeId);
localStorageAdapter.writeString(STORAGE_KEY_UI_THEME_DARK, darkUiThemeId);
@@ -333,7 +346,18 @@ export const useSettingsState = () => {
notifySettingsChanged(STORAGE_KEY_UI_THEME_DARK, darkUiThemeId);
notifySettingsChanged(STORAGE_KEY_ACCENT_MODE, accentMode);
notifySettingsChanged(STORAGE_KEY_COLOR, customAccent);
}, [theme, lightUiThemeId, darkUiThemeId, accentMode, customAccent, notifySettingsChanged]);
}, [theme, resolvedTheme, lightUiThemeId, darkUiThemeId, accentMode, customAccent, notifySettingsChanged]);
// Listen for OS color scheme changes to keep systemPreference in sync
useEffect(() => {
if (typeof window === 'undefined' || !window.matchMedia) return;
const mql = window.matchMedia('(prefers-color-scheme: dark)');
const handler = (e: MediaQueryListEvent) => {
setSystemPreference(e.matches ? 'dark' : 'light');
};
mql.addEventListener('change', handler);
return () => mql.removeEventListener('change', handler);
}, []);
useLayoutEffect(() => {
localStorageAdapter.writeString(STORAGE_KEY_UI_LANGUAGE, uiLanguage);
@@ -522,7 +546,7 @@ export const useSettingsState = () => {
if (e.key === STORAGE_KEY_TERM_SETTINGS && e.newValue) {
try {
const newSettings = JSON.parse(e.newValue) as TerminalSettings;
mergeIncomingTerminalSettings({ ...DEFAULT_TERMINAL_SETTINGS, ...newSettings });
mergeIncomingTerminalSettings(newSettings);
} catch {
// ignore parse errors
}
@@ -823,6 +847,7 @@ export const useSettingsState = () => {
return {
theme,
setTheme,
resolvedTheme,
lightUiThemeId,
setLightUiThemeId,
darkUiThemeId,

View File

@@ -1,184 +0,0 @@
/**
* useSftpFileOperations - Shared file operations for SFTP components
*
* This hook provides common file operations like open, edit, preview
* that can be shared between SFTPModal and SftpView components.
*/
import { useCallback, useState } from "react";
import { getFileExtension, isTextFile, FileOpenerType } from "../../lib/sftpFileUtils";
import { toast } from "../../components/ui/toast";
import { useI18n } from "../i18n/I18nProvider";
import { useSftpFileAssociations } from "./useSftpFileAssociations";
export interface FileOperationsState {
// Text editor state
showTextEditor: boolean;
textEditorTarget: { name: string; fullPath: string } | null;
textEditorContent: string;
loadingTextContent: boolean;
// File opener dialog state
showFileOpenerDialog: boolean;
fileOpenerTarget: { name: string; fullPath: string } | null;
}
export interface FileOperationsActions {
// Open file based on type/association
openFile: (fileName: string, fullPath: string) => void;
// Edit text file
editFile: (
fileName: string,
fullPath: string,
readContent: () => Promise<string>
) => Promise<void>;
// Save text file
saveTextFile: (
content: string,
writeContent: (path: string, content: string) => Promise<void>
) => Promise<void>;
// Handle file opener selection
handleFileOpenerSelect: (
openerType: FileOpenerType,
setAsDefault: boolean,
readTextContent: () => Promise<string>,
readImageData: () => Promise<ArrayBuffer>
) => Promise<void>;
// Close modals
closeTextEditor: () => void;
closeFileOpenerDialog: () => void;
// Check if file can be edited
canEditFile: (fileName: string) => boolean;
}
export interface UseSftpFileOperationsResult {
state: FileOperationsState;
actions: FileOperationsActions;
}
export function useSftpFileOperations(): UseSftpFileOperationsResult {
const { t } = useI18n();
const { getOpenerForFile, setOpenerForExtension } = useSftpFileAssociations();
// Text editor state
const [showTextEditor, setShowTextEditor] = useState(false);
const [textEditorTarget, setTextEditorTarget] = useState<{ name: string; fullPath: string } | null>(null);
const [textEditorContent, setTextEditorContent] = useState("");
const [loadingTextContent, setLoadingTextContent] = useState(false);
// File opener dialog state
const [showFileOpenerDialog, setShowFileOpenerDialog] = useState(false);
const [fileOpenerTarget, setFileOpenerTarget] = useState<{ name: string; fullPath: string } | null>(null);
const canEditFile = useCallback((fileName: string) => {
return isTextFile(fileName);
}, []);
const closeTextEditor = useCallback(() => {
setShowTextEditor(false);
setTextEditorTarget(null);
setTextEditorContent("");
}, []);
const closeFileOpenerDialog = useCallback(() => {
setShowFileOpenerDialog(false);
setFileOpenerTarget(null);
}, []);
const editFile = useCallback(async (
fileName: string,
fullPath: string,
readContent: () => Promise<string>
) => {
try {
setLoadingTextContent(true);
setTextEditorTarget({ name: fileName, fullPath });
const content = await readContent();
setTextEditorContent(content);
setShowTextEditor(true);
} catch (e) {
toast.error(
e instanceof Error ? e.message : t("sftp.error.loadFailed"),
"SFTP",
);
} finally {
setLoadingTextContent(false);
}
}, [t]);
const saveTextFile = useCallback(async (
content: string,
writeContent: (path: string, content: string) => Promise<void>
) => {
if (!textEditorTarget) return;
await writeContent(textEditorTarget.fullPath, content);
}, [textEditorTarget]);
const openFile = useCallback((fileName: string, fullPath: string) => {
const savedOpener = getOpenerForFile(fileName);
if (savedOpener) {
// User has saved an opener for this file type
// We'll just set the target and let the caller handle it
setFileOpenerTarget({ name: fileName, fullPath });
// Return the opener type so caller knows which operation to perform
if (savedOpener === 'builtin-editor' && canEditFile(fileName)) {
// Don't show dialog, caller should call editFile
return 'edit' as const;
}
}
// No saved opener, show the dialog
setFileOpenerTarget({ name: fileName, fullPath });
setShowFileOpenerDialog(true);
return 'dialog' as const;
}, [getOpenerForFile, canEditFile]);
const handleFileOpenerSelect = useCallback(async (
openerType: FileOpenerType,
setAsDefault: boolean,
readTextContent: () => Promise<string>,
_readImageData: () => Promise<ArrayBuffer>
) => {
if (!fileOpenerTarget) return;
if (setAsDefault) {
const ext = getFileExtension(fileOpenerTarget.name);
if (ext !== 'file') {
setOpenerForExtension(ext, openerType);
}
}
setShowFileOpenerDialog(false);
if (openerType === 'builtin-editor') {
await editFile(fileOpenerTarget.name, fileOpenerTarget.fullPath, readTextContent);
}
}, [fileOpenerTarget, setOpenerForExtension, editFile]);
return {
state: {
showTextEditor,
textEditorTarget,
textEditorContent,
loadingTextContent,
showFileOpenerDialog,
fileOpenerTarget,
},
actions: {
openFile,
editFile,
saveTextFile,
handleFileOpenerSelect,
closeTextEditor,
closeFileOpenerDialog,
canEditFile,
},
};
}

View File

@@ -36,7 +36,15 @@ export const useSftpState = (
identities: Identity[],
options?: SftpStateOptions
) => {
const tabsState = useSftpTabsState();
const createPane = useCallback(
(id?: string, showHiddenFiles = options?.defaultShowHiddenFiles ?? false) =>
createEmptyPane(id, showHiddenFiles),
[options?.defaultShowHiddenFiles],
);
const tabsState = useSftpTabsState({
defaultShowHiddenFiles: options?.defaultShowHiddenFiles,
});
const {
leftTabs,
rightTabs,
@@ -49,6 +57,7 @@ export const useSftpState = (
getActivePane,
updateTab,
updateActiveTab,
setTabShowHiddenFiles,
addTab,
closeTab,
selectTab,
@@ -143,7 +152,7 @@ export const useSftpState = (
reconnectingRef,
makeCacheKey,
clearCacheForConnection,
createEmptyPane,
createEmptyPane: createPane,
});
const {
@@ -205,6 +214,13 @@ export const useSftpState = (
[clearCacheForConnection, getActivePane, navigateTo, updateActiveTab],
);
const setShowHiddenFiles = useCallback(
(side: "left" | "right", tabId: string, showHiddenFiles: boolean) => {
setTabShowHiddenFiles(side, tabId, showHiddenFiles);
},
[setTabShowHiddenFiles],
);
const {
transfers,
conflicts,
@@ -270,6 +286,7 @@ export const useSftpState = (
selectAll,
setFilter,
setFilenameEncoding,
setShowHiddenFiles,
createDirectory,
createFile,
deleteFiles,
@@ -315,6 +332,7 @@ export const useSftpState = (
selectAll,
setFilter,
setFilenameEncoding,
setShowHiddenFiles,
createDirectory,
createFile,
deleteFiles,
@@ -364,6 +382,8 @@ export const useSftpState = (
setFilter: (...args: Parameters<typeof setFilter>) => methodsRef.current.setFilter(...args),
setFilenameEncoding: (...args: Parameters<typeof setFilenameEncoding>) =>
methodsRef.current.setFilenameEncoding(...args),
setShowHiddenFiles: (...args: Parameters<typeof setShowHiddenFiles>) =>
methodsRef.current.setShowHiddenFiles(...args),
createDirectory: (...args: Parameters<typeof createDirectory>) => methodsRef.current.createDirectory(...args),
createFile: (...args: Parameters<typeof createFile>) => methodsRef.current.createFile(...args),
deleteFiles: (...args: Parameters<typeof deleteFiles>) => methodsRef.current.deleteFiles(...args),

View File

@@ -1,68 +0,0 @@
import { useCallback, useState } from "react";
import { loadFromGist, syncToGist } from "../../infrastructure/services/syncService";
export type SyncStatus = "idle" | "success" | "error";
export const useSyncState = () => {
const [isSyncing, setIsSyncing] = useState(false);
const [syncStatus, setSyncStatus] = useState<SyncStatus>("idle");
const resetSyncStatus = useCallback(() => {
setSyncStatus("idle");
}, []);
const verify = useCallback(async (token: string, gistId?: string) => {
setIsSyncing(true);
setSyncStatus("idle");
try {
if (gistId) {
await loadFromGist(token, gistId);
}
setSyncStatus("success");
} catch (err) {
setSyncStatus("error");
throw err;
} finally {
setIsSyncing(false);
}
}, []);
const upload = useCallback(
async (
token: string,
gistId: string | undefined,
data: Parameters<typeof syncToGist>[2],
) => {
setIsSyncing(true);
setSyncStatus("idle");
try {
const newGistId = await syncToGist(token, gistId, data);
setSyncStatus("success");
return newGistId;
} catch (err) {
setSyncStatus("error");
throw err;
} finally {
setIsSyncing(false);
}
},
[],
);
const download = useCallback(async (token: string, gistId: string) => {
setIsSyncing(true);
setSyncStatus("idle");
try {
const data = await loadFromGist(token, gistId);
setSyncStatus("success");
return data;
} catch (err) {
setSyncStatus("error");
throw err;
} finally {
setIsSyncing(false);
}
}, []);
return { isSyncing, syncStatus, resetSyncStatus, verify, upload, download };
};

View File

@@ -1,13 +1,17 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { checkForUpdates, getReleaseUrl, type ReleaseInfo, type UpdateCheckResult } from '../../infrastructure/services/updateService';
import { localStorageAdapter } from '../../infrastructure/persistence/localStorageAdapter';
import { STORAGE_KEY_UPDATE_DISMISSED_VERSION, STORAGE_KEY_UPDATE_LAST_CHECK } from '../../infrastructure/config/storageKeys';
import { STORAGE_KEY_UPDATE_DISMISSED_VERSION, STORAGE_KEY_UPDATE_LAST_CHECK, STORAGE_KEY_UPDATE_LATEST_RELEASE } from '../../infrastructure/config/storageKeys';
import { netcattyBridge } from '../../infrastructure/services/netcattyBridge';
// Check for updates at most once per hour
const UPDATE_CHECK_INTERVAL_MS = 60 * 60 * 1000;
// Delay startup check to avoid slowing down app launch
const STARTUP_CHECK_DELAY_MS = 5000;
// Delay startup check to avoid slowing down app launch.
// 8s gives electron-updater's startAutoCheck(5000) time to emit
// 'update-available' first. The `onUpdateAvailable` handler also cancels
// any pending startup timeout, so even on slow networks where the event
// arrives after 8s the duplicate check is avoided.
const STARTUP_CHECK_DELAY_MS = 8000;
// Enable demo mode for development (set via localStorage: localStorage.setItem('debug.updateDemo', '1'))
const IS_UPDATE_DEMO_MODE = typeof window !== 'undefined' &&
window.localStorage?.getItem('debug.updateDemo') === '1';
@@ -19,6 +23,10 @@ const debugLog = (...args: unknown[]) => {
}
};
export type AutoDownloadStatus = 'idle' | 'downloading' | 'ready' | 'error';
export type ManualCheckStatus = 'idle' | 'checking' | 'available' | 'up-to-date' | 'error';
export interface UpdateState {
isChecking: boolean;
hasUpdate: boolean;
@@ -26,6 +34,12 @@ export interface UpdateState {
latestRelease: ReleaseInfo | null;
error: string | null;
lastCheckedAt: number | null;
// Auto-download state — driven by electron-updater IPC events
autoDownloadStatus: AutoDownloadStatus;
downloadPercent: number;
downloadError: string | null;
/** Manual check state — driven by user clicking "Check for Updates" */
manualCheckStatus: ManualCheckStatus;
}
export interface UseUpdateCheckResult {
@@ -33,6 +47,7 @@ export interface UseUpdateCheckResult {
checkNow: () => Promise<UpdateCheckResult | null>;
dismissUpdate: () => void;
openReleasePage: () => void;
installUpdate: () => void;
}
/**
@@ -49,11 +64,44 @@ export function useUpdateCheck(): UseUpdateCheckResult {
latestRelease: null,
error: null,
lastCheckedAt: null,
autoDownloadStatus: 'idle',
downloadPercent: 0,
downloadError: null,
manualCheckStatus: 'idle',
});
const hasCheckedOnStartupRef = useRef(false);
const isCheckingRef = useRef(false);
const startupCheckTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// Track current version in a ref to avoid stale closure in checkNow
const currentVersionRef = useRef(updateState.currentVersion);
// Track autoDownloadStatus in a ref so checkNow always reads the latest value
const autoDownloadStatusRef = useRef<AutoDownloadStatus>('idle');
// Timer ref for auto-resetting manualCheckStatus='up-to-date' back to 'idle'
const manualCheckResetTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// Flag: true when we suppressed auto-download because the version was dismissed.
// Used to distinguish "idle because dismissed" from "idle because not hydrated yet"
// in the progress/downloaded/error callbacks.
const dismissedAutoDownloadRef = useRef(false);
// Keep currentVersionRef in sync so checkNow always reads the latest version
useEffect(() => {
currentVersionRef.current = updateState.currentVersion;
}, [updateState.currentVersion]);
// Keep autoDownloadStatusRef in sync so checkNow always reads the latest download state
useEffect(() => {
autoDownloadStatusRef.current = updateState.autoDownloadStatus;
}, [updateState.autoDownloadStatus]);
// Cleanup: clear any pending manualCheckStatus reset timer on unmount
useEffect(() => {
return () => {
if (manualCheckResetTimeoutRef.current) {
clearTimeout(manualCheckResetTimeoutRef.current);
}
};
}, []);
// Get current app version
useEffect(() => {
@@ -71,6 +119,136 @@ export function useUpdateCheck(): UseUpdateCheckResult {
void loadVersion();
}, []);
// Hydrate auto-download status from the main process so windows opened
// after the download started (e.g. Settings) immediately reflect the
// current state instead of showing stale 'idle'.
useEffect(() => {
const bridge = netcattyBridge.get();
void bridge?.getUpdateStatus?.().then((snapshot) => {
if (!snapshot || snapshot.status === 'idle') return;
// Respect dismissed versions: if the user dismissed this release,
// don't surface download progress/ready state in late-opening windows.
// Also set the dismissed ref so subsequent IPC events are suppressed.
const dismissedVersion = localStorageAdapter.readString(STORAGE_KEY_UPDATE_DISMISSED_VERSION);
if (snapshot.version && snapshot.version === dismissedVersion) {
dismissedAutoDownloadRef.current = true;
return;
}
setUpdateState((prev) => {
// Don't overwrite if the renderer already has a newer state
if (prev.autoDownloadStatus !== 'idle') return prev;
return {
...prev,
autoDownloadStatus: snapshot.status,
downloadPercent: snapshot.percent,
downloadError: snapshot.error,
// Use snapshot version if no release data or if versions differ
latestRelease: (!prev.latestRelease || (snapshot.version && prev.latestRelease.version !== snapshot.version)) ? (snapshot.version ? {
version: snapshot.version,
tagName: `v${snapshot.version}`,
name: `v${snapshot.version}`,
body: '',
htmlUrl: '',
publishedAt: new Date().toISOString(),
assets: [],
} : prev.latestRelease) : prev.latestRelease,
};
});
});
}, []);
// Subscribe to electron-updater auto-download IPC events.
// These fire automatically when autoDownload=true in the main process.
useEffect(() => {
const bridge = netcattyBridge.get();
// When electron-updater confirms no update in its feed, don't write
// STORAGE_KEY_UPDATE_LAST_CHECK — that would throttle the GitHub API
// fallback for an hour. Let performCheck write it on success so the
// GitHub check can still discover releases not yet in the updater feed.
const cleanupNotAvailable = bridge?.onUpdateNotAvailable?.(() => {
// No-op for now — the GitHub fallback will handle lastCheckedAt.
});
const cleanupAvailable = bridge?.onUpdateAvailable?.((info) => {
// Cancel any pending startup GitHub API check — electron-updater is
// now authoritative and we don't want a duplicate toast.
if (startupCheckTimeoutRef.current) {
clearTimeout(startupCheckTimeoutRef.current);
startupCheckTimeoutRef.current = null;
}
// Check if this version was dismissed by the user
const dismissedVersion = localStorageAdapter.readString(STORAGE_KEY_UPDATE_DISMISSED_VERSION);
const isDismissed = dismissedVersion === info.version;
if (isDismissed) {
dismissedAutoDownloadRef.current = true;
}
setUpdateState((prev) => ({
...prev,
hasUpdate: !isDismissed,
// Only transition to 'downloading' if the user hasn't dismissed this
// version — otherwise leave the status at 'idle' so no download
// progress/ready toast appears for a release they don't want.
autoDownloadStatus: isDismissed ? prev.autoDownloadStatus : 'downloading',
downloadPercent: isDismissed ? prev.downloadPercent : 0,
downloadError: isDismissed ? prev.downloadError : null,
// Use electron-updater's version if GitHub API hasn't resolved yet or
// if the updater reports a different version than the cached release.
latestRelease: (!prev.latestRelease || prev.latestRelease.version !== info.version) ? {
version: info.version,
tagName: `v${info.version}`,
name: `v${info.version}`,
body: info.releaseNotes || '',
htmlUrl: '',
publishedAt: info.releaseDate || new Date().toISOString(),
assets: [],
} : prev.latestRelease,
}));
});
const cleanupProgress = bridge?.onUpdateDownloadProgress?.((p) => {
// If we suppressed the download for a dismissed version, ignore progress.
if (dismissedAutoDownloadRef.current) return;
setUpdateState((prev) => ({
...prev,
autoDownloadStatus: 'downloading',
downloadPercent: Math.round(p.percent),
}));
});
const cleanupDownloaded = bridge?.onUpdateDownloaded?.(() => {
// If the download was for a dismissed version, don't transition to
// 'ready' — that would trigger the "Update ready" toast.
if (dismissedAutoDownloadRef.current) return;
setUpdateState((prev) => ({
...prev,
autoDownloadStatus: 'ready',
downloadPercent: 100,
}));
});
const cleanupError = bridge?.onUpdateError?.((payload) => {
// If we suppressed the download for a dismissed version, ignore errors.
if (dismissedAutoDownloadRef.current) return;
setUpdateState((prev) => ({
...prev,
autoDownloadStatus: 'error',
downloadError: payload.error,
}));
});
return () => {
cleanupNotAvailable?.();
cleanupAvailable?.();
cleanupProgress?.();
cleanupDownloaded?.();
cleanupError?.();
};
}, []);
const performCheck = useCallback(async (currentVersion: string): Promise<UpdateCheckResult | null> => {
debugLog('performCheck called', { currentVersion, IS_UPDATE_DEMO_MODE });
@@ -119,8 +297,16 @@ export function useUpdateCheck(): UseUpdateCheckResult {
debugLog('Latest release version:', result.latestRelease?.version);
const now = Date.now();
// Save last check time
localStorageAdapter.writeNumber(STORAGE_KEY_UPDATE_LAST_CHECK, now);
// Only advance last-check time and cache release on successful checks.
// Failed checks (result.error set, no latestRelease) must not update
// the timestamp — otherwise stale cached release data persists for an
// hour while the throttle prevents re-checking.
if (!result.error) {
localStorageAdapter.writeNumber(STORAGE_KEY_UPDATE_LAST_CHECK, now);
if (result.latestRelease) {
localStorageAdapter.writeString(STORAGE_KEY_UPDATE_LATEST_RELEASE, JSON.stringify(result.latestRelease));
}
}
// Check if this version was dismissed
const dismissedVersion = localStorageAdapter.readString(STORAGE_KEY_UPDATE_DISMISSED_VERSION);
@@ -156,11 +342,121 @@ export function useUpdateCheck(): UseUpdateCheckResult {
}
}, []);
const checkNow = useCallback(async () => {
// In demo mode, use fake version to allow checking
const version = IS_UPDATE_DEMO_MODE ? '0.0.1' : updateState.currentVersion;
return performCheck(version);
}, [performCheck, updateState.currentVersion]);
const checkNow = useCallback(async (): Promise<UpdateCheckResult | null> => {
// Prevent concurrent checks (performCheck owns isCheckingRef)
if (isCheckingRef.current) {
debugLog('checkNow: already checking, skipping');
return null;
}
// Cancel any pending startup auto-check to avoid racing with
// electron-updater's startAutoCheck — concurrent checkForUpdates()
// calls are rejected by electron-updater and would surface a false error.
if (startupCheckTimeoutRef.current) {
clearTimeout(startupCheckTimeoutRef.current);
startupCheckTimeoutRef.current = null;
}
// Clear any pending "up-to-date" auto-reset timer
if (manualCheckResetTimeoutRef.current) {
clearTimeout(manualCheckResetTimeoutRef.current);
manualCheckResetTimeoutRef.current = null;
}
// Reset dismissed flag so a manual retry can surface download events again
dismissedAutoDownloadRef.current = false;
// Immediately reflect 'checking' in the UI; reset download error so the user can retry
setUpdateState((prev) => {
// Eagerly sync the ref so the checkForUpdate gate below reads the updated value
if (prev.autoDownloadStatus === 'error') {
autoDownloadStatusRef.current = 'idle';
}
return {
...prev,
manualCheckStatus: 'checking',
error: null,
// P2: reset download error state so auto-download can retry on next available update
autoDownloadStatus: prev.autoDownloadStatus === 'error' ? 'idle' : prev.autoDownloadStatus,
downloadError: prev.autoDownloadStatus === 'error' ? null : prev.downloadError,
};
});
// Skip check for dev/invalid builds (demo mode overrides to '0.0.1' inside performCheck)
const effectiveVersion = IS_UPDATE_DEMO_MODE ? '0.0.1' : currentVersionRef.current;
if (!effectiveVersion || effectiveVersion === '0.0.0') {
// Dev/invalid build — can't determine update status, reset to idle
setUpdateState((prev) => ({
...prev,
manualCheckStatus: 'idle',
}));
return null;
}
// Delegate to performCheck (GitHub API) — completely independent of
// electron-updater's startAutoCheck() in the main process.
// performCheck sets isCheckingRef, isChecking, hasUpdate, latestRelease.
const result = await performCheck(effectiveVersion);
// Determine manual check status. performCheck already suppressed dismissed
// versions in state (hasUpdate=false), so we must respect that here too —
// otherwise a dismissed release would be reported as 'available' and could
// trigger a background download via checkForUpdate below.
const dismissedVersion = localStorageAdapter.readString(STORAGE_KEY_UPDATE_DISMISSED_VERSION);
const isAvailable = result !== null && !result.error && result.hasUpdate &&
result.latestRelease?.version !== dismissedVersion;
const nextStatus: ManualCheckStatus =
result === null || result.error ? 'error' : isAvailable ? 'available' : 'up-to-date';
setUpdateState((prev) => ({
...prev,
manualCheckStatus: nextStatus,
}));
if (nextStatus === 'up-to-date') {
// Auto-reset "up-to-date" badge back to idle after 5s
manualCheckResetTimeoutRef.current = setTimeout(() => {
setUpdateState((prev) => ({ ...prev, manualCheckStatus: 'idle' }));
}, 5000);
} else if ((nextStatus === 'available' || nextStatus === 'error') && autoDownloadStatusRef.current === 'idle') {
// Trigger electron-updater as a fallback. This covers two cases:
// 1. 'available': GitHub found an update but electron-updater hasn't
// started a download yet — kick it off.
// 2. 'error': GitHub API failed (blocked/rate-limited), but the
// electron-updater feed may still be reachable. Without this,
// environments where api.github.com is blocked would never attempt
// the auto-download path.
void netcattyBridge.get()?.checkForUpdate?.().then((res) => {
if (res?.error && res?.supported !== false) {
// Surface actual download-feed errors; unsupported platforms
// (res.supported === false) should keep autoDownloadStatus at
// 'idle' so the manual download link shows.
setUpdateState((prev) => ({
...prev,
autoDownloadStatus: 'error',
downloadError: res.error,
}));
} else if (res?.checking) {
// Another check is already in flight — don't change status; the
// in-flight check will resolve via IPC events.
} else if (nextStatus === 'error' && !res?.error && !res?.available) {
// GitHub API failed but electron-updater says no update available.
// Clear the error status so Settings doesn't stay stuck in error state.
setUpdateState((prev) => ({
...prev,
manualCheckStatus: 'up-to-date',
}));
manualCheckResetTimeoutRef.current = setTimeout(() => {
setUpdateState((prev) => ({ ...prev, manualCheckStatus: 'idle' }));
}, 5000);
}
}).catch(() => {
// Bridge unavailable — ignore; the manual download link remains visible
});
}
return result;
}, [performCheck]);
const dismissUpdate = useCallback(() => {
if (updateState.latestRelease?.version) {
@@ -189,6 +485,10 @@ export function useUpdateCheck(): UseUpdateCheckResult {
window.open(url, '_blank', 'noopener,noreferrer');
}, [updateState.latestRelease]);
const installUpdate = useCallback(() => {
netcattyBridge.get()?.installUpdate?.();
}, []);
// Startup check with delay - runs once on mount
useEffect(() => {
debugLog('Startup check effect mounted, IS_UPDATE_DEMO_MODE:', IS_UPDATE_DEMO_MODE);
@@ -238,13 +538,60 @@ export function useUpdateCheck(): UseUpdateCheckResult {
const now = Date.now();
if (lastCheck && now - lastCheck < UPDATE_CHECK_INTERVAL_MS) {
hasCheckedOnStartupRef.current = true;
// Hydrate cached release info so late-opening windows show the result
const cachedRelease = localStorageAdapter.readString(STORAGE_KEY_UPDATE_LATEST_RELEASE);
if (cachedRelease) {
try {
const release = JSON.parse(cachedRelease) as ReleaseInfo;
const dismissedVersion = localStorageAdapter.readString(STORAGE_KEY_UPDATE_DISMISSED_VERSION);
const isNewer = updateState.currentVersion.localeCompare(release.version, undefined, { numeric: true, sensitivity: 'base' }) < 0;
const showUpdate = isNewer && release.version !== dismissedVersion;
setUpdateState((prev) => ({
...prev,
latestRelease: prev.latestRelease ?? release,
hasUpdate: prev.hasUpdate || showUpdate,
lastCheckedAt: lastCheck,
}));
} catch {
// Ignore corrupted cache
}
}
return;
}
hasCheckedOnStartupRef.current = true;
debugLog('Starting delayed update check for version:', updateState.currentVersion);
startupCheckTimeoutRef.current = setTimeout(() => {
startupCheckTimeoutRef.current = setTimeout(async () => {
// If electron-updater's auto-check already started a download, skip the
// redundant GitHub API check to avoid duplicate toast notifications.
if (autoDownloadStatusRef.current !== 'idle') {
debugLog('Skipping startup check — auto-download already active');
return;
}
// If the main process check is still in flight, reschedule the
// fallback instead of permanently skipping it — the auto-check may
// fail silently (check-phase errors aren't broadcast to the renderer).
try {
const snapshot = await netcattyBridge.get()?.getUpdateStatus?.();
if (snapshot?.isChecking) {
debugLog('Main process check still in flight — rescheduling fallback');
startupCheckTimeoutRef.current = setTimeout(async () => {
if (autoDownloadStatusRef.current !== 'idle') return;
// Re-check if the main process check is still running to avoid
// duplicate notifications on very slow networks.
try {
const snap = await netcattyBridge.get()?.getUpdateStatus?.();
if (snap?.isChecking || (snap?.status && snap.status !== 'idle')) return;
} catch { /* fall through */ }
debugLog('=== Rescheduled fallback check triggered ===');
void performCheck(updateState.currentVersion);
}, 5000);
return;
}
} catch {
// Bridge unavailable — fall through to GitHub check
}
debugLog('=== Delayed check triggered ===');
void performCheck(updateState.currentVersion);
}, STARTUP_CHECK_DELAY_MS);
@@ -261,5 +608,6 @@ export function useUpdateCheck(): UseUpdateCheckResult {
checkNow,
dismissUpdate,
openReleasePage,
installUpdate,
};
}

View File

@@ -44,6 +44,7 @@ type ExportableVaultData = {
identities?: Identity[];
snippets: Snippet[];
customGroups: string[];
snippetPackages?: string[];
knownHosts?: KnownHost[];
};
@@ -557,9 +558,10 @@ export const useVaultState = () => {
identities,
snippets,
customGroups,
snippetPackages,
knownHosts,
}),
[hosts, keys, identities, snippets, customGroups, knownHosts],
[hosts, keys, identities, snippets, customGroups, snippetPackages, knownHosts],
);
const importData = useCallback(
@@ -569,6 +571,7 @@ export const useVaultState = () => {
if (payload.identities) updateIdentities(payload.identities);
if (payload.snippets) updateSnippets(payload.snippets);
if (payload.customGroups) updateCustomGroups(payload.customGroups);
if (payload.snippetPackages) updateSnippetPackages(payload.snippetPackages);
if (payload.knownHosts) updateKnownHosts(payload.knownHosts);
},
[
@@ -577,6 +580,7 @@ export const useVaultState = () => {
updateIdentities,
updateSnippets,
updateCustomGroups,
updateSnippetPackages,
updateKnownHosts,
],
);

View File

@@ -1,309 +0,0 @@
import { ChevronDown, Eye, EyeOff, Key, Lock, User } from "lucide-react";
import React, { useState } from "react";
import { useI18n } from "../application/i18n/I18nProvider";
import { cn } from "../lib/utils";
import { Host, SSHKey } from "../types";
import { DistroAvatar } from "./DistroAvatar";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
import { ScrollArea } from "./ui/scroll-area";
interface AuthDialogProps {
host: Host;
keys: SSHKey[];
onSubmit: (auth: {
username: string;
authMethod: "password" | "key";
password?: string;
keyId?: string;
saveCredentials: boolean;
}) => void;
onCancel: () => void;
}
const AuthDialog: React.FC<AuthDialogProps> = ({
host,
keys,
onSubmit,
onCancel,
}) => {
const { t } = useI18n();
const [username, setUsername] = useState(host.username || "root");
const [authMethod, setAuthMethod] = useState<"password" | "key">("password");
const [password, setPassword] = useState("");
const [selectedKeyId, setSelectedKeyId] = useState<string | null>(null);
const [showPassword, setShowPassword] = useState(false);
const [saveCredentials, setSaveCredentials] = useState(true);
const [isKeySelectOpen, setIsKeySelectOpen] = useState(false);
const _selectedKey = keys.find((k) => k.id === selectedKeyId);
const handleSubmit = () => {
onSubmit({
username,
authMethod,
password: authMethod === "password" ? password : undefined,
keyId: authMethod === "key" ? (selectedKeyId ?? undefined) : undefined,
saveCredentials,
});
};
const isValid =
username.trim() &&
((authMethod === "password" && password.trim()) ||
(authMethod === "key" && selectedKeyId));
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm">
<div className="w-[420px] max-w-[90vw] bg-background border border-border/60 rounded-2xl shadow-2xl animate-in fade-in-0 zoom-in-95 duration-200">
{/* Header */}
<div className="px-6 py-5 border-b border-border/50">
<div className="flex items-center gap-3">
<DistroAvatar
host={host}
fallback={host.label.slice(0, 2).toUpperCase()}
className="h-12 w-12"
/>
<div>
<h2 className="text-base font-semibold">{host.label}</h2>
<p className="text-xs text-muted-foreground font-mono">
SSH {host.hostname}:{host.port || 22}
</p>
</div>
</div>
</div>
{/* Progress indicator */}
<div className="px-6 py-4">
<div className="flex items-center gap-3">
<div className="h-8 w-8 rounded-full bg-primary text-primary-foreground flex items-center justify-center">
<User size={14} />
</div>
<div className="flex-1 h-0.5 bg-muted" />
<div
className={cn(
"h-8 w-8 rounded-full flex items-center justify-center transition-colors",
username.trim()
? "bg-primary/20 text-primary"
: "bg-muted text-muted-foreground",
)}
>
{authMethod === "password" ? (
<Lock size={14} />
) : (
<Key size={14} />
)}
</div>
<div className="flex-1 h-0.5 bg-muted" />
<div className="h-8 w-8 rounded-full bg-muted text-muted-foreground flex items-center justify-center text-xs font-mono">
{">_"}
</div>
</div>
</div>
{/* Auth method tabs */}
<div className="px-6">
<div className="flex gap-1 p-1 bg-secondary/80 rounded-lg border border-border/60">
<button
className={cn(
"flex-1 flex items-center justify-center gap-2 py-2 text-sm font-medium rounded-md transition-all",
authMethod === "password"
? "bg-primary text-primary-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground hover:bg-secondary",
)}
onClick={() => setAuthMethod("password")}
>
<Lock size={14} />
{t("terminal.auth.password")}
</button>
<button
className={cn(
"flex-1 flex items-center justify-center gap-2 py-2 text-sm font-medium rounded-md transition-all",
authMethod === "key"
? "bg-primary text-primary-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground hover:bg-secondary",
)}
onClick={() => setAuthMethod("key")}
>
<Key size={14} />
{t("terminal.auth.sshKey")}
</button>
</div>
</div>
{/* Form */}
<div className="px-6 py-4 space-y-4">
{/* Username field (shown when no username on host) */}
{!host.username && (
<div className="space-y-2">
<Label htmlFor="auth-username">{t("terminal.auth.username")}</Label>
<Input
id="auth-username"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder={t("terminal.auth.username.placeholder")}
autoFocus
/>
</div>
)}
{/* Password field */}
{authMethod === "password" && (
<div className="space-y-2">
<Label htmlFor="auth-password">
{t("terminal.auth.passwordLabel")}
</Label>
<div className="relative">
<Input
id="auth-password"
type={showPassword ? "text" : "password"}
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder={t("terminal.auth.password.placeholder")}
className="pr-10"
autoFocus={!!host.username}
onKeyDown={(e) => {
if (e.key === "Enter" && isValid) {
handleSubmit();
}
}}
/>
<button
type="button"
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
onClick={() => setShowPassword(!showPassword)}
>
{showPassword ? <EyeOff size={16} /> : <Eye size={16} />}
</button>
</div>
</div>
)}
{/* Key selection */}
{authMethod === "key" && (
<div className="space-y-2">
<Label>{t("terminal.auth.selectKey")}</Label>
{keys.length === 0 ? (
<div className="text-sm text-muted-foreground p-3 border border-dashed border-border/60 rounded-lg text-center">
{t("terminal.auth.noKeysHint")}
</div>
) : (
<div className="space-y-2">
{keys
.filter((k) => k.category === "key")
.slice(0, 5)
.map((key) => (
<button
key={key.id}
className={cn(
"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-colors text-left",
selectedKeyId === key.id
? "border-primary bg-primary/5"
: "border-border/50 hover:bg-secondary/50",
)}
onClick={() => setSelectedKeyId(key.id)}
>
<div
className={cn(
"h-8 w-8 rounded-lg flex items-center justify-center",
"bg-primary/20 text-primary",
)}
>
<Key size={14} />
</div>
<div className="flex-1 min-w-0">
<div className="text-sm font-medium truncate">
{key.label}
</div>
<div className="text-xs text-muted-foreground">
{t("auth.keyType", { type: key.type })}
</div>
</div>
</button>
))}
{keys.filter((k) => k.category === "key").length > 5 && (
<Popover
open={isKeySelectOpen}
onOpenChange={setIsKeySelectOpen}
>
<PopoverTrigger asChild>
<Button variant="outline" className="w-full">
{t("auth.showAllKeys")}
<ChevronDown size={14} className="ml-2" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-80 p-0">
<ScrollArea className="h-64">
<div className="p-2 space-y-1">
{keys
.filter((k) => k.category === "key")
.map((key) => (
<button
key={key.id}
className={cn(
"w-full flex items-center gap-2 px-2 py-2 rounded-md text-left transition-colors",
selectedKeyId === key.id
? "bg-primary/10"
: "hover:bg-secondary",
)}
onClick={() => {
setSelectedKeyId(key.id);
setIsKeySelectOpen(false);
}}
>
<Key size={14} className="text-primary" />
<span className="text-sm truncate">
{key.label}
</span>
<span className="text-xs text-muted-foreground ml-auto">
{key.type}
</span>
</button>
))}
</div>
</ScrollArea>
</PopoverContent>
</Popover>
)}
</div>
)}
</div>
)}
</div>
{/* Footer */}
<div className="px-6 py-4 border-t border-border/50 flex items-center justify-between">
<Button variant="secondary" onClick={onCancel}>
{t("common.close")}
</Button>
<div className="flex items-center gap-2">
<Popover>
<PopoverTrigger asChild>
<Button disabled={!isValid} onClick={handleSubmit}>
{t("terminal.auth.continueSave")}
<ChevronDown size={14} className="ml-2" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-40 p-1" align="end">
<button
className="w-full px-3 py-2 text-sm text-left hover:bg-secondary rounded-md"
onClick={() => {
setSaveCredentials(false);
handleSubmit();
}}
disabled={!isValid}
>
{t("common.continue")}
</button>
</PopoverContent>
</Popover>
</div>
</div>
</div>
</div>
);
};
export default AuthDialog;

View File

@@ -35,7 +35,7 @@ import { useI18n } from '../application/i18n/I18nProvider';
import {
findSyncPayloadEncryptedCredentialPaths,
} from '../domain/credentials';
import type { CloudProvider, ConflictInfo, SyncPayload, WebDAVAuthType, WebDAVConfig, S3Config } from '../domain/sync';
import { isProviderReadyForSync, type CloudProvider, type ConflictInfo, type SyncPayload, type WebDAVAuthType, type WebDAVConfig, type S3Config } from '../domain/sync';
import { cn } from '../lib/utils';
import { Button } from './ui/button';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from './ui/dialog';
@@ -681,10 +681,9 @@ export const SyncDashboard: React.FC<SyncDashboardProps> = ({
const disconnectOtherProviders = async (current: CloudProvider) => {
const providers: CloudProvider[] = ['github', 'google', 'onedrive', 'webdav', 's3'];
const isActive = (status: string) => status === 'connected' || status === 'syncing';
for (const provider of providers) {
if (provider === current) continue;
if (isActive(sync.providers[provider].status)) {
if (isProviderReadyForSync(sync.providers[provider])) {
await sync.disconnectProvider(provider);
}
}
@@ -1061,13 +1060,13 @@ export const SyncDashboard: React.FC<SyncDashboardProps> = ({
provider="github"
name="GitHub Gist"
icon={<Github size={24} />}
isConnected={sync.providers.github.status === 'connected' || sync.providers.github.status === 'syncing'}
isConnected={isProviderReadyForSync(sync.providers.github)}
isSyncing={sync.providers.github.status === 'syncing'}
isConnecting={sync.providers.github.status === 'connecting'}
account={sync.providers.github.account}
lastSync={sync.providers.github.lastSync}
error={sync.providers.github.error}
disabled={sync.hasAnyConnectedProvider && sync.providers.github.status !== 'connected' && sync.providers.github.status !== 'syncing'}
disabled={sync.hasAnyConnectedProvider && !isProviderReadyForSync(sync.providers.github)}
onConnect={handleConnectGitHub}
onDisconnect={() => sync.disconnectProvider('github')}
onSync={() => handleSync('github')}
@@ -1077,13 +1076,13 @@ export const SyncDashboard: React.FC<SyncDashboardProps> = ({
provider="google"
name="Google Drive"
icon={<GoogleDriveIcon className="w-6 h-6" />}
isConnected={sync.providers.google.status === 'connected' || sync.providers.google.status === 'syncing'}
isConnected={isProviderReadyForSync(sync.providers.google)}
isSyncing={sync.providers.google.status === 'syncing'}
isConnecting={sync.providers.google.status === 'connecting'}
account={sync.providers.google.account}
lastSync={sync.providers.google.lastSync}
error={sync.providers.google.error}
disabled={sync.hasAnyConnectedProvider && sync.providers.google.status !== 'connected' && sync.providers.google.status !== 'syncing'}
disabled={sync.hasAnyConnectedProvider && !isProviderReadyForSync(sync.providers.google)}
onConnect={handleConnectGoogle}
onDisconnect={() => sync.disconnectProvider('google')}
onSync={() => handleSync('google')}
@@ -1093,13 +1092,13 @@ export const SyncDashboard: React.FC<SyncDashboardProps> = ({
provider="onedrive"
name="Microsoft OneDrive"
icon={<OneDriveIcon className="w-6 h-6" />}
isConnected={sync.providers.onedrive.status === 'connected' || sync.providers.onedrive.status === 'syncing'}
isConnected={isProviderReadyForSync(sync.providers.onedrive)}
isSyncing={sync.providers.onedrive.status === 'syncing'}
isConnecting={sync.providers.onedrive.status === 'connecting'}
account={sync.providers.onedrive.account}
lastSync={sync.providers.onedrive.lastSync}
error={sync.providers.onedrive.error}
disabled={sync.hasAnyConnectedProvider && sync.providers.onedrive.status !== 'connected' && sync.providers.onedrive.status !== 'syncing'}
disabled={sync.hasAnyConnectedProvider && !isProviderReadyForSync(sync.providers.onedrive)}
onConnect={handleConnectOneDrive}
onDisconnect={() => sync.disconnectProvider('onedrive')}
onSync={() => handleSync('onedrive')}
@@ -1109,13 +1108,13 @@ export const SyncDashboard: React.FC<SyncDashboardProps> = ({
provider="webdav"
name={t('cloudSync.provider.webdav')}
icon={<Server size={24} />}
isConnected={sync.providers.webdav.status === 'connected' || sync.providers.webdav.status === 'syncing'}
isConnected={isProviderReadyForSync(sync.providers.webdav)}
isSyncing={sync.providers.webdav.status === 'syncing'}
isConnecting={sync.providers.webdav.status === 'connecting'}
account={sync.providers.webdav.account}
lastSync={sync.providers.webdav.lastSync}
error={sync.providers.webdav.error}
disabled={sync.hasAnyConnectedProvider && sync.providers.webdav.status !== 'connected' && sync.providers.webdav.status !== 'syncing'}
disabled={sync.hasAnyConnectedProvider && !isProviderReadyForSync(sync.providers.webdav)}
onEdit={openWebdavDialog}
onConnect={openWebdavDialog}
onDisconnect={() => sync.disconnectProvider('webdav')}
@@ -1126,13 +1125,13 @@ export const SyncDashboard: React.FC<SyncDashboardProps> = ({
provider="s3"
name={t('cloudSync.provider.s3')}
icon={<Database size={24} />}
isConnected={sync.providers.s3.status === 'connected' || sync.providers.s3.status === 'syncing'}
isConnected={isProviderReadyForSync(sync.providers.s3)}
isSyncing={sync.providers.s3.status === 'syncing'}
isConnecting={sync.providers.s3.status === 'connecting'}
account={sync.providers.s3.account}
lastSync={sync.providers.s3.lastSync}
error={sync.providers.s3.error}
disabled={sync.hasAnyConnectedProvider && sync.providers.s3.status !== 'connected' && sync.providers.s3.status !== 'syncing'}
disabled={sync.hasAnyConnectedProvider && !isProviderReadyForSync(sync.providers.s3)}
onEdit={openS3Dialog}
onConnect={openS3Dialog}
onDisconnect={() => sync.disconnectProvider('s3')}

View File

@@ -17,6 +17,7 @@ export const DISTRO_LOGOS: Record<string, string> = {
redhat: "/distro/redhat.svg",
oracle: "/distro/oracle.svg",
kali: "/distro/kali.svg",
almalinux: "/distro/almalinux.svg",
};
export const DISTRO_COLORS: Record<string, string> = {
@@ -32,6 +33,7 @@ export const DISTRO_COLORS: Record<string, string> = {
redhat: "bg-[#EE0000]",
oracle: "bg-[#C74634]",
kali: "bg-[#0F6DB3]",
almalinux: "bg-[#173B66]",
default: "bg-slate-600",
};

View File

@@ -1,107 +0,0 @@
import { ChevronRight,Folder,FolderOpen,FolderPlus,Plus } from 'lucide-react';
import React,{ useMemo } from 'react';
import { useI18n } from '../application/i18n/I18nProvider';
import { cn } from '../lib/utils';
import { GroupNode } from '../types';
import { Collapsible,CollapsibleContent,CollapsibleTrigger } from './ui/collapsible';
import { ContextMenu,ContextMenuContent,ContextMenuItem,ContextMenuTrigger } from './ui/context-menu';
interface GroupTreeItemProps {
node: GroupNode;
depth: number;
expandedPaths: Set<string>;
onToggle: (path: string) => void;
onSelectGroup: (path: string) => void;
selectedGroup: string | null;
onEditGroup: (path: string) => void;
onNewHost: (path: string) => void;
onNewSubfolder: (path: string) => void;
isManagedGroup?: (path: string) => boolean;
}
export const GroupTreeItem: React.FC<GroupTreeItemProps> = ({
node,
depth,
expandedPaths,
onToggle,
onSelectGroup,
selectedGroup,
onEditGroup,
onNewHost,
onNewSubfolder,
}) => {
const { t } = useI18n();
const isExpanded = expandedPaths.has(node.path);
const hasChildren = node.children && Object.keys(node.children).length > 0;
const paddingLeft = `${depth * 12 + 12}px`;
const isSelected = selectedGroup === node.path;
const childNodes = useMemo(() => {
return node.children
? (Object.values(node.children) as unknown as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name))
: [];
}, [node.children]);
return (
<Collapsible open={isExpanded} onOpenChange={() => onToggle(node.path)}>
<ContextMenu>
<ContextMenuTrigger>
<CollapsibleTrigger asChild>
<div
className={cn(
"flex items-center py-1.5 pr-2 text-sm font-medium cursor-pointer transition-colors select-none group relative rounded-r-md",
isSelected ? "bg-primary/10 text-primary border-l-2 border-primary" : "text-muted-foreground hover:bg-muted/50 hover:text-foreground"
)}
style={{ paddingLeft }}
onClick={() => onSelectGroup(node.path)}
>
<div className="mr-1.5 flex-shrink-0 w-4 h-4 flex items-center justify-center">
{hasChildren && (
<div className={cn("transition-transform duration-200", isExpanded ? "rotate-90" : "")}>
<ChevronRight size={12} />
</div>
)}
</div>
<div className="mr-2 text-primary/80 group-hover:text-primary transition-colors">
{isExpanded ? <FolderOpen size={16} /> : <Folder size={16} />}
</div>
<span className="truncate flex-1">{node.name}</span>
{node.hosts.length > 0 && (
<span className="text-[10px] opacity-70 bg-background/50 px-1.5 rounded-full border border-border">
{node.hosts.length}
</span>
)}
</div>
</CollapsibleTrigger>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem onClick={() => onNewHost(node.path)}>
<Plus className="mr-2 h-4 w-4" /> {t("action.newHost")}
</ContextMenuItem>
<ContextMenuItem onClick={() => onNewSubfolder(node.path)}>
<FolderPlus className="mr-2 h-4 w-4" /> {t("action.newSubfolder")}
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
{hasChildren && (
<CollapsibleContent>
{childNodes.map((child) => (
<GroupTreeItem
key={child.path}
node={child}
depth={depth + 1}
expandedPaths={expandedPaths}
onToggle={onToggle}
onSelectGroup={onSelectGroup}
selectedGroup={selectedGroup}
onEditGroup={onEditGroup}
onNewHost={onNewHost}
onNewSubfolder={onNewSubfolder}
/>
))}
</CollapsibleContent>
)}
</Collapsible>
);
};

View File

@@ -156,13 +156,6 @@ const HostDetailsPanel: React.FC<HostDetailsPanelProps> = ({
// Group input state for inline creation suggestion
const [groupInputValue, setGroupInputValue] = useState(form.group || "");
// Check if the entered group is new (doesn't exist)
// Reserved for future use: showing inline "create new group" suggestion
const _isNewGroup = useMemo(() => {
const trimmed = groupInputValue.trim();
return trimmed.length > 0 && !groups.includes(trimmed);
}, [groupInputValue, groups]);
useEffect(() => {
if (initialData) {
// Ensure telnetEnabled is set when protocol is telnet

View File

@@ -1,382 +0,0 @@
import { Key, Lock, Plus, Save, Server, X } from "lucide-react";
import React, { useEffect, useState } from "react";
import { useI18n } from "../application/i18n/I18nProvider";
import { cn } from "../lib/utils";
import { Host, SSHKey } from "../types";
import { Button } from "./ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "./ui/dialog";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
import { Switch } from "./ui/switch";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "./ui/select";
interface HostFormProps {
initialData?: Host | null;
availableKeys: SSHKey[];
groups: string[];
onSave: (host: Host) => void;
onCancel: () => void;
}
const HostForm: React.FC<HostFormProps> = ({
initialData,
availableKeys,
groups,
onSave,
onCancel,
}) => {
const { t } = useI18n();
const [formData, setFormData] = useState<Partial<Host>>(
initialData || {
label: "",
hostname: "",
port: 22,
username: "root",
tags: [],
os: "linux",
group: "General",
identityFileId: "",
},
);
const [authType, setAuthType] = useState<"password" | "key">(
initialData?.identityFileId ? "key" : "password",
);
const [tagInput, setTagInput] = useState("");
const handleAddTag = () => {
const tag = tagInput.trim();
if (tag && !formData.tags?.includes(tag)) {
setFormData((prev) => ({ ...prev, tags: [...(prev.tags || []), tag] }));
setTagInput("");
}
};
const handleRemoveTag = (tagToRemove: string) => {
setFormData((prev) => ({
...prev,
tags: (prev.tags || []).filter((t) => t !== tagToRemove),
}));
};
const handleTagKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter") {
e.preventDefault();
handleAddTag();
}
};
// Effect to ensure we have a valid auth state if switching back and forth
useEffect(() => {
if (authType === "password") {
setFormData((prev) => ({ ...prev, identityFileId: "" }));
} else if (
authType === "key" &&
!formData.identityFileId &&
availableKeys.length > 0
) {
// Default to first key if none selected
setFormData((prev) => ({ ...prev, identityFileId: availableKeys[0].id }));
}
}, [authType, availableKeys, formData.identityFileId]);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (formData.label && formData.hostname && formData.username) {
onSave({
...formData,
id: initialData?.id || crypto.randomUUID(),
tags: formData.tags || [],
port: formData.port || 22,
group: formData.group || "General",
identityFileId:
authType === "key" ? formData.identityFileId : undefined,
createdAt: initialData?.createdAt || Date.now(),
} as Host);
}
};
return (
<Dialog open={true} onOpenChange={() => onCancel()}>
<DialogContent>
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Server className="h-5 w-5 text-primary" />
{initialData ? t("hostForm.title.edit") : t("hostForm.title.new")}
</DialogTitle>
<DialogDescription className="sr-only">
{initialData ? t("hostForm.desc.edit") : t("hostForm.desc.new")}
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="label">{t("hostForm.field.label")}</Label>
<Input
id="label"
placeholder={t("hostForm.placeholder.label")}
value={formData.label}
onChange={(e) =>
setFormData({ ...formData, label: e.target.value })
}
required
/>
</div>
<div className="grid grid-cols-3 gap-4">
<div className="col-span-2 grid gap-2">
<Label htmlFor="hostname">{t("hostForm.field.hostname")}</Label>
<Input
id="hostname"
placeholder={t("hostForm.placeholder.hostname")}
value={formData.hostname}
onChange={(e) =>
setFormData({ ...formData, hostname: e.target.value })
}
required
/>
</div>
<div className="grid gap-2">
<Label htmlFor="port">{t("hostForm.field.port")}</Label>
<Input
id="port"
type="number"
value={formData.port}
onChange={(e) =>
setFormData({ ...formData, port: parseInt(e.target.value) })
}
required
/>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="grid gap-2">
<Label htmlFor="username">{t("hostForm.field.username")}</Label>
<Input
id="username"
value={formData.username}
onChange={(e) =>
setFormData({ ...formData, username: e.target.value })
}
required
/>
</div>
<div className="grid gap-2">
<Label htmlFor="os">{t("hostForm.field.osType")}</Label>
<Select
value={formData.os}
onValueChange={(val: "linux" | "windows" | "macos") =>
setFormData({ ...formData, os: val })
}
>
<SelectTrigger>
<SelectValue placeholder={t("hostForm.placeholder.selectOs")} />
</SelectTrigger>
<SelectContent>
<SelectItem value="linux">Linux</SelectItem>
<SelectItem value="windows">Windows</SelectItem>
<SelectItem value="macos">macOS</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="grid gap-2">
<Label htmlFor="group">{t("hostForm.field.group")}</Label>
<Input
id="group"
placeholder={t("hostForm.placeholder.group")}
value={formData.group}
onChange={(e) =>
setFormData({ ...formData, group: e.target.value })
}
list="group-suggestions"
autoComplete="off"
/>
<datalist id="group-suggestions">
{groups.map((g) => (
<option key={g} value={g} />
))}
</datalist>
</div>
<div className="grid gap-2">
<Label htmlFor="tags">{t("hostForm.field.tags")}</Label>
<div className="flex gap-2">
<Input
id="tags"
placeholder={t("hostForm.placeholder.addTag")}
value={tagInput}
onChange={(e) => setTagInput(e.target.value)}
onKeyDown={handleTagKeyDown}
className="flex-1"
/>
<Button
type="button"
variant="secondary"
size="icon"
onClick={handleAddTag}
disabled={!tagInput.trim()}
>
<Plus size={16} />
</Button>
</div>
{formData.tags && formData.tags.length > 0 && (
<div className="flex flex-wrap gap-1.5 mt-1">
{formData.tags.map((tag) => (
<span
key={tag}
className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-primary/10 text-primary text-xs"
>
{tag}
<button
type="button"
onClick={() => handleRemoveTag(tag)}
className="hover:bg-primary/20 rounded-full p-0.5"
>
<X size={12} />
</button>
</span>
))}
</div>
)}
</div>
<div className="space-y-3 pt-2">
<div className="flex items-center justify-between space-x-2 border rounded-md p-3">
<div className="space-y-0.5">
<Label htmlFor="sftp-sudo" className="text-base">
{t("hostDetails.sftp.sudo")}
</Label>
<p className="text-xs text-muted-foreground">
{t("hostDetails.sftp.sudo.desc")}
</p>
{formData.sftpSudo && authType === "key" && (
<p className="text-xs text-amber-500 mt-1">
{t("hostDetails.sftp.sudo.passwordWarning")}
</p>
)}
</div>
<Switch
id="sftp-sudo"
checked={formData.sftpSudo || false}
onCheckedChange={(checked) =>
setFormData({ ...formData, sftpSudo: checked })
}
/>
</div>
<div className="space-y-1">
<Label htmlFor="sftp-encoding">
{t("hostDetails.sftp.encoding")}
</Label>
<Select
value={formData.sftpEncoding || "auto"}
onValueChange={(val) =>
setFormData({ ...formData, sftpEncoding: val as Host["sftpEncoding"] })
}
>
<SelectTrigger id="sftp-encoding">
<SelectValue placeholder={t("sftp.encoding.label")} />
</SelectTrigger>
<SelectContent>
<SelectItem value="auto">{t("sftp.encoding.auto")}</SelectItem>
<SelectItem value="utf-8">{t("sftp.encoding.utf8")}</SelectItem>
<SelectItem value="gb18030">{t("sftp.encoding.gb18030")}</SelectItem>
</SelectContent>
</Select>
<p className="text-xs text-muted-foreground">
{t("hostDetails.sftp.encoding.desc")}
</p>
</div>
<Label>{t("hostForm.auth.method")}</Label>
<div className="grid grid-cols-2 gap-4">
<div
className={cn(
"border rounded-md p-3 flex flex-col items-center justify-center gap-2 cursor-pointer transition-all hover:bg-accent/50",
authType === "password"
? "border-primary bg-primary/5 text-primary ring-1 ring-primary"
: "text-muted-foreground",
)}
onClick={() => setAuthType("password")}
>
<Lock size={20} />
<span className="text-xs font-medium">{t("hostForm.auth.password")}</span>
</div>
<div
className={cn(
"border rounded-md p-3 flex flex-col items-center justify-center gap-2 cursor-pointer transition-all hover:bg-accent/50",
authType === "key"
? "border-primary bg-primary/5 text-primary ring-1 ring-primary"
: "text-muted-foreground",
)}
onClick={() => setAuthType("key")}
>
<Key size={20} />
<span className="text-xs font-medium">{t("hostForm.auth.sshKey")}</span>
</div>
</div>
{authType === "key" && (
<div className="animate-in fade-in zoom-in-95 duration-200">
<Select
value={formData.identityFileId || ""}
onValueChange={(val) =>
setFormData({ ...formData, identityFileId: val })
}
>
<SelectTrigger>
<SelectValue placeholder={t("hostForm.auth.selectKey")} />
</SelectTrigger>
<SelectContent>
{availableKeys.map((key) => (
<SelectItem key={key.id} value={key.id}>
{key.label} ({key.type})
</SelectItem>
))}
{availableKeys.length === 0 && (
<SelectItem value="none" disabled>
{t("hostForm.auth.noKeys")}
</SelectItem>
)}
</SelectContent>
</Select>
{availableKeys.length === 0 && (
<p className="text-[10px] text-destructive mt-1">
{t("hostForm.auth.noKeysHint")}
</p>
)}
</div>
)}
</div>
<DialogFooter>
<Button type="button" variant="ghost" onClick={onCancel}>
{t("common.cancel")}
</Button>
<Button type="submit">
<Save className="mr-2 h-4 w-4" /> {t("hostForm.saveHost")}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
};
export default HostForm;

View File

@@ -1,411 +0,0 @@
import {
Key,
LayoutGrid,
List as ListIcon,
Pencil,
Plus,
Search,
Shield,
Trash2,
} from "lucide-react";
import React, { useMemo, useState } from "react";
import { useI18n } from "../application/i18n/I18nProvider";
import { KeyType } from "../domain/models";
import { cn } from "../lib/utils";
import { SSHKey } from "../types";
import { Button } from "./ui/button";
import { Card, CardDescription, CardTitle } from "./ui/card";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "./ui/dialog";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
import { Textarea } from "./ui/textarea";
interface KeyManagerProps {
keys: SSHKey[];
onSave: (key: SSHKey) => void;
onDelete: (id: string) => void;
}
const KeyManager: React.FC<KeyManagerProps> = ({ keys, onSave, onDelete }) => {
const { t } = useI18n();
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [panelMode, setPanelMode] = useState<"new" | "edit">("new");
const [draftKey, setDraftKey] = useState<Partial<SSHKey>>({
id: "",
label: "",
type: "RSA",
privateKey: "",
publicKey: "",
created: Date.now(),
});
const [generateMode, setGenerateMode] = useState(false);
const [search, setSearch] = useState("");
const [viewMode, setViewMode] = useState<"grid" | "list">("grid");
const handleGenerate = () => {
// Simulate Key Generation
const mockKey =
`-----BEGIN ${draftKey.type} PRIVATE KEY-----\n` +
`MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC${Math.random().toString(36).substring(7)}\n` +
`... (simulated generated content) ...\n` +
`-----END ${draftKey.type} PRIVATE KEY-----`;
setDraftKey({ ...draftKey, privateKey: mockKey });
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!draftKey.label || !draftKey.privateKey) return;
const payload: SSHKey = {
id: draftKey.id || crypto.randomUUID(),
label: draftKey.label,
type: (draftKey.type as KeyType) || "RSA",
privateKey: draftKey.privateKey,
publicKey: draftKey.publicKey?.trim() || undefined,
created: draftKey.created || Date.now(),
source: draftKey.source || (generateMode ? "generated" : "imported"),
category: draftKey.category || "key",
};
onSave(payload);
setIsDialogOpen(false);
setGenerateMode(false);
};
const openPanelForKey = (key: SSHKey) => {
setPanelMode("edit");
setDraftKey({ ...key });
setIsDialogOpen(true);
setGenerateMode(false);
};
const openPanelNew = (isGenerate = false) => {
setPanelMode("new");
setGenerateMode(isGenerate);
setDraftKey({
id: "",
label: "",
type: "RSA",
privateKey: isGenerate
? "Click generate to create a new key pair..."
: "",
publicKey: "",
created: Date.now(),
});
setIsDialogOpen(true);
};
const handleDelete = (id: string) => {
onDelete(id);
if (draftKey.id === id) {
setIsDialogOpen(false);
setDraftKey({
id: "",
label: "",
type: "RSA",
privateKey: "",
publicKey: "",
created: Date.now(),
});
}
};
const filteredKeys = useMemo(() => {
const term = search.trim().toLowerCase();
return keys.filter((k) => {
if (!term) return true;
return (
k.label.toLowerCase().includes(term) ||
(k.type || "").toString().toLowerCase().includes(term)
);
});
}, [keys, search]);
const derivedPublicKey = useMemo(() => {
if (draftKey.publicKey) return draftKey.publicKey;
if (!draftKey.label) return "Generated By netcatty";
return `ssh-${(draftKey.type || "ed25519").toLowerCase()} AAAAC3NzaC1lZDI1NTE5AAAA${(
draftKey.label || "netcatty"
)
.replace(/\s+/g, "")
.slice(0, 8)} Generated By netcatty`;
}, [draftKey.label, draftKey.type, draftKey.publicKey]);
return (
<div className="px-2.5 py-2.5 lg:px-3 lg:py-3 h-full overflow-y-auto space-y-3.5 relative">
<div className="flex flex-wrap items-center gap-3 bg-secondary/60 border border-border/70 rounded-xl px-2 py-1.5 shadow-sm">
<Button
size="sm"
variant="secondary"
className="h-8 px-3 gap-2"
disabled
>
Key
<span className="text-[10px] px-2 rounded-full h-5 min-w-[22px] flex items-center justify-center bg-primary/10 text-primary border border-border/70">
{keys.length}
</span>
</Button>
<div className="ml-auto flex items-center gap-2">
<div className="relative">
<Search
size={14}
className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"
/>
<Input
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder="Search keys..."
className="h-9 pl-8 w-44 md:w-56"
/>
</div>
<Button
size="icon"
variant={viewMode === "grid" ? "secondary" : "ghost"}
className="h-9 w-9"
onClick={() => setViewMode("grid")}
>
<LayoutGrid size={16} />
</Button>
<Button
size="icon"
variant={viewMode === "list" ? "secondary" : "ghost"}
className="h-9 w-9"
onClick={() => setViewMode("list")}
>
<ListIcon size={16} />
</Button>
<Button size="sm" onClick={() => openPanelNew(false)}>
<Plus size={14} className="mr-2" /> Import
</Button>
<Button
size="sm"
variant="secondary"
onClick={() => openPanelNew(true)}
>
Generate
</Button>
</div>
</div>
<div className="space-y-3">
<div className="flex items-center justify-between px-1">
<h2 className="text-base font-semibold text-muted-foreground">
Keys
</h2>
</div>
<div className="space-y-3">
{filteredKeys.length === 0 && (
<div className="flex flex-col items-center justify-center h-64 text-muted-foreground">
<div className="h-16 w-16 rounded-2xl bg-secondary/80 flex items-center justify-center mb-4">
<Shield size={32} className="opacity-60" />
</div>
<h3 className="text-lg font-semibold text-foreground mb-2">
Set up your keys
</h3>
<p className="text-sm text-center max-w-sm">
Import or generate SSH keys for secure authentication.
</p>
</div>
)}
<div
className={
viewMode === "grid"
? "grid gap-3 grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
: "flex flex-col gap-0"
}
>
{filteredKeys.map((key) => (
<Card
key={key.id}
className={cn(
"group cursor-pointer soft-card elevate rounded-xl",
viewMode === "grid"
? "h-[68px] px-3 py-2"
: "h-14 px-3 py-2 hover:bg-secondary/60 rounded-lg transition-colors",
)}
onClick={() => openPanelForKey(key)}
>
<div className="flex items-center gap-3 h-full">
<div className="h-9 w-9 rounded-md bg-primary/15 text-primary flex items-center justify-center">
<Key size={16} />
</div>
<div className="min-w-0 flex-1">
<CardTitle className="text-sm font-semibold truncate">
{key.label}
</CardTitle>
<CardDescription className="text-[11px] font-mono text-muted-foreground truncate">
Type {key.type}
</CardDescription>
<div className="text-[10px] text-muted-foreground/80 font-mono truncate">
SHA256:{key.id.substring(0, 16)}...
</div>
</div>
<div className="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
<Button
size="icon"
variant="ghost"
className="h-8 w-8"
onClick={(e) => {
e.stopPropagation();
openPanelForKey(key);
}}
>
<Pencil size={14} />
</Button>
<Button
size="icon"
variant="ghost"
className="h-8 w-8 text-destructive hover:text-destructive"
onClick={(e) => {
e.stopPropagation();
handleDelete(key.id);
}}
>
<Trash2 size={14} />
</Button>
</div>
</div>
</Card>
))}
</div>
</div>
</div>
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
<DialogContent className="max-w-2xl">
<DialogHeader>
<DialogTitle>
{panelMode === "new"
? t("keychain.keyDialog.newTitle")
: t("keychain.keyDialog.editTitle")}
</DialogTitle>
<DialogDescription className="sr-only">
{panelMode === "new"
? t("keychain.keyDialog.newDesc")
: t("keychain.keyDialog.editDesc")}
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label>{t("keychain.field.label")}</Label>
<Input
value={draftKey.label}
onChange={(e) =>
setDraftKey({ ...draftKey, label: e.target.value })
}
placeholder={t("keychain.field.labelPlaceholder")}
required
/>
</div>
<div className="space-y-2">
<Label>{t("keychain.field.privateKeyRequired")}</Label>
<Textarea
value={draftKey.privateKey}
onChange={(e) =>
setDraftKey({ ...draftKey, privateKey: e.target.value })
}
placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"
className="min-h-[160px] font-mono text-xs"
required
/>
{generateMode && (
<Button
type="button"
size="sm"
variant="secondary"
onClick={handleGenerate}
>
{t("keychain.generate.generate")}
</Button>
)}
</div>
<div className="space-y-2">
<Label>{t("keychain.field.publicKey")}</Label>
<Textarea
value={derivedPublicKey}
onChange={(e) =>
setDraftKey({ ...draftKey, publicKey: e.target.value })
}
placeholder="ssh-ed25519 AAAAC3... user@host"
className="min-h-[90px] font-mono text-xs"
/>
</div>
<div className="space-y-2">
<Label className="flex items-center gap-2">
{t("terminal.auth.certificate")}{" "}
<span className="text-[10px] px-2 py-0.5 rounded-full bg-muted text-muted-foreground">
{t("common.optional")}
</span>
</Label>
<Textarea
placeholder={t("keychain.field.certificatePlaceholder")}
className="min-h-[80px] text-xs"
/>
</div>
<div className="border border-dashed border-border/80 rounded-xl p-4 text-center space-y-2 bg-background/60">
<div className="text-sm text-muted-foreground">
{t("keychain.import.dropHint")}
</div>
<Button
type="button"
variant="secondary"
onClick={() => {
// mock file import
setDraftKey({
...draftKey,
label: draftKey.label || t("keychain.import.importedKeyLabel"),
privateKey:
draftKey.privateKey ||
"-----BEGIN OPENSSH PRIVATE KEY-----\nAAAAC3NzaC1lZDI1NTE5AAAA\n-----END OPENSSH PRIVATE KEY-----",
});
}}
>
{t("keychain.import.importFromFile")}
</Button>
</div>
<DialogFooter>
{panelMode === "edit" && draftKey.id && (
<Button
type="button"
variant="ghost"
className="text-destructive mr-auto"
onClick={() => handleDelete(draftKey.id!)}
>
{t("common.delete")}
</Button>
)}
<Button
type="button"
variant="ghost"
onClick={() => setIsDialogOpen(false)}
>
{t("common.cancel")}
</Button>
<Button type="submit">
{panelMode === "new"
? t("keychain.import.saveKey")
: t("keychain.keyDialog.updateKey")}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
</div>
);
};
export default KeyManager;

View File

@@ -450,11 +450,6 @@ echo $3 >> "$FILE"`);
[onDeleteIdentity, panel, closePanel],
);
// Copy to clipboard
const _copyToClipboard = useCallback((_text: string) => {
navigator.clipboard.writeText(_text);
}, []);
// Get icon for key source
const getKeyIcon = (key: SSHKey) => {
if (key.certificate) return <BadgeCheck size={16} />;
@@ -506,46 +501,6 @@ echo $3 >> "$FILE"`);
[],
);
// Handle drag and drop
const _handleDrop = useCallback((event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
event.stopPropagation();
const file = event.dataTransfer.files?.[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
const content = e.target?.result as string;
if (content) {
let detectedType: KeyType = "ED25519";
const lc = content.toLowerCase();
if (lc.includes("rsa")) detectedType = "RSA";
else if (lc.includes("ecdsa") || lc.includes("ec private"))
detectedType = "ECDSA";
else if (lc.includes("ed25519")) detectedType = "ED25519";
const label = file.name.replace(/\.(pem|key|pub|ppk)$/i, "");
setDraftKey((prev) => ({
...prev,
privateKey: content,
label: prev.label || label,
type: detectedType,
}));
}
};
reader.readAsText(file);
}, []);
const _handleDragOver = useCallback(
(event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
event.stopPropagation();
},
[],
);
return (
<div className="h-full flex relative">
{/* Hidden file input */}

View File

@@ -307,8 +307,6 @@ const PortForwarding: React.FC<PortForwardingProps> = ({
const label =
newFormDraft.label?.trim() ||
(() => {
// Host lookup reserved for future label enhancement (e.g., "Local:8080 → api.example.com:80 via server1")
const _host = hosts.find((h) => h.id === newFormDraft.hostId);
switch (newFormDraft.type) {
case "local":
return `Local:${newFormDraft.localPort}${newFormDraft.remoteHost}:${newFormDraft.remotePort}`;
@@ -546,12 +544,6 @@ const PortForwarding: React.FC<PortForwardingProps> = ({
);
};
// Handle skip wizard (just save with defaults)
const _skipWizard = () => {
setShowWizard(false);
resetWizard();
};
// Render wizard panel content
const hasRules = filteredRules.length > 0;

View File

@@ -14,7 +14,7 @@ import React, { useMemo, useState } from "react";
import { useI18n } from "../application/i18n/I18nProvider";
import type { QuickConnectTarget } from "../domain/quickConnect";
import { cn } from "../lib/utils";
import { Host, KnownHost, SSHKey } from "../types";
import { Host, SSHKey } from "../types";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
@@ -30,7 +30,6 @@ interface QuickConnectWizardProps {
open: boolean;
target: QuickConnectTarget;
keys: SSHKey[];
knownHosts: KnownHost[];
warnings?: string[];
onConnect: (host: Host) => void;
onSaveHost?: (host: Host) => void;
@@ -42,7 +41,6 @@ const QuickConnectWizard: React.FC<QuickConnectWizardProps> = ({
open,
target,
keys,
knownHosts,
warnings,
onConnect,
onSaveHost,
@@ -69,16 +67,7 @@ const QuickConnectWizard: React.FC<QuickConnectWizardProps> = ({
const [password, setPassword] = useState("");
const [selectedKeyId, setSelectedKeyId] = useState<string | null>(null);
const [showPassword, setShowPassword] = useState(false);
const [saveCredentials, _setSaveCredentials] = useState(true);
// Check if host is in known hosts
const _existingKnownHost = useMemo(() => {
return knownHosts.find(
(kh) =>
kh.hostname === target.hostname &&
(kh.port === port || (!kh.port && port === 22)),
);
}, [knownHosts, target.hostname, port]);
const [saveCredentials] = useState(true);
// Reset state when target changes
React.useEffect(() => {

View File

@@ -93,6 +93,7 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
const {
sftpAutoSync,
sftpShowHiddenFiles,
setSftpShowHiddenFiles,
sftpUseCompressedUpload,
hotkeyScheme,
keyBindings,
@@ -204,6 +205,7 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
const {
currentPath,
setCurrentPath,
currentPathRef,
files,
loading,
setLoading,
@@ -384,6 +386,7 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
dismissTask,
} = useSftpModalTransfers({
currentPath,
currentPathRef,
isLocalSession,
joinPath: joinPathForSession,
ensureSftp,
@@ -475,13 +478,13 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
initialUploadTriggeredRef.current = true;
// Trigger upload with full DropEntry data (preserves directory structure)
handleUploadEntries(initialEntriesToUpload);
}, [initialEntriesToUpload, open, loading, handleUploadEntries]);
void handleUploadEntries(initialEntriesToUpload);
}, [handleUploadEntries, initialEntriesToUpload, loading, open]);
// Display files with parent entry (like SftpView)
const displayFiles = useMemo(() => {
// Filter hidden files using utility function
const visibleFiles = filterHiddenFiles(files, sftpShowHiddenFiles, isLocalSession);
const visibleFiles = filterHiddenFiles(files, sftpShowHiddenFiles);
// Check if we're at root
const atRoot = isRootPathForSession(currentPath);
@@ -495,7 +498,7 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
lastModified: undefined,
};
return [parentEntry, ...visibleFiles.filter((f) => f.name !== "..")];
}, [files, currentPath, isRootPathForSession, sftpShowHiddenFiles, isLocalSession]);
}, [files, currentPath, isRootPathForSession, sftpShowHiddenFiles]);
// Sorted files
const sortedFiles = useMemo(() => {
@@ -541,6 +544,8 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
return parentEntry ? [parentEntry, ...sorted] : sorted;
}, [displayFiles, sortField, sortOrder]);
const hasFiles = files.length > 0;
const hasDisplayFiles = sortedFiles.length > 0;
const {
fileListRef,
handleFileListScroll,
@@ -685,6 +690,10 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
onCreateFile={handleCreateFile}
onFileSelect={handleFileSelect}
onFolderSelect={handleFolderSelect}
showHiddenFiles={sftpShowHiddenFiles}
onToggleShowHiddenFiles={() =>
setSftpShowHiddenFiles(!sftpShowHiddenFiles)
}
onUpdateHost={onUpdateHost}
onNavigateToBookmark={(path) => setCurrentPath(path)}
/>
@@ -693,7 +702,8 @@ const SFTPModal: React.FC<SFTPModalProps> = ({
t={t}
currentPath={currentPath}
isLocalSession={isLocalSession}
files={files}
hasFiles={hasFiles}
hasDisplayFiles={hasDisplayFiles}
selectedFiles={selectedFiles}
dragActive={dragActive}
loading={loading}

View File

@@ -197,19 +197,6 @@ const SelectHostPanel: React.FC<SelectHostPanelProps> = ({
}));
}, [currentPath]);
const _handleBack = () => {
if (currentPath) {
const parts = currentPath.split("/");
if (parts.length > 1) {
setCurrentPath(parts.slice(0, -1).join("/"));
} else {
setCurrentPath(null);
}
} else {
onBack();
}
};
return (
<div
className={cn(

View File

@@ -4,7 +4,7 @@ import AppLogo from "./AppLogo";
import { Button } from "./ui/button";
import { cn } from "../lib/utils";
import { useApplicationBackend } from "../application/state/useApplicationBackend";
import { useUpdateCheck } from "../application/state/useUpdateCheck";
import type { UpdateState, UseUpdateCheckResult } from "../application/state/useUpdateCheck";
import { useI18n } from "../application/i18n/I18nProvider";
import { SettingsTabContent } from "./settings/settings-ui";
import { toast } from "./ui/toast";
@@ -63,13 +63,18 @@ const ActionRow: React.FC<{
</button>
);
export default function SettingsApplicationTab() {
interface SettingsApplicationTabProps {
updateState: UpdateState;
checkNow: UseUpdateCheckResult['checkNow'];
openReleasePage: UseUpdateCheckResult['openReleasePage'];
installUpdate: UseUpdateCheckResult['installUpdate'];
}
export default function SettingsApplicationTab({ updateState, checkNow, openReleasePage, installUpdate }: SettingsApplicationTabProps) {
const { t } = useI18n();
const { openExternal, getApplicationInfo } = useApplicationBackend();
const { updateState, checkNow, openReleasePage } = useUpdateCheck();
const [appInfo, setAppInfo] = useState<AppInfo>({ name: "Netcatty", version: "" });
const [lastCheckResult, setLastCheckResult] = useState<'none' | 'available' | 'upToDate'>('none');
const [hasAutoChecked, setHasAutoChecked] = useState(false);
useEffect(() => {
let cancelled = false;
@@ -93,19 +98,6 @@ export default function SettingsApplicationTab() {
const isUpdateDemoMode = typeof window !== 'undefined' &&
window.localStorage?.getItem('debug.updateDemo') === '1';
// Auto check for updates when entering this page
useEffect(() => {
if (hasAutoChecked) return;
if (updateState.isChecking) return;
// In demo mode or when we have a valid version, auto-check
const canCheck = isUpdateDemoMode || (appInfo.version && appInfo.version !== '0.0.0');
if (!canCheck) return;
setHasAutoChecked(true);
void checkNow();
}, [hasAutoChecked, updateState.isChecking, isUpdateDemoMode, appInfo.version, checkNow]);
const handleCheckForUpdates = async () => {
// In demo mode, allow checking even for dev builds
if (!isUpdateDemoMode && (!appInfo.version || appInfo.version === '0.0.0')) {
@@ -124,8 +116,9 @@ export default function SettingsApplicationTab() {
t('update.available.message', { version: result.latestRelease.version }),
t('update.available.title')
);
// Open the release page
openReleasePage();
// Don't auto-open the release page here — checkNow() already triggers
// electron-updater on supported platforms, and the Settings > System tab
// shows a "Manual Download" link on unsupported platforms.
} else if (result) {
setLastCheckResult('upToDate');
toast.success(
@@ -154,18 +147,25 @@ export default function SettingsApplicationTab() {
<span className="text-sm text-muted-foreground">
{appInfo.version ? appInfo.version : " "}
</span>
{/* Update available badge - inline with version */}
{updateState.hasUpdate && updateState.latestRelease && (
{/* Update badge - reflects auto-download state */}
{updateState.latestRelease && (updateState.hasUpdate || updateState.autoDownloadStatus === 'downloading' || updateState.autoDownloadStatus === 'ready') && (
<button
onClick={() => void openReleasePage()}
onClick={() => updateState.autoDownloadStatus === 'ready' ? installUpdate() : void openReleasePage()}
className={cn(
"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium",
"bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300",
"hover:bg-blue-200 dark:hover:bg-blue-800 transition-colors cursor-pointer"
updateState.autoDownloadStatus === 'ready'
? "bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-300 hover:bg-green-200 dark:hover:bg-green-800"
: "bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 hover:bg-blue-200 dark:hover:bg-blue-800",
"transition-colors cursor-pointer"
)}
>
<ArrowUpCircle size={12} />
v{updateState.latestRelease.version} {t('update.downloadNow')}
v{updateState.latestRelease.version}{' '}
{updateState.autoDownloadStatus === 'ready'
? t('update.restartNow')
: updateState.autoDownloadStatus === 'downloading'
? `${updateState.downloadPercent}%`
: t('update.downloadNow')}
</button>
)}
</div>

View File

@@ -3,10 +3,12 @@
* This component is rendered in a separate Electron window
*/
import { AppWindow, Cloud, FileType, HardDrive, Keyboard, Palette, TerminalSquare, X } from "lucide-react";
import React, { useCallback, useEffect, useState } from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { useSettingsState } from "../application/state/useSettingsState";
import { usePortForwardingState } from "../application/state/usePortForwardingState";
import { useVaultState } from "../application/state/useVaultState";
import { useWindowControls } from "../application/state/useWindowControls";
import { useUpdateCheck } from "../application/state/useUpdateCheck";
import { I18nProvider, useI18n } from "../application/i18n/I18nProvider";
import SettingsApplicationTab from "./SettingsApplicationTab";
import SettingsAppearanceTab from "./settings/tabs/SettingsAppearanceTab";
@@ -31,17 +33,38 @@ const SettingsSyncTabWithVault: React.FC = () => {
keys,
identities,
snippets,
customGroups,
snippetPackages,
knownHosts,
importDataFromString,
clearVaultData,
} = useVaultState();
const { rules: portForwardingRules, importRules: importPortForwardingRules } = usePortForwardingState();
// Strip transient runtime fields before passing to sync
const portForwardingRulesForSync = useMemo(
() =>
portForwardingRules.map((rule) => ({
...rule,
status: "inactive" as const,
error: undefined,
lastUsedAt: undefined,
})),
[portForwardingRules],
);
const vault = useMemo(
() => ({ hosts, keys, identities, snippets, customGroups, snippetPackages, knownHosts }),
[hosts, keys, identities, snippets, customGroups, snippetPackages, knownHosts],
);
return (
<SettingsSyncTab
hosts={hosts}
keys={keys}
identities={identities}
snippets={snippets}
vault={vault}
portForwardingRules={portForwardingRulesForSync}
importDataFromString={importDataFromString}
importPortForwardingRules={importPortForwardingRules}
clearVaultData={clearVaultData}
/>
);
@@ -50,6 +73,7 @@ const SettingsSyncTabWithVault: React.FC = () => {
const SettingsPageContent: React.FC<{ settings: SettingsState }> = ({ settings }) => {
const { t } = useI18n();
const { notifyRendererReady, closeSettingsWindow } = useWindowControls();
const { updateState, checkNow, installUpdate, openReleasePage } = useUpdateCheck();
const [activeTab, setActiveTab] = useState("application");
const [mountedTabs, setMountedTabs] = useState(() => new Set(["application"]));
@@ -144,7 +168,14 @@ const SettingsPageContent: React.FC<{ settings: SettingsState }> = ({ settings }
</div>
<div className="flex-1 h-full flex flex-col min-h-0 bg-muted/10">
{mountedTabs.has("application") && <SettingsApplicationTab />}
{mountedTabs.has("application") && (
<SettingsApplicationTab
updateState={updateState}
checkNow={checkNow}
openReleasePage={openReleasePage}
installUpdate={installUpdate}
/>
)}
{mountedTabs.has("appearance") && (
<SettingsAppearanceTab
@@ -216,6 +247,10 @@ const SettingsPageContent: React.FC<{ settings: SettingsState }> = ({ settings }
closeToTray={settings.closeToTray}
setCloseToTray={settings.setCloseToTray}
hotkeyRegistrationError={settings.hotkeyRegistrationError}
updateState={updateState}
checkNow={checkNow}
installUpdate={installUpdate}
openReleasePage={openReleasePage}
/>
)}
</div>

View File

@@ -81,7 +81,8 @@ const SftpViewInner: React.FC<SftpViewProps> = ({ hosts, keys, identities, updat
const sftpOptions = useMemo(() => ({
...fileWatchHandlers,
useCompressedUpload: sftpUseCompressedUpload,
}), [fileWatchHandlers, sftpUseCompressedUpload]);
defaultShowHiddenFiles: sftpShowHiddenFiles,
}), [fileWatchHandlers, sftpUseCompressedUpload, sftpShowHiddenFiles]);
const sftp = useSftpState(hosts, keys, identities, sftpOptions);
@@ -107,7 +108,6 @@ const SftpViewInner: React.FC<SftpViewProps> = ({ hosts, keys, identities, updat
hotkeyScheme,
sftpRef,
isActive,
showHiddenFiles: sftpShowHiddenFiles,
});
// Subscribe to focused side for visual indicator
@@ -118,6 +118,14 @@ const SftpViewInner: React.FC<SftpViewProps> = ({ hosts, keys, identities, updat
sftpFocusStore.setFocusedSide(side);
}, []);
const handleToggleHiddenFiles = useCallback((side: "left" | "right", paneId: string) => {
const sideTabs = side === "left" ? sftpRef.current.leftTabs : sftpRef.current.rightTabs;
const pane = sideTabs.tabs.find((tab) => tab.id === paneId);
if (!pane) return;
sftpRef.current.setShowHiddenFiles(side, paneId, !pane.showHiddenFiles);
}, []);
// Sync activeTabId to external store (allows child components to subscribe without parent re-render)
// Using useLayoutEffect to sync before paint
useLayoutEffect(() => {
@@ -225,7 +233,6 @@ const SftpViewInner: React.FC<SftpViewProps> = ({ hosts, keys, identities, updat
dragCallbacks={dragCallbacks}
leftCallbacks={leftCallbacks}
rightCallbacks={rightCallbacks}
showHiddenFiles={sftpShowHiddenFiles}
>
<div
className={cn(
@@ -277,6 +284,7 @@ const SftpViewInner: React.FC<SftpViewProps> = ({ hosts, keys, identities, updat
pane={pane}
showHeader
showEmptyHeader={false}
onToggleShowHiddenFiles={() => handleToggleHiddenFiles("left", pane.id)}
/>
</SftpPaneWrapper>
))}
@@ -333,6 +341,7 @@ const SftpViewInner: React.FC<SftpViewProps> = ({ hosts, keys, identities, updat
pane={pane}
showHeader
showEmptyHeader={false}
onToggleShowHiddenFiles={() => handleToggleHiddenFiles("right", pane.id)}
/>
</SftpPaneWrapper>
))}

View File

@@ -25,7 +25,7 @@ import {
Server,
} from 'lucide-react';
import { useCloudSync } from '../application/state/useCloudSync';
import type { CloudProvider } from '../domain/sync';
import { isProviderReadyForSync, type CloudProvider } from '../domain/sync';
import { useI18n } from '../application/i18n/I18nProvider';
import { cn } from '../lib/utils';
import { Button } from './ui/button';
@@ -122,12 +122,11 @@ export const SyncStatusButton: React.FC<SyncStatusButtonProps> = ({
// Get connected provider (include syncing status as it's still connected)
const getConnectedProvider = (): CloudProvider | null => {
const isProviderActive = (status: string) => status === 'connected' || status === 'syncing';
if (isProviderActive(sync.providers.github.status)) return 'github';
if (isProviderActive(sync.providers.google.status)) return 'google';
if (isProviderActive(sync.providers.onedrive.status)) return 'onedrive';
if (isProviderActive(sync.providers.webdav.status)) return 'webdav';
if (isProviderActive(sync.providers.s3.status)) return 's3';
if (isProviderReadyForSync(sync.providers.github)) return 'github';
if (isProviderReadyForSync(sync.providers.google)) return 'google';
if (isProviderReadyForSync(sync.providers.onedrive)) return 'onedrive';
if (isProviderReadyForSync(sync.providers.webdav)) return 'webdav';
if (isProviderReadyForSync(sync.providers.s3)) return 's3';
return null;
};
@@ -136,9 +135,9 @@ export const SyncStatusButton: React.FC<SyncStatusButtonProps> = ({
// Determine overall status for the button indicator
const getOverallStatus = (): StatusIndicatorProps['status'] => {
if (sync.isSyncing) return 'syncing';
if (sync.lastError) return 'error';
if (sync.hasAnyConnectedProvider) return 'synced';
if (sync.overallSyncStatus === 'syncing') return 'syncing';
if (sync.overallSyncStatus === 'error' || sync.overallSyncStatus === 'conflict') return 'error';
if (sync.overallSyncStatus === 'synced') return 'synced';
return 'none';
};

View File

@@ -21,6 +21,10 @@ import {
TerminalSettings,
KeyBinding,
} from "../types";
import {
shouldEnableNativeUserInputAutoScroll,
shouldScrollOnTerminalInput,
} from "../domain/terminalScroll";
import { resolveHostAuth } from "../domain/sshAuth";
import { useTerminalBackend } from "../application/state/useTerminalBackend";
import KnownHostConfirmDialog, { HostKeyInfo } from "./KnownHostConfirmDialog";
@@ -215,10 +219,15 @@ const TerminalComponent: React.FC<TerminalProps> = ({
const hasConnectedRef = useRef(false);
const hasRunStartupCommandRef = useRef(false);
const commandBufferRef = useRef<string>("");
const [hasMouseTracking, setHasMouseTracking] = useState(false);
const mouseTrackingRef = useRef(false);
const serialLineBufferRef = useRef<string>("");
const terminalSettingsRef = useRef(terminalSettings);
terminalSettingsRef.current = terminalSettings;
const isVisibleRef = useRef(isVisible);
isVisibleRef.current = isVisible;
const pendingOutputScrollRef = useRef(false);
useEffect(() => {
if (xtermRuntimeRef.current) {
@@ -414,8 +423,11 @@ const TerminalComponent: React.FC<TerminalProps> = ({
sessionId,
startupCommand,
terminalSettings,
terminalSettingsRef,
terminalBackend,
serialConfig,
isVisibleRef,
pendingOutputScrollRef,
sessionRef,
hasConnectedRef,
hasRunStartupCommandRef,
@@ -452,6 +464,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
let disposed = false;
setError(null);
hasConnectedRef.current = false;
pendingOutputScrollRef.current = false;
setProgressLogs([]);
setShowLogs(false);
setIsCancelling(false);
@@ -701,7 +714,8 @@ const TerminalComponent: React.FC<TerminalProps> = ({
terminalSettings.drawBoldInBrightColors;
termRef.current.options.minimumContrastRatio =
terminalSettings.minimumContrastRatio;
termRef.current.options.scrollOnUserInput = terminalSettings.scrollOnInput;
termRef.current.options.scrollOnUserInput =
shouldEnableNativeUserInputAutoScroll(terminalSettings);
termRef.current.options.altClickMovesCursor = !terminalSettings.altAsMeta;
termRef.current.options.wordSeparator = terminalSettings.wordSeparators;
termRef.current.options.ignoreBracketedPasteMode = terminalSettings.disableBracketedPaste ?? false;
@@ -730,10 +744,20 @@ const TerminalComponent: React.FC<TerminalProps> = ({
}, [host.fontSize, host.fontFamily, host.theme, fontFamilyId, fontSize, effectiveTheme, availableFonts]);
useEffect(() => {
if (isVisible && fitAddonRef.current) {
const timer = setTimeout(() => safeFit(), 50);
return () => clearTimeout(timer);
}
if (!isVisible) return;
const timer = setTimeout(() => {
safeFit();
if (pendingOutputScrollRef.current) {
termRef.current?.scrollToBottom();
if (typeof requestAnimationFrame === "function") {
requestAnimationFrame(() => {
termRef.current?.scrollToBottom();
});
}
pendingOutputScrollRef.current = false;
}
}, 50);
return () => clearTimeout(timer);
}, [isVisible]);
useEffect(() => {
@@ -882,6 +906,61 @@ const TerminalComponent: React.FC<TerminalProps> = ({
term.onSelectionChange(onSelectionChange);
}, [terminalSettings?.copyOnSelect]);
// Track whether the terminal application has enabled mouse tracking
// (e.g. tmux with `set -g mouse on`, vim with `set mouse=a`).
// When mouse tracking is active, disable Netcatty's context menu to avoid
// conflicting with the application's own mouse handling.
useEffect(() => {
const term = termRef.current;
if (!term) return;
const disposable = term.onWriteParsed(() => {
const tracking = term.modes.mouseTrackingMode !== 'none';
if (tracking !== mouseTrackingRef.current) {
mouseTrackingRef.current = tracking;
setHasMouseTracking(tracking);
}
});
// Set initial state
const initial = term.modes.mouseTrackingMode !== 'none';
mouseTrackingRef.current = initial;
setHasMouseTracking(initial);
return () => disposable.dispose();
}, [sessionId]);
// Prevent xterm.js's built-in rightClickHandler and right-button mouseup
// from interfering with tmux/vim popup menus when mouse tracking is active.
// - contextmenu: xterm.js calls textarea.select() which steals focus
// - mouseup (button 2): tmux interprets the right-button release as a
// dismiss action, closing the popup menu immediately after it appears
// Both are intercepted at the capture phase before xterm.js's own listeners.
useEffect(() => {
const el = containerRef.current;
if (!el) return;
const handleContextMenuCapture = (e: MouseEvent) => {
if (mouseTrackingRef.current) {
e.preventDefault();
e.stopImmediatePropagation();
}
};
const handleMouseUpCapture = (e: MouseEvent) => {
if (e.button === 2 && mouseTrackingRef.current) {
e.stopImmediatePropagation();
}
};
el.addEventListener('contextmenu', handleContextMenuCapture, true);
el.addEventListener('mouseup', handleMouseUpCapture, true);
return () => {
el.removeEventListener('contextmenu', handleContextMenuCapture, true);
el.removeEventListener('mouseup', handleMouseUpCapture, true);
};
}, [sessionId]);
useEffect(() => {
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
@@ -904,17 +983,29 @@ const TerminalComponent: React.FC<TerminalProps> = ({
const disableBracketedPasteRef = useRef(terminalSettings?.disableBracketedPaste ?? false);
disableBracketedPasteRef.current = terminalSettings?.disableBracketedPaste ?? false;
const scrollOnPasteRef = useRef(terminalSettings?.scrollOnPaste ?? true);
scrollOnPasteRef.current = terminalSettings?.scrollOnPaste ?? true;
const scrollToBottomAfterProgrammaticInput = (data: string) => {
if (termRef.current && shouldScrollOnTerminalInput(terminalSettingsRef.current, data)) {
termRef.current.scrollToBottom();
}
};
const terminalContextActions = useTerminalContextActions({
termRef,
sessionRef,
terminalBackend,
onHasSelectionChange: setHasSelection,
disableBracketedPasteRef,
scrollOnPasteRef,
});
const handleSnippetClick = (cmd: string) => {
if (sessionRef.current) {
terminalBackend.writeToSession(sessionRef.current, `${cmd}\r`);
const payload = `${cmd}\r`;
terminalBackend.writeToSession(sessionRef.current, payload);
scrollToBottomAfterProgrammaticInput(payload);
setIsScriptsOpen(false);
termRef.current?.focus();
return;
@@ -1011,6 +1102,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
if (!termRef.current) return;
cleanupSession();
auth.resetForRetry();
hasRunStartupCommandRef.current = false;
setStatus("connecting");
setError(null);
setProgressLogs(["Retrying secure channel..."]);
@@ -1080,6 +1172,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
const pathsText = paths.join(' ');
// Write the paths to the terminal
terminalBackend.writeToSession(sessionRef.current, pathsText);
scrollToBottomAfterProgrammaticInput(pathsText);
termRef.current.focus();
}
} else {
@@ -1144,8 +1237,6 @@ const TerminalComponent: React.FC<TerminalProps> = ({
: status === "connecting"
? "bg-amber-400"
: "bg-rose-500";
const _isConnecting = status === "connecting";
const _hasError = Boolean(error);
return (
<TerminalContextMenu
@@ -1153,6 +1244,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
hotkeyScheme={hotkeyScheme}
keyBindings={keyBindings}
rightClickBehavior={terminalSettings?.rightClickBehavior}
isAlternateScreen={hasMouseTracking}
onCopy={terminalContextActions.onCopy}
onPaste={terminalContextActions.onPaste}
onSelectAll={terminalContextActions.onSelectAll}
@@ -1638,6 +1730,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
if (sessionRef.current) {
const payload = text + '\r';
terminalBackend.writeToSession(sessionRef.current, payload);
scrollToBottomAfterProgrammaticInput(payload);
onBroadcastInput?.(payload, sessionRef.current);
}
}}

View File

@@ -70,18 +70,6 @@ const ThemeSelectPanel: React.FC<ThemeSelectPanelProps> = ({
return [...TERMINAL_THEMES, ...customThemes];
}, [customThemes]);
// Group themes by type - reserved for future sectioned view
const _groupedThemes = useMemo(() => {
const dark = allThemes.filter(t => t.type === 'dark');
const light = allThemes.filter(t => t.type === 'light');
return { dark, light };
}, [allThemes]);
// Find selected theme info - reserved for displaying selection details
const _selectedTheme = useMemo(() => {
return allThemes.find(t => t.id === selectedThemeId);
}, [selectedThemeId, allThemes]);
const renderThemeItem = (theme: TerminalTheme) => {
const isSelected = theme.id === selectedThemeId;

View File

@@ -2495,7 +2495,6 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
open={isQuickConnectOpen}
target={quickConnectTarget}
keys={keys}
knownHosts={knownHosts}
onConnect={handleQuickConnect}
onSaveHost={handleQuickConnectSaveHost}
onClose={() => {

View File

@@ -1,94 +0,0 @@
/**
* Edit Key Panel - Edit existing SSH key
*/
import { Info } from 'lucide-react';
import React from 'react';
import { useI18n } from '../../application/i18n/I18nProvider';
import { SSHKey } from '../../types';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
import { Label } from '../ui/label';
import { Textarea } from '../ui/textarea';
interface EditKeyPanelProps {
draftKey: Partial<SSHKey>;
_originalKey: SSHKey; // Reserved for future diff/comparison feature
setDraftKey: (key: Partial<SSHKey>) => void;
onExport: () => void;
onSave: () => void;
}
export const EditKeyPanel: React.FC<EditKeyPanelProps> = ({
draftKey,
_originalKey, // Reserved for future diff/comparison feature
setDraftKey,
onExport,
onSave,
}) => {
const { t } = useI18n();
return (
<>
<div className="space-y-2">
<Label>{t('keychain.field.labelRequired')}</Label>
<Input
value={draftKey.label || ''}
onChange={e => setDraftKey({ ...draftKey, label: e.target.value })}
placeholder={t('keychain.field.labelPlaceholder')}
/>
</div>
<div className="space-y-2">
<Label className="text-destructive">{t('keychain.field.privateKeyRequired')}</Label>
<Textarea
value={draftKey.privateKey || ''}
onChange={e => setDraftKey({ ...draftKey, privateKey: e.target.value })}
placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"
className="min-h-[180px] font-mono text-xs"
/>
</div>
<div className="space-y-2">
<Label className="text-muted-foreground">{t('keychain.field.publicKey')}</Label>
<Textarea
value={draftKey.publicKey || ''}
onChange={e => setDraftKey({ ...draftKey, publicKey: e.target.value })}
placeholder="ssh-ed25519 AAAA..."
className="min-h-[80px] font-mono text-xs"
/>
</div>
<div className="space-y-2">
<Label className="text-muted-foreground">{t('terminal.auth.certificate')}</Label>
<Textarea
value={draftKey.certificate || ''}
onChange={e => setDraftKey({ ...draftKey, certificate: e.target.value })}
placeholder={t('keychain.field.certificatePlaceholder')}
className="min-h-[60px] font-mono text-xs"
/>
</div>
{/* Key Export section */}
<div className="pt-4 mt-4 border-t border-border/60">
<div className="flex items-center gap-2 mb-3">
<span className="text-sm font-medium">{t('keychain.export.title')}</span>
<div className="h-4 w-4 rounded-full bg-muted flex items-center justify-center">
<Info size={10} className="text-muted-foreground" />
</div>
</div>
<Button className="w-full h-11" onClick={onExport}>
{t('keychain.export.exportToHost')}
</Button>
</div>
{/* Save button */}
<Button
className="w-full h-11 mt-4"
disabled={!draftKey.label?.trim() || !draftKey.privateKey?.trim()}
onClick={onSave}
>
{t('common.saveChanges')}
</Button>
</>
);
};

View File

@@ -1,246 +0,0 @@
/**
* Export Key Panel - Export SSH key to remote host
*/
import { ChevronRight, Info } from 'lucide-react';
import React, { useState } from 'react';
import { useKeychainBackend } from '../../application/state/useKeychainBackend';
import { useI18n } from '../../application/i18n/I18nProvider';
import { resolveHostAuth } from '../../domain/sshAuth';
import { cn } from '../../lib/utils';
import { Host, Identity, SSHKey } from '../../types';
import { Button } from '../ui/button';
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible';
import { Input } from '../ui/input';
import { Label } from '../ui/label';
import { Textarea } from '../ui/textarea';
import { toast } from '../ui/toast';
import { getKeyIcon, getKeyTypeDisplay, isMacOS } from './utils';
interface ExportKeyPanelProps {
keyItem: SSHKey;
_hosts: Host[]; // Reserved for future inline host list/validation
keys: SSHKey[];
identities: Identity[];
exportHost: Host | null;
_setExportHost: (host: Host | null) => void; // Host selection handled by onShowHostSelector callback
onShowHostSelector: () => void;
onSaveHost?: (host: Host) => void;
onClose: () => void;
}
const DEFAULT_EXPORT_SCRIPT = `DIR="$HOME/$1"
FILE="$DIR/$2"
if [ ! -d "$DIR" ]; then
mkdir -p "$DIR"
chmod 700 "$DIR"
fi
if [ ! -f "$FILE" ]; then
touch "$FILE"
chmod 600 "$FILE"
fi
echo $3 >> "$FILE"`;
export const ExportKeyPanel: React.FC<ExportKeyPanelProps> = ({
keyItem,
_hosts, // Reserved for future inline host list/validation
keys,
identities,
exportHost,
_setExportHost, // Host selection handled by onShowHostSelector callback
onShowHostSelector,
onSaveHost,
onClose,
}) => {
const { t } = useI18n();
const { execCommand } = useKeychainBackend();
const [exportLocation, setExportLocation] = useState('.ssh');
const [exportFilename, setExportFilename] = useState('authorized_keys');
const [exportAdvancedOpen, setExportAdvancedOpen] = useState(false);
const [exportScript, setExportScript] = useState(DEFAULT_EXPORT_SCRIPT);
const [isExporting, setIsExporting] = useState(false);
const isMac = isMacOS();
const handleExport = async () => {
if (!exportHost || !keyItem.publicKey) return;
setIsExporting(true);
try {
const exportAuth = resolveHostAuth({ host: exportHost, keys, identities });
// Check for authentication method
if (!exportAuth.password && !exportAuth.key?.privateKey) {
throw new Error(t('keychain.export.missingCredentials'));
}
const hostPrivateKey = exportAuth.key?.privateKey;
// Escape the public key for shell
const escapedPublicKey = keyItem.publicKey.replace(/'/g, "'\\''");
// Build the command by replacing $1, $2, $3
const scriptWithVars = exportScript
.replace(/\$1/g, exportLocation)
.replace(/\$2/g, exportFilename)
.replace(/\$3/g, `'${escapedPublicKey}'`);
const command = scriptWithVars;
// Execute via SSH
const result = await execCommand({
hostname: exportHost.hostname,
username: exportAuth.username,
port: exportHost.port || 22,
password: exportAuth.password,
privateKey: hostPrivateKey,
command,
timeout: 30000,
enableKeyboardInteractive: true,
sessionId: `export-key:${exportHost.id}:${keyItem.id}`,
});
// Check result
const exitCode = result?.code;
const hasError = result?.stderr?.trim();
if (exitCode === 0 || (exitCode == null && !hasError)) {
// Update host to use this key for authentication
if (onSaveHost) {
const updatedHost: Host = {
...exportHost,
identityFileId: keyItem.id,
authMethod: 'key',
};
onSaveHost(updatedHost);
}
toast.success(
t('keychain.export.successMessage', { host: exportHost.label }),
t('keychain.export.successTitle'),
);
onClose();
} else {
const errorMsg = hasError || result?.stdout?.trim() || `Command exited with code ${exitCode}`;
toast.error(
t('keychain.export.failedMessage', { error: errorMsg }),
t('keychain.export.failedTitle'),
);
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
toast.error(
t('keychain.export.failedGeneric', { message }),
t('keychain.export.failedTitle'),
);
} finally {
setIsExporting(false);
}
};
return (
<>
{/* Key info card */}
<div className="flex items-center gap-3 p-3 bg-card border border-border/80 rounded-lg">
<div className={cn(
"h-10 w-10 rounded-md flex items-center justify-center",
keyItem.certificate
? "bg-emerald-500/15 text-emerald-500"
: "bg-primary/15 text-primary"
)}>
{getKeyIcon(keyItem)}
</div>
<div className="min-w-0 flex-1">
<p className="text-sm font-semibold truncate">{keyItem.label}</p>
<p className="text-xs text-muted-foreground">
{t('auth.keyType', { type: getKeyTypeDisplay(keyItem, isMac) })}
</p>
</div>
</div>
{/* Export to field */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-muted-foreground">{t('keychain.export.exportToRequired')}</Label>
<Button
variant="link"
className="h-auto p-0 text-primary text-sm"
onClick={onShowHostSelector}
>
{t('keychain.export.selectHost')}
</Button>
</div>
<Input
value={exportHost?.label || ''}
readOnly
placeholder={t('keychain.export.selectHostPlaceholder')}
className="bg-muted/50 cursor-pointer"
onClick={onShowHostSelector}
/>
</div>
{/* Location field */}
<div className="space-y-2">
<Label className="text-muted-foreground">{t('keychain.export.locationLabel')}</Label>
<Input
value={exportLocation}
onChange={e => setExportLocation(e.target.value)}
placeholder=".ssh"
/>
</div>
{/* Filename field */}
<div className="space-y-2">
<Label className="text-muted-foreground">{t('keychain.export.filenameLabel')}</Label>
<Input
value={exportFilename}
onChange={e => setExportFilename(e.target.value)}
placeholder="authorized_keys"
/>
</div>
{/* Info note */}
<div className="flex items-start gap-2 p-3 bg-muted/50 border border-border/60 rounded-lg">
<Info size={14} className="mt-0.5 text-muted-foreground shrink-0" />
<p className="text-xs text-muted-foreground">
{t('keychain.export.note.supportsOnly')}{' '}
<span className="font-semibold text-foreground">UNIX</span>{' '}
{t('keychain.export.note.systems')}{' '}
{t('keychain.export.note.use')}{' '}
<span className="font-semibold text-foreground">{t('keychain.export.advanced')}</span>{' '}
{t('keychain.export.note.customize')}
</p>
</div>
{/* Advanced collapsible */}
<Collapsible open={exportAdvancedOpen} onOpenChange={setExportAdvancedOpen}>
<CollapsibleTrigger asChild>
<Button variant="ghost" className="w-full justify-between px-0 h-10 hover:bg-transparent hover:text-current">
<span className="font-medium">{t('keychain.export.advanced')}</span>
<ChevronRight size={16} className={cn(
"transition-transform",
exportAdvancedOpen && "rotate-90"
)} />
</Button>
</CollapsibleTrigger>
<CollapsibleContent className="space-y-2 pt-2">
<Label className="text-muted-foreground">{t('keychain.export.scriptRequired')}</Label>
<Textarea
value={exportScript}
onChange={e => setExportScript(e.target.value)}
className="min-h-[180px] font-mono text-xs"
placeholder={t('keychain.export.scriptPlaceholder')}
/>
</CollapsibleContent>
</Collapsible>
{/* Export button */}
<Button
className="w-full h-11"
disabled={!exportHost || !exportLocation || !exportFilename || isExporting}
onClick={handleExport}
>
{isExporting ? t('keychain.export.exporting') : t('keychain.export.exportAndAttach')}
</Button>
</>
);
};

View File

@@ -15,8 +15,6 @@ export { IdentityCard } from './IdentityCard';
export { KeyCard } from './KeyCard';
// Panel components
export { EditKeyPanel } from './EditKeyPanel';
export { ExportKeyPanel } from './ExportKeyPanel';
export { GenerateStandardPanel } from './GenerateStandardPanel';
export { IdentityPanel } from './IdentityPanel';
export { ImportKeyPanel } from './ImportKeyPanel';

View File

@@ -1,5 +1,5 @@
import React, { useCallback } from "react";
import { Check, Moon, Palette, Sun } from "lucide-react";
import { Check, Monitor, Moon, Palette, Sun } from "lucide-react";
import { useI18n } from "../../../application/i18n/I18nProvider";
import { DARK_UI_THEMES, LIGHT_UI_THEMES } from "../../../infrastructure/config/uiThemes";
import { useAvailableUIFonts } from "../../../application/state/uiFontStore";
@@ -9,8 +9,8 @@ import { SectionHeader, SettingsTabContent, SettingRow, Toggle, Select } from ".
import { FontSelect } from "../FontSelect";
export default function SettingsAppearanceTab(props: {
theme: "dark" | "light";
setTheme: (theme: "dark" | "light") => void;
theme: "dark" | "light" | "system";
setTheme: (theme: "dark" | "light" | "system") => void;
lightUiThemeId: string;
setLightUiThemeId: (themeId: string) => void;
darkUiThemeId: string;
@@ -97,6 +97,12 @@ export default function SettingsAppearanceTab(props: {
{ name: "Slate", value: "215 16% 47%" },
];
const THEME_OPTIONS: { value: "light" | "system" | "dark"; icon: React.ReactNode; label: string }[] = [
{ value: "light", icon: <Sun size={14} />, label: t("settings.appearance.theme.light") },
{ value: "system", icon: <Monitor size={14} />, label: t("settings.appearance.theme.system") },
{ value: "dark", icon: <Moon size={14} />, label: t("settings.appearance.theme.dark") },
];
const renderThemeSwatches = (
options: { id: string; name: string; tokens: { background: string } }[],
value: string,
@@ -153,13 +159,25 @@ export default function SettingsAppearanceTab(props: {
<SectionHeader title={t("settings.appearance.uiTheme")} />
<div className="space-y-0 divide-y divide-border rounded-lg border bg-card px-4">
<SettingRow
label={t("settings.appearance.darkMode")}
description={t("settings.appearance.darkMode.desc")}
label={t("settings.appearance.theme")}
description={t("settings.appearance.theme.desc")}
>
<div className="flex items-center gap-2">
<Sun size={14} className="text-muted-foreground" />
<Toggle checked={theme === "dark"} onChange={(v) => setTheme(v ? "dark" : "light")} />
<Moon size={14} className="text-muted-foreground" />
<div className="flex items-center rounded-lg border border-border bg-muted/50 p-0.5">
{THEME_OPTIONS.map((opt) => (
<button
key={opt.value}
onClick={() => setTheme(opt.value)}
className={cn(
"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-colors",
theme === opt.value
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
)}
>
{opt.icon}
{opt.label}
</button>
))}
</div>
</SettingRow>
</div>

View File

@@ -1,51 +1,73 @@
import React, { useCallback } from "react";
import type { Host, Identity, Snippet, SSHKey } from "../../../domain/models";
import type { PortForwardingRule } from "../../../domain/models";
import type { SyncPayload } from "../../../domain/sync";
import { buildSyncPayload, applySyncPayload } from "../../../domain/syncPayload";
import type { SyncableVaultData } from "../../../domain/syncPayload";
import { STORAGE_KEY_PORT_FORWARDING } from "../../../infrastructure/config/storageKeys";
import { localStorageAdapter } from "../../../infrastructure/persistence/localStorageAdapter";
import { CloudSyncSettings } from "../../CloudSyncSettings";
import { SettingsTabContent } from "../settings-ui";
export default function SettingsSyncTab(props: {
hosts: Host[];
keys: SSHKey[];
identities: Identity[];
snippets: Snippet[];
vault: SyncableVaultData;
portForwardingRules: PortForwardingRule[];
importDataFromString: (data: string) => void;
importPortForwardingRules: (rules: PortForwardingRule[]) => void;
clearVaultData: () => void;
}) {
const { hosts, keys, identities, snippets, importDataFromString, clearVaultData } = props;
const {
vault,
portForwardingRules,
importDataFromString,
importPortForwardingRules,
clearVaultData,
} = props;
const buildSyncPayload = useCallback((): SyncPayload => {
return {
hosts,
keys,
identities,
snippets,
customGroups: [],
syncedAt: Date.now(),
};
}, [hosts, keys, identities, snippets]);
const applySyncPayload = useCallback(
(payload: SyncPayload) => {
importDataFromString(
JSON.stringify({
hosts: payload.hosts,
keys: payload.keys,
identities: payload.identities,
snippets: payload.snippets,
customGroups: payload.customGroups,
}),
const onBuildPayload = useCallback((): SyncPayload => {
// If hook state is empty but localStorage has data, the async store
// initialization hasn't finished yet. Read from localStorage directly
// to avoid uploading empty arrays and overwriting the remote snapshot.
let effectiveRules = portForwardingRules;
if (effectiveRules.length === 0) {
const stored = localStorageAdapter.read<PortForwardingRule[]>(
STORAGE_KEY_PORT_FORWARDING,
);
if (stored && Array.isArray(stored) && stored.length > 0) {
// Strip transient per-device fields (status, error, lastUsedAt)
// that setGlobalRules persists to localStorage but shouldn't be
// included in the cloud sync snapshot.
effectiveRules = stored.map(({ status: _status, error: _error, ...rest }) => ({
...rest,
status: "inactive" as const,
error: undefined,
lastUsedAt: undefined,
}));
}
}
return buildSyncPayload(vault, effectiveRules);
}, [vault, portForwardingRules]);
const onApplyPayload = useCallback(
(payload: SyncPayload) => {
applySyncPayload(payload, {
importVaultData: importDataFromString,
importPortForwardingRules,
});
},
[importDataFromString],
[importDataFromString, importPortForwardingRules],
);
const clearAllLocalData = useCallback(() => {
clearVaultData();
importPortForwardingRules([]);
}, [clearVaultData, importPortForwardingRules]);
return (
<SettingsTabContent value="sync">
<CloudSyncSettings
onBuildPayload={buildSyncPayload}
onApplyPayload={applySyncPayload}
onClearLocalData={clearVaultData}
onBuildPayload={onBuildPayload}
onApplyPayload={onApplyPayload}
onClearLocalData={clearAllLocalData}
/>
</SettingsTabContent>
);

View File

@@ -1,11 +1,12 @@
/**
* Settings System Tab - System information, temp file management, session logs, and global hotkey
*/
import { FileText, FolderOpen, HardDrive, Keyboard, RefreshCw, RotateCcw, Trash2 } from "lucide-react";
import { Download, ExternalLink, FileText, FolderOpen, HardDrive, Keyboard, RefreshCw, RotateCcw, Trash2 } from "lucide-react";
import React, { useCallback, useEffect, useState } from "react";
import { useI18n } from "../../../application/i18n/I18nProvider";
import { getCredentialProtectionAvailability } from "../../../infrastructure/services/credentialProtection";
import { netcattyBridge } from "../../../infrastructure/services/netcattyBridge";
import type { UpdateState } from '../../../application/state/useUpdateCheck';
import { SessionLogFormat, keyEventToString } from "../../../domain/models";
import { TabsContent } from "../../ui/tabs";
import { Button } from "../../ui/button";
@@ -26,6 +27,22 @@ function formatBytes(bytes: number): string {
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
}
/** Returns a locale-agnostic relative time string for the given timestamp. */
function formatLastChecked(
timestamp: number | null,
t: (key: string) => string,
): string {
if (!timestamp) return '';
const diffMs = Date.now() - timestamp;
if (diffMs < 0) return t('settings.update.lastCheckedJustNow');
const diffMins = Math.floor(diffMs / 60000);
if (diffMins < 1) return t('settings.update.lastCheckedJustNow');
if (diffMins < 60)
return t('settings.update.lastCheckedMinutesAgo').replace('{n}', String(diffMins));
const diffHours = Math.floor(diffMins / 60);
return t('settings.update.lastCheckedHoursAgo').replace('{n}', String(diffHours));
}
interface SettingsSystemTabProps {
sessionLogsEnabled: boolean;
setSessionLogsEnabled: (enabled: boolean) => void;
@@ -38,6 +55,11 @@ interface SettingsSystemTabProps {
closeToTray: boolean;
setCloseToTray: (enabled: boolean) => void;
hotkeyRegistrationError: string | null;
// Unified update state — from useUpdateCheck hook in SettingsPageContent
updateState: UpdateState;
checkNow: () => Promise<unknown>;
installUpdate: () => void;
openReleasePage: () => void;
}
const SettingsSystemTab: React.FC<SettingsSystemTabProps> = ({
@@ -52,6 +74,10 @@ const SettingsSystemTab: React.FC<SettingsSystemTabProps> = ({
closeToTray,
setCloseToTray,
hotkeyRegistrationError,
updateState,
checkNow,
installUpdate,
openReleasePage,
}) => {
const { t } = useI18n();
const isMac = typeof navigator !== "undefined" && /Mac/i.test(navigator.platform);
@@ -65,6 +91,18 @@ const SettingsSystemTab: React.FC<SettingsSystemTabProps> = ({
const [credentialsAvailable, setCredentialsAvailable] = useState<boolean | null>(null);
const [isCheckingCredentials, setIsCheckingCredentials] = useState(false);
const [appVersion, setAppVersion] = useState('');
// Load app version on mount
useEffect(() => {
const promise = netcattyBridge.get()?.getAppInfo?.();
if (promise) {
promise.then((info) => {
setAppVersion(info?.version ?? '');
}).catch(() => {});
}
}, []);
const loadTempDirInfo = useCallback(async () => {
const bridge = netcattyBridge.get();
if (!bridge?.getTempDirInfo) return;
@@ -218,6 +256,129 @@ const SettingsSystemTab: React.FC<SettingsSystemTabProps> = ({
</p>
</div>
{/* Software Update Section */}
<div className="space-y-4">
<div className="flex items-center gap-2">
<Download size={18} className="text-muted-foreground" />
<h3 className="text-base font-medium">{t('settings.update.title')}</h3>
</div>
<div className="rounded-lg border border-border/60 p-4 space-y-3">
{/* Current version */}
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">
{t('settings.update.currentVersion')}
</span>
<span className="text-sm font-mono">
{updateState.currentVersion || appVersion || '...'}
</span>
</div>
{/* Status message — priority: autoDownloadStatus > isChecking/manualCheckStatus */}
{updateState.autoDownloadStatus === 'downloading' && (
<div className="space-y-2">
<p className="text-sm text-muted-foreground">
{t('settings.update.downloading').replace('{percent}', String(updateState.downloadPercent))}
</p>
<div className="h-2 w-full rounded-full bg-muted overflow-hidden">
<div
className="h-full rounded-full bg-primary transition-all duration-300"
style={{ width: `${updateState.downloadPercent}%` }}
/>
</div>
</div>
)}
{updateState.autoDownloadStatus === 'ready' && (
<p className="text-sm text-green-600 dark:text-green-400">
{t('settings.update.readyToInstall')}
</p>
)}
{updateState.autoDownloadStatus === 'error' && (
<p className="text-sm text-destructive">
{updateState.downloadError || t('settings.update.error')}
</p>
)}
{updateState.autoDownloadStatus === 'idle' && (
<>
{updateState.manualCheckStatus === 'up-to-date' && (
<p className="text-sm text-green-600 dark:text-green-400">
{t('settings.update.upToDate')}
</p>
)}
{(updateState.manualCheckStatus === 'available' || (updateState.manualCheckStatus === 'idle' && updateState.hasUpdate)) && (
<p className="text-sm text-blue-600 dark:text-blue-400">
{t('settings.update.available').replace(
'{version}',
updateState.latestRelease?.version ?? ''
)}
</p>
)}
{updateState.manualCheckStatus === 'error' && (
<p className="text-sm text-destructive">
{updateState.error || t('settings.update.error')}
</p>
)}
</>
)}
{/* Action buttons */}
<div className="flex items-center gap-2 pt-1">
{/* Checking spinner — shown when isChecking OR manualCheckStatus=checking, but no active download */}
{(updateState.autoDownloadStatus === 'idle' || updateState.autoDownloadStatus === 'error') &&
(updateState.isChecking || updateState.manualCheckStatus === 'checking') ? (
<Button variant="outline" size="sm" disabled>
<RefreshCw size={14} className="mr-1.5 animate-spin" />
{t('settings.update.checking')}
</Button>
) : (updateState.autoDownloadStatus === 'idle' || updateState.autoDownloadStatus === 'error') ? (
/* Check button — shown in idle states and in error state (allows retry) */
<Button
variant="outline"
size="sm"
onClick={() => void checkNow()}
>
<RefreshCw size={14} className="mr-1.5" />
{t('settings.update.checkForUpdates')}
</Button>
) : null}
{/* Install button — shown when download is complete */}
{updateState.autoDownloadStatus === 'ready' && (
<Button variant="default" size="sm" onClick={installUpdate}>
<RotateCcw size={14} className="mr-1.5" />
{t('settings.update.restartNow')}
</Button>
)}
{/* Open releases — shown on download error */}
{updateState.autoDownloadStatus === 'error' && (
<Button variant="ghost" size="sm" onClick={openReleasePage}>
<ExternalLink size={14} className="mr-1.5" />
{t('settings.update.manualDownload')}
</Button>
)}
{/* Open releases — shown when update found on unsupported platform, or on check error */}
{updateState.autoDownloadStatus === 'idle' &&
(updateState.manualCheckStatus === 'available' || updateState.manualCheckStatus === 'error' || (updateState.manualCheckStatus === 'idle' && updateState.hasUpdate)) && (
<Button variant="ghost" size="sm" onClick={openReleasePage}>
<ExternalLink size={14} className="mr-1.5" />
{t('settings.update.manualDownload')}
</Button>
)}
</div>
</div>
<p className="text-xs text-muted-foreground">
{updateState.lastCheckedAt && (
<span>
{t('settings.update.lastCheckedPrefix')}
{formatLastChecked(updateState.lastCheckedAt, t)}
{' '}
</span>
)}
{t('settings.update.hint')}
</p>
</div>
{/* Credential Protection Section */}
<div className="space-y-4">
<div className="flex items-center gap-2">

View File

@@ -17,7 +17,8 @@ interface SftpModalFileListProps {
t: (key: string, params?: Record<string, unknown>) => string;
currentPath: string;
isLocalSession: boolean;
files: RemoteFile[];
hasFiles: boolean;
hasDisplayFiles: boolean;
selectedFiles: Set<string>;
dragActive: boolean;
loading: boolean;
@@ -60,7 +61,8 @@ export const SftpModalFileList: React.FC<SftpModalFileListProps> = ({
t,
currentPath,
isLocalSession,
files,
hasFiles,
hasDisplayFiles,
selectedFiles,
dragActive,
loading,
@@ -169,7 +171,7 @@ export const SftpModalFileList: React.FC<SftpModalFileListProps> = ({
</div>
)}
{loading && files.length === 0 && (
{loading && !hasFiles && (
<div className="absolute inset-0 flex items-center justify-center bg-background/80">
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
</div>
@@ -200,7 +202,7 @@ export const SftpModalFileList: React.FC<SftpModalFileListProps> = ({
</div>
)}
{files.length === 0 && !loading && (
{!hasDisplayFiles && !loading && (
<div className="flex flex-col items-center justify-center h-full text-muted-foreground">
<Folder size={48} className="mb-3 opacity-50" />
<div className="text-sm font-medium">{t("sftp.emptyDirectory")}</div>

View File

@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react";
import { ArrowUp, Bookmark, Check, ChevronRight, FilePlus, FolderPlus, FolderUp, Home, Languages, MoreHorizontal, RefreshCw, Trash2, Upload } from "lucide-react";
import { ArrowUp, Bookmark, Check, ChevronRight, Eye, EyeOff, FilePlus, FolderPlus, FolderUp, Home, Languages, MoreHorizontal, RefreshCw, Trash2, Upload } from "lucide-react";
import { cn } from "../../lib/utils";
import type { Host, SftpFilenameEncoding } from "../../types";
import { useSftpBookmarks } from "../sftp/hooks/useSftpBookmarks";
@@ -51,6 +51,8 @@ interface SftpModalHeaderProps {
onCreateFile: () => void;
onFileSelect: (e: React.ChangeEvent<HTMLInputElement>) => void;
onFolderSelect: (e: React.ChangeEvent<HTMLInputElement>) => void;
showHiddenFiles: boolean;
onToggleShowHiddenFiles: () => void;
onUpdateHost?: (host: Host) => void;
onNavigateToBookmark?: (path: string) => void;
}
@@ -91,6 +93,8 @@ export const SftpModalHeader: React.FC<SftpModalHeaderProps> = ({
onCreateFile,
onFileSelect,
onFolderSelect,
showHiddenFiles,
onToggleShowHiddenFiles,
onUpdateHost,
onNavigateToBookmark,
}) => {
@@ -302,6 +306,22 @@ export const SftpModalHeader: React.FC<SftpModalHeaderProps> = ({
</PopoverContent>
</Popover>
)}
<Tooltip
open={openTooltip === 'showHiddenFiles'}
onOpenChange={handleTooltipOpenChange('showHiddenFiles')}
>
<TooltipTrigger asChild>
<Button
variant={showHiddenFiles ? "secondary" : "ghost"}
size="icon"
className={cn("h-7 w-7", showHiddenFiles && "text-primary")}
onClick={onToggleShowHiddenFiles}
>
{showHiddenFiles ? <EyeOff size={14} /> : <Eye size={14} />}
</Button>
</TooltipTrigger>
<TooltipContent>{t("settings.sftp.showHiddenFiles")}</TooltipContent>
</Tooltip>
<div className="flex items-center gap-1 text-sm flex-1 min-w-0 overflow-hidden">
{isEditingPath ? (

View File

@@ -13,6 +13,7 @@ interface TransferTask {
status: "pending" | "uploading" | "downloading" | "completed" | "failed" | "cancelled";
error?: string;
direction: "upload" | "download";
targetPath?: string;
}
interface SftpModalUploadTasksProps {
@@ -166,6 +167,9 @@ export const SftpModalUploadTasks: React.FC<SftpModalUploadTasksProps> = ({ task
{task.status === "completed" && (
<div className="text-[10px] text-green-600 mt-0.5">
{t(task.direction === "download" ? "sftp.download.completed" : "sftp.upload.completed")} - {formatBytes(task.totalBytes)}
{task.targetPath && (
<span className="text-muted-foreground ml-1"> {task.targetPath}</span>
)}
</div>
)}
{task.status === "cancelled" && (

View File

@@ -53,6 +53,7 @@ interface UseSftpModalSessionParams {
interface UseSftpModalSessionResult {
currentPath: string;
setCurrentPath: (path: string) => void;
currentPathRef: React.MutableRefObject<string>;
files: RemoteFile[];
setFiles: (files: RemoteFile[]) => void;
loading: boolean;
@@ -428,6 +429,7 @@ export const useSftpModalSession = ({
return {
currentPath,
setCurrentPath,
currentPathRef,
files,
setFiles,
loading,

View File

@@ -27,6 +27,7 @@ interface TransferTask {
fileCount?: number;
completedCount?: number;
direction: "upload" | "download";
targetPath?: string;
}
// Keep UploadTask as alias for backwards compatibility
@@ -34,6 +35,7 @@ type UploadTask = TransferTask;
interface UseSftpModalTransfersParams {
currentPath: string;
currentPathRef: React.MutableRefObject<string>;
isLocalSession: boolean;
joinPath: (base: string, name: string) => string;
ensureSftp: () => Promise<string>;
@@ -98,6 +100,7 @@ interface UseSftpModalTransfersResult {
export const useSftpModalTransfers = ({
currentPath,
currentPathRef,
isLocalSession,
joinPath,
ensureSftp,
@@ -213,8 +216,16 @@ export const useSftpModalTransfers = ({
};
}, [writeLocalFile, mkdirLocal, mkdirSftp, writeSftpBinary, writeSftpBinaryWithProgress, cancelSftpUpload, startStreamTransfer, cancelTransfer]);
const refreshTargetPathIfCurrent = useCallback(
async (targetPath: string) => {
if (currentPathRef.current !== targetPath) return;
await loadFiles(targetPath, { force: true });
},
[currentPathRef, loadFiles],
);
// Create upload callbacks
const createUploadCallbacks = useCallback((): UploadCallbacks => {
const createUploadCallbacks = useCallback((targetPath: string): UploadCallbacks => {
return {
onScanningStart: (taskId: string) => {
const scanningTask: UploadTask = {
@@ -246,6 +257,7 @@ export const useSftpModalTransfers = ({
startTime: Date.now(),
isDirectory: task.isDirectory,
direction: "upload",
targetPath,
};
setUploadTasks(prev => [...prev, uploadTask]);
},
@@ -348,11 +360,13 @@ export const useSftpModalTransfers = ({
// Helper function to perform upload with compression setting from user preference
const performUpload = useCallback(async (
files: FileList | File[],
useCompressed: boolean
useCompressed: boolean,
targetPathOverride?: string,
): Promise<void> => {
if (files.length === 0) return;
setUploading(true);
const targetPath = targetPathOverride ?? currentPathRef.current;
// Get SFTP ID for remote sessions
let sftpId: string | null = null;
@@ -365,13 +379,13 @@ export const useSftpModalTransfers = ({
const controller = new UploadController();
uploadControllerRef.current = controller;
const callbacks = createUploadCallbacks();
const callbacks = createUploadCallbacks(targetPath);
try {
await uploadFromFileList(
files,
{
targetPath: currentPath,
targetPath,
sftpId,
isLocal: isLocalSession,
bridge: createUploadBridge,
@@ -382,7 +396,7 @@ export const useSftpModalTransfers = ({
controller
);
await loadFiles(currentPath, { force: true });
await refreshTargetPathIfCurrent(targetPath);
} catch (error) {
toast.error(
error instanceof Error ? error.message : t("sftp.error.uploadFailed"),
@@ -394,7 +408,7 @@ export const useSftpModalTransfers = ({
uploadControllerRef.current = null;
cachedSftpIdRef.current = null;
}
}, [currentPath, createUploadBridge, createUploadCallbacks, ensureSftp, isLocalSession, joinPath, loadFiles, t]);
}, [createUploadBridge, createUploadCallbacks, currentPathRef, ensureSftp, isLocalSession, joinPath, refreshTargetPathIfCurrent, t]);
const handleDownload = useCallback(
async (file: RemoteFile) => {
@@ -818,6 +832,7 @@ export const useSftpModalTransfers = ({
const handleUploadFromDrop = useCallback(
async (dataTransfer: DataTransfer) => {
setUploading(true);
const targetPath = currentPathRef.current;
// Get SFTP ID for remote sessions
let sftpId: string | null = null;
@@ -830,13 +845,13 @@ export const useSftpModalTransfers = ({
const controller = new UploadController();
uploadControllerRef.current = controller;
const callbacks = createUploadCallbacks();
const callbacks = createUploadCallbacks(targetPath);
try {
await uploadFromDataTransfer(
dataTransfer,
{
targetPath: currentPath,
targetPath,
sftpId,
isLocal: isLocalSession,
bridge: createUploadBridge,
@@ -847,7 +862,7 @@ export const useSftpModalTransfers = ({
controller
);
await loadFiles(currentPath, { force: true });
await refreshTargetPathIfCurrent(targetPath);
} catch (error) {
toast.error(
error instanceof Error ? error.message : t("sftp.error.uploadFailed"),
@@ -860,7 +875,7 @@ export const useSftpModalTransfers = ({
cachedSftpIdRef.current = null;
}
},
[currentPath, createUploadBridge, createUploadCallbacks, ensureSftp, isLocalSession, joinPath, loadFiles, t, useCompressedUpload],
[createUploadBridge, createUploadCallbacks, currentPathRef, ensureSftp, isLocalSession, joinPath, refreshTargetPathIfCurrent, t, useCompressedUpload],
);
// Handle upload from DropEntry array (used for drag-and-drop to terminal)
@@ -869,6 +884,7 @@ export const useSftpModalTransfers = ({
if (entries.length === 0) return;
setUploading(true);
const targetPath = currentPathRef.current;
// Get SFTP ID for remote sessions
let sftpId: string | null = null;
@@ -881,13 +897,13 @@ export const useSftpModalTransfers = ({
const controller = new UploadController();
uploadControllerRef.current = controller;
const callbacks = createUploadCallbacks();
const callbacks = createUploadCallbacks(targetPath);
try {
await uploadEntriesDirect(
entries,
{
targetPath: currentPath,
targetPath,
sftpId,
isLocal: isLocalSession,
bridge: createUploadBridge,
@@ -898,7 +914,7 @@ export const useSftpModalTransfers = ({
controller
);
await loadFiles(currentPath, { force: true });
await refreshTargetPathIfCurrent(targetPath);
} catch (error) {
toast.error(
error instanceof Error ? error.message : t("sftp.error.uploadFailed"),
@@ -911,7 +927,7 @@ export const useSftpModalTransfers = ({
cachedSftpIdRef.current = null;
}
},
[currentPath, createUploadBridge, createUploadCallbacks, ensureSftp, isLocalSession, joinPath, loadFiles, t, useCompressedUpload],
[createUploadBridge, createUploadCallbacks, currentPathRef, ensureSftp, isLocalSession, joinPath, refreshTargetPathIfCurrent, t, useCompressedUpload],
);
// Handle upload from File array (used by file input after copying files)

View File

@@ -98,9 +98,6 @@ export interface SftpContextValue {
// Callbacks for each side
leftCallbacks: SftpPaneCallbacks;
rightCallbacks: SftpPaneCallbacks;
// Settings
showHiddenFiles: boolean;
}
const SftpContext = createContext<SftpContextValue | null>(null);
@@ -140,12 +137,6 @@ export const useSftpUpdateHosts = () => {
return context.updateHosts;
};
// Hook to get showHiddenFiles setting
export const useSftpShowHiddenFiles = (): boolean => {
const context = useSftpContext();
return context.showHiddenFiles;
};
interface SftpContextProviderProps {
hosts: Host[];
updateHosts: (hosts: Host[]) => void;
@@ -153,7 +144,6 @@ interface SftpContextProviderProps {
dragCallbacks: SftpDragCallbacks;
leftCallbacks: SftpPaneCallbacks;
rightCallbacks: SftpPaneCallbacks;
showHiddenFiles: boolean;
children: React.ReactNode;
}
@@ -164,7 +154,6 @@ export const SftpContextProvider: React.FC<SftpContextProviderProps> = ({
dragCallbacks,
leftCallbacks,
rightCallbacks,
showHiddenFiles,
children,
}) => {
// Memoize the context value to prevent unnecessary re-renders
@@ -177,9 +166,8 @@ export const SftpContextProvider: React.FC<SftpContextProviderProps> = ({
dragCallbacks,
leftCallbacks,
rightCallbacks,
showHiddenFiles,
}),
[hosts, updateHosts, draggedFiles, dragCallbacks, leftCallbacks, rightCallbacks, showHiddenFiles],
[hosts, updateHosts, draggedFiles, dragCallbacks, leftCallbacks, rightCallbacks],
);
return <SftpContext.Provider value={value}>{children}</SftpContext.Provider>;

View File

@@ -411,7 +411,7 @@ export const SftpPaneFileList: React.FC<SftpPaneFileListProps> = ({
{/* Loading overlay - covers entire pane when navigating directories */}
{pane.loading && sortedDisplayFiles.length > 0 && !pane.reconnecting && (
<div className="absolute inset-0 flex items-center justify-center bg-background/40 backdrop-blur-[1px] pointer-events-none z-10">
<div className="absolute inset-0 flex items-center justify-center bg-background/40 backdrop-blur-[1px] z-10">
<Loader2 size={24} className="animate-spin text-muted-foreground" />
</div>
)}

View File

@@ -1,5 +1,5 @@
import React from "react";
import { Bookmark, Check, ChevronLeft, FilePlus, Folder, FolderPlus, Home, Languages, RefreshCw, Search, Trash2, X } from "lucide-react";
import { Bookmark, Check, ChevronLeft, Eye, EyeOff, FilePlus, Folder, FolderPlus, Home, Languages, RefreshCw, Search, Trash2, X } from "lucide-react";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { Popover, PopoverClose, PopoverContent, PopoverTrigger } from "../ui/popover";
@@ -47,6 +47,8 @@ interface SftpPaneToolbarProps {
onToggleBookmark: () => void;
onNavigateToBookmark: (path: string) => void;
onDeleteBookmark: (id: string) => void;
showHiddenFiles: boolean;
onToggleShowHiddenFiles?: () => void;
}
export const SftpPaneToolbar: React.FC<SftpPaneToolbarProps> = ({
@@ -86,6 +88,8 @@ export const SftpPaneToolbar: React.FC<SftpPaneToolbarProps> = ({
onToggleBookmark,
onNavigateToBookmark,
onDeleteBookmark,
showHiddenFiles,
onToggleShowHiddenFiles,
}) => (
<>
{/* Toolbar - always visible when connected */}
@@ -300,6 +304,15 @@ export const SftpPaneToolbar: React.FC<SftpPaneToolbarProps> = ({
>
<FilePlus size={14} />
</Button>
<Button
variant={showHiddenFiles ? "secondary" : "ghost"}
size="icon"
className={cn("h-6 w-6", showHiddenFiles && "text-primary")}
onClick={onToggleShowHiddenFiles}
title={t("settings.sftp.showHiddenFiles")}
>
{showHiddenFiles ? <EyeOff size={14} /> : <Eye size={14} />}
</Button>
<Button
variant={showFilterBar || pane.filter ? "secondary" : "ghost"}
size="icon"

View File

@@ -12,7 +12,6 @@ import {
useSftpDrag,
useSftpHosts,
useSftpPaneCallbacks,
useSftpShowHiddenFiles,
useSftpUpdateHosts,
} from "./index";
import type { SftpPane } from "../../application/state/sftp/types";
@@ -58,6 +57,7 @@ interface SftpPaneViewProps {
pane: SftpPane;
showHeader?: boolean;
showEmptyHeader?: boolean;
onToggleShowHiddenFiles?: () => void;
}
const SftpPaneViewInner: React.FC<SftpPaneViewProps> = ({
@@ -65,13 +65,13 @@ const SftpPaneViewInner: React.FC<SftpPaneViewProps> = ({
pane,
showHeader = true,
showEmptyHeader = true,
onToggleShowHiddenFiles,
}) => {
const isActive = true;
const callbacks = useSftpPaneCallbacks(side);
const { draggedFiles, onDragStart, onDragEnd } = useSftpDrag();
const hosts = useSftpHosts();
const showHiddenFiles = useSftpShowHiddenFiles();
const { t } = useI18n();
const [, startTransition] = useTransition();
@@ -118,7 +118,7 @@ const SftpPaneViewInner: React.FC<SftpPaneViewProps> = ({
files: pane.files,
filter: pane.filter,
connection: pane.connection,
showHiddenFiles,
showHiddenFiles: pane.showHiddenFiles,
sortField,
sortOrder,
});
@@ -333,6 +333,8 @@ const SftpPaneViewInner: React.FC<SftpPaneViewProps> = ({
onToggleBookmark={toggleBookmark}
onNavigateToBookmark={callbacks.onNavigateTo}
onDeleteBookmark={deleteBookmark}
showHiddenFiles={pane.showHiddenFiles}
onToggleShowHiddenFiles={onToggleShowHiddenFiles}
/>
<SftpPaneFileList

View File

@@ -32,7 +32,6 @@ interface UseSftpKeyboardShortcutsParams {
hotkeyScheme: "disabled" | "mac" | "pc";
sftpRef: MutableRefObject<SftpStateApi>;
isActive: boolean;
showHiddenFiles: boolean;
}
/**
@@ -58,7 +57,6 @@ export const useSftpKeyboardShortcuts = ({
hotkeyScheme,
sftpRef,
isActive,
showHiddenFiles,
}: UseSftpKeyboardShortcutsParams) => {
const handleKeyDown = useCallback(
async (e: KeyboardEvent) => {
@@ -238,7 +236,7 @@ export const useSftpKeyboardShortcuts = ({
case "sftpSelectAll": {
// Select all files in the current pane
const term = pane.filter.trim().toLowerCase();
let visibleFiles = filterHiddenFiles(pane.files, showHiddenFiles, pane.connection.isLocal);
let visibleFiles = filterHiddenFiles(pane.files, pane.showHiddenFiles);
if (term) {
visibleFiles = visibleFiles.filter(
(f) => f.name === ".." || f.name.toLowerCase().includes(term),
@@ -280,7 +278,7 @@ export const useSftpKeyboardShortcuts = ({
}
}
},
[hotkeyScheme, isActive, keyBindings, sftpRef, showHiddenFiles]
[hotkeyScheme, isActive, keyBindings, sftpRef]
);
useEffect(() => {

View File

@@ -29,12 +29,12 @@ export const useSftpPaneFiles = ({
}: UseSftpPaneFilesParams): UseSftpPaneFilesResult => {
const filteredFiles = useMemo(() => {
const term = filter.trim().toLowerCase();
let nextFiles = filterHiddenFiles(files, showHiddenFiles, connection?.isLocal);
let nextFiles = filterHiddenFiles(files, showHiddenFiles);
if (!term) return nextFiles;
return nextFiles.filter(
(f) => f.name === ".." || f.name.toLowerCase().includes(term),
);
}, [files, filter, showHiddenFiles, connection?.isLocal]);
}, [files, filter, showHiddenFiles]);
const displayFiles = useMemo(() => {
if (!connection) return [];

View File

@@ -19,7 +19,6 @@ export {
useSftpDrag,
useSftpHosts,
useSftpUpdateHosts,
useSftpShowHiddenFiles,
useActiveTabId,
useIsPaneActive,
activeTabStore,

View File

@@ -192,39 +192,37 @@ export const isNavigableDirectory = (entry: SftpFileEntry): boolean => {
* Check if a file is hidden
* - Windows: checks the `hidden` attribute (set by localFsBridge)
* - Unix/Linux (remote): also treats dotfiles (names starting with '.') as hidden
* The ".." parent directory entry is never considered hidden.
/**
* A file is considered hidden if:
* - It has the Windows hidden attribute (`hidden === true`), OR
* - Its name starts with a dot (Unix/Linux dotfile convention)
*
* @param isLocal When true, only the Windows hidden attribute is checked.
* This prevents `.gitignore` etc. from disappearing on local Windows panes.
* The ".." parent directory entry is never considered hidden.
*/
export const isHiddenFile = <T extends { name: string; hidden?: boolean }>(
file: T,
isLocal?: boolean
): boolean => {
if (file.name === "..") return false;
// Windows hidden attribute — always checked
// Windows hidden attribute
if (file.hidden === true) return true;
// Unix/Linux dotfile convention — only on remote/non-local connections
if (!isLocal && file.name.startsWith(".")) return true;
// Unix/Linux dotfile convention
if (file.name.startsWith(".")) return true;
return false;
};
/** @deprecated Use isHiddenFile instead */
export const isWindowsHiddenFile = <T extends { name: string; hidden?: boolean }>(file: T): boolean =>
isHiddenFile(file, true);
isHiddenFile(file);
/**
* Filter files based on hidden file visibility setting.
* Filters Windows hidden files and, on remote connections, Unix/Linux dotfiles.
* Filters Windows hidden files and Unix/Linux dotfiles on all connections.
* Always preserves ".." parent directory entry.
*
* @param isLocal Pass true for local filesystem panes to skip dotfile filtering.
*/
export const filterHiddenFiles = <T extends { name: string; hidden?: boolean }>(
files: T[],
showHiddenFiles: boolean,
isLocal?: boolean
): T[] => {
if (showHiddenFiles) return files;
return files.filter((f) => !isHiddenFile(f, isLocal));
return files.filter((f) => !isHiddenFile(f));
};

View File

@@ -31,7 +31,7 @@ export interface TerminalConnectionDialogProps {
authProps: Omit<TerminalAuthDialogProps, 'keys'>;
keys: SSHKey[];
// Progress props
progressProps: Omit<TerminalConnectionProgressProps, 'status' | 'error' | 'showLogs' | '_setShowLogs'>;
progressProps: Omit<TerminalConnectionProgressProps, 'status' | 'error' | 'showLogs'>;
}
// Helper to get protocol display info
@@ -166,7 +166,6 @@ export const TerminalConnectionDialog: React.FC<TerminalConnectionDialogProps> =
status={status}
error={error}
showLogs={showLogs}
_setShowLogs={setShowLogs}
{...progressProps}
/>
)}

View File

@@ -14,7 +14,6 @@ export interface TerminalConnectionProgressProps {
timeLeft: number;
isCancelling: boolean;
showLogs: boolean;
_setShowLogs: (show: boolean) => void; // Reserved for future log toggle UI within this component
progressLogs: string[];
onCancel: () => void;
onRetry: () => void;
@@ -26,7 +25,6 @@ export const TerminalConnectionProgress: React.FC<TerminalConnectionProgressProp
timeLeft,
isCancelling,
showLogs,
_setShowLogs, // Reserved for future log toggle UI within this component
progressLogs,
onCancel,
onRetry,

View File

@@ -28,6 +28,7 @@ export interface TerminalContextMenuProps {
hotkeyScheme?: 'disabled' | 'mac' | 'pc';
keyBindings?: KeyBinding[];
rightClickBehavior?: RightClickBehavior;
isAlternateScreen?: boolean;
onCopy?: () => void;
onPaste?: () => void;
onSelectAll?: () => void;
@@ -44,6 +45,7 @@ export const TerminalContextMenu: React.FC<TerminalContextMenuProps> = ({
hotkeyScheme = 'mac',
keyBindings,
rightClickBehavior = 'context-menu',
isAlternateScreen = false,
onCopy,
onPaste,
onSelectAll,
@@ -73,10 +75,14 @@ export const TerminalContextMenu: React.FC<TerminalContextMenuProps> = ({
const splitVShortcut = getShortcut('split-vertical');
const clearShortcut = getShortcut('clear-buffer');
const showContextMenu = rightClickBehavior === 'context-menu';
const showContextMenu = rightClickBehavior === 'context-menu' && !isAlternateScreen;
const handleRightClick = useCallback(
(e: React.MouseEvent) => {
// In alternate screen (tmux, vim, etc.), let the terminal application
// handle right-click natively to avoid conflicting menus
if (isAlternateScreen) return;
if (rightClickBehavior === 'paste') {
e.preventDefault();
e.stopPropagation();
@@ -87,7 +93,7 @@ export const TerminalContextMenu: React.FC<TerminalContextMenuProps> = ({
onSelectWord?.();
}
},
[rightClickBehavior, onPaste, onSelectWord],
[rightClickBehavior, onPaste, onSelectWord, isAlternateScreen],
);
// Always use ContextMenu wrapper to maintain consistent React tree structure

View File

@@ -14,12 +14,14 @@ export const useTerminalContextActions = ({
terminalBackend,
onHasSelectionChange,
disableBracketedPasteRef,
scrollOnPasteRef,
}: {
termRef: RefObject<XTerm | null>;
sessionRef: RefObject<string | null>;
terminalBackend: TerminalBackendWriteApi;
onHasSelectionChange?: (hasSelection: boolean) => void;
disableBracketedPasteRef?: RefObject<boolean>;
scrollOnPasteRef?: RefObject<boolean>;
}) => {
const onCopy = useCallback(() => {
const term = termRef.current;
@@ -39,11 +41,19 @@ export const useTerminalContextActions = ({
let data = normalizeLineEndings(text);
if (term.modes.bracketedPasteMode && !disableBracketedPasteRef?.current) data = wrapBracketedPaste(data);
terminalBackend.writeToSession(sessionRef.current, data);
if (scrollOnPasteRef?.current) {
term.scrollToBottom();
if (typeof requestAnimationFrame === "function") {
requestAnimationFrame(() => {
term.scrollToBottom();
});
}
}
}
} catch (err) {
logger.warn("Failed to paste from clipboard", err);
}
}, [sessionRef, termRef, terminalBackend, disableBracketedPasteRef]);
}, [sessionRef, termRef, terminalBackend, disableBracketedPasteRef, scrollOnPasteRef]);
const onSelectAll = useCallback(() => {
const term = termRef.current;

View File

@@ -1,31 +0,0 @@
/**
* Terminal components module
* Re-exports all terminal sub-components
*/
export { TerminalAuthDialog } from './TerminalAuthDialog';
export type { TerminalAuthDialogProps } from './TerminalAuthDialog';
export { TerminalConnectionProgress } from './TerminalConnectionProgress';
export type { TerminalConnectionProgressProps } from './TerminalConnectionProgress';
export { TerminalToolbar } from './TerminalToolbar';
export type { TerminalToolbarProps } from './TerminalToolbar';
export { HostKeywordHighlightPopover } from './HostKeywordHighlightPopover';
export type { HostKeywordHighlightPopoverProps } from './HostKeywordHighlightPopover';
export { TerminalConnectionDialog } from './TerminalConnectionDialog';
export type { ChainProgress,TerminalConnectionDialogProps } from './TerminalConnectionDialog';
export { TerminalContextMenu } from './TerminalContextMenu';
export type { TerminalContextMenuProps } from './TerminalContextMenu';
export { TerminalSearchBar } from './TerminalSearchBar';
export type { TerminalSearchBarProps } from './TerminalSearchBar';
export { KeywordHighlighter } from './keywordHighlight';
export { useTerminalSearch } from './hooks/useTerminalSearch';
export { useTerminalContextActions } from './hooks/useTerminalContextActions';
export { useTerminalAuthState } from './hooks/useTerminalAuthState';

View File

@@ -2,6 +2,7 @@ import type { FitAddon } from "@xterm/addon-fit";
import type { SerializeAddon } from "@xterm/addon-serialize";
import type { Terminal as XTerm } from "@xterm/xterm";
import type { Dispatch, RefObject, SetStateAction } from "react";
import { shouldScrollOnTerminalOutput } from "../../../domain/terminalScroll";
import { logger } from "../../../lib/logger";
import type { Host, Identity, SerialConfig, SSHKey, TerminalSession, TerminalSettings } from "../../../types";
import {
@@ -68,8 +69,11 @@ export type TerminalSessionStartersContext = {
sessionId: string;
startupCommand?: string;
terminalSettings?: TerminalSettings;
terminalSettingsRef?: RefObject<TerminalSettings | undefined>;
terminalBackend: TerminalBackendApi;
serialConfig?: SerialConfig;
isVisibleRef?: RefObject<boolean>;
pendingOutputScrollRef?: RefObject<boolean>;
sessionRef: RefObject<string | null>;
hasConnectedRef: RefObject<boolean>;
@@ -117,6 +121,41 @@ const buildTermEnv = (host: Host, terminalSettings?: TerminalSettings) => {
return env;
};
const handleTerminalOutputAutoScroll = (
ctx: TerminalSessionStartersContext,
term: XTerm,
) => {
const settings = ctx.terminalSettingsRef?.current ?? ctx.terminalSettings;
if (!shouldScrollOnTerminalOutput(settings)) {
return;
}
if (ctx.isVisibleRef?.current === false) {
if (ctx.pendingOutputScrollRef) {
ctx.pendingOutputScrollRef.current = true;
}
return;
}
term.scrollToBottom();
};
const writeSessionData = (
ctx: TerminalSessionStartersContext,
term: XTerm,
data: string,
) => {
const settings = ctx.terminalSettingsRef?.current ?? ctx.terminalSettings;
if (!shouldScrollOnTerminalOutput(settings)) {
term.write(data);
return;
}
term.write(data, () => {
handleTerminalOutputAutoScroll(ctx, term);
});
};
const attachSessionToTerminal = (
ctx: TerminalSessionStartersContext,
term: XTerm,
@@ -139,7 +178,7 @@ const attachSessionToTerminal = (
// Replace \n that is not preceded by \r with \r\n
data = data.replace(/(?<!\r)\n/g, "\r\n");
}
term.write(data);
writeSessionData(ctx, term, data);
if (!ctx.hasConnectedRef.current) {
ctx.updateStatus("connected");
opts?.onConnected?.();
@@ -491,8 +530,11 @@ export const createTerminalSessionStarters = (ctx: TerminalSessionStartersContex
const commandToRun = ctx.startupCommand || ctx.host.startupCommand;
if (commandToRun && !ctx.hasRunStartupCommandRef.current) {
ctx.hasRunStartupCommandRef.current = true;
const scheduledSessionId = id;
setTimeout(() => {
if (!ctx.sessionRef.current) return;
// Guard against stale timers: if the session changed (e.g. user
// clicked Start Over quickly), skip to avoid double execution
if (!ctx.sessionRef.current || ctx.sessionRef.current !== scheduledSessionId) return;
ctx.terminalBackend.writeToSession(ctx.sessionRef.current, `${commandToRun}\r`);
if (ctx.onCommandExecuted) {
ctx.onCommandExecuted(commandToRun, ctx.host.id, ctx.host.label, ctx.sessionId);
@@ -611,8 +653,9 @@ export const createTerminalSessionStarters = (ctx: TerminalSessionStartersContex
const commandToRun = ctx.startupCommand || ctx.host.startupCommand;
if (commandToRun && !ctx.hasRunStartupCommandRef.current) {
ctx.hasRunStartupCommandRef.current = true;
const scheduledSessionId = id;
setTimeout(() => {
if (!ctx.sessionRef.current) return;
if (!ctx.sessionRef.current || ctx.sessionRef.current !== scheduledSessionId) return;
ctx.terminalBackend.writeToSession(ctx.sessionRef.current, `${commandToRun}\r`);
if (ctx.onCommandExecuted) {
ctx.onCommandExecuted(commandToRun, ctx.host.id, ctx.host.label, ctx.sessionId);
@@ -661,7 +704,7 @@ export const createTerminalSessionStarters = (ctx: TerminalSessionStartersContex
ctx.sessionRef.current = id;
ctx.disposeDataRef.current = ctx.terminalBackend.onSessionData(id, (chunk) => {
term.write(chunk);
writeSessionData(ctx, term, chunk);
if (!ctx.hasConnectedRef.current) {
ctx.updateStatus("connected");
setTimeout(() => {

View File

@@ -17,6 +17,11 @@ import {
type XTermPlatform,
resolveXTermPerformanceConfig,
} from "../../../infrastructure/config/xtermPerformance";
import {
shouldEnableNativeUserInputAutoScroll,
shouldScrollOnTerminalInput,
shouldScrollOnTerminalPaste,
} from "../../../domain/terminalScroll";
import { logger } from "../../../lib/logger";
import { isMacPlatform, normalizeLineEndings, wrapBracketedPaste } from "../../../lib/utils";
import { netcattyBridge } from "../../../infrastructure/services/netcattyBridge";
@@ -148,7 +153,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
const fontWeightBold = settings?.fontWeightBold ?? 700;
const lineHeight = 1 + (settings?.linePadding ?? 0) / 10;
const minimumContrastRatio = settings?.minimumContrastRatio ?? 1;
const scrollOnUserInput = settings?.scrollOnInput ?? true;
const scrollOnUserInput = shouldEnableNativeUserInputAutoScroll(settings);
const altIsMeta = settings?.altAsMeta ?? false;
const wordSeparator = settings?.wordSeparators ?? " ()[]{}'\"";
const keywordHighlightRules = settings?.keywordHighlightRules ?? [];
@@ -202,6 +207,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
drawBoldTextInBrightColors,
minimumContrastRatio,
scrollOnUserInput,
macOptionClickForcesSelection: true,
altClickMovesCursor: !altIsMeta,
wordSeparator,
theme: {
@@ -335,6 +341,24 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
const appLevelActions = getAppLevelActions();
const terminalActions = getTerminalPassthroughActions();
const scrollViewportToBottom = () => {
term.scrollToBottom();
if (typeof requestAnimationFrame === "function") {
requestAnimationFrame(() => {
term.scrollToBottom();
});
}
};
const scrollToBottomAfterPaste = () => {
if (shouldScrollOnTerminalPaste(ctx.terminalSettingsRef.current)) {
scrollViewportToBottom();
}
};
const scrollToBottomAfterInput = (data: string) => {
if (shouldScrollOnTerminalInput(ctx.terminalSettingsRef.current, data)) {
term.scrollToBottom();
}
};
term.attachCustomKeyEventHandler((e: KeyboardEvent) => {
if (e.type !== "keydown") {
@@ -421,6 +445,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
let data = normalizeLineEndings(text);
if (term.modes.bracketedPasteMode && !ctx.terminalSettingsRef.current?.disableBracketedPaste) data = wrapBracketedPaste(data);
ctx.terminalBackend.writeToSession(id, data);
scrollToBottomAfterPaste();
}
});
break;
@@ -456,6 +481,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
let data = normalizeLineEndings(text);
if (term.modes.bracketedPasteMode && !ctx.terminalSettingsRef.current?.disableBracketedPaste) data = wrapBracketedPaste(data);
ctx.terminalBackend.writeToSession(ctx.sessionRef.current, data);
scrollToBottomAfterPaste();
}
} catch (err) {
logger.warn("[Terminal] Failed to paste from clipboard:", err);
@@ -536,6 +562,8 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
ctx.onBroadcastInputRef.current(data, ctx.sessionId);
}
scrollToBottomAfterInput(data);
if (ctx.statusRef.current === "connected" && ctx.onCommandExecuted) {
if (data === "\r" || data === "\n") {
const cmd = ctx.commandBufferRef.current.trim();

View File

@@ -13,6 +13,7 @@ export const normalizeDistroId = (value?: string) => {
if (v.includes('amzn') || v.includes('amazon') || v.includes('aws')) return 'amazon';
if (v.includes('opensuse') || v.includes('suse') || v.includes('sles')) return 'opensuse';
if (v.includes('red hat') || v.includes('redhat') || v.includes('rhel')) return 'redhat';
if (v.includes('almalinux')) return 'almalinux';
if (v.includes('oracle')) return 'oracle';
if (v.includes('kali')) return 'kali';
return '';

View File

@@ -438,15 +438,79 @@ export interface TerminalSettings {
rendererType: 'auto' | 'webgl' | 'canvas'; // Terminal renderer: auto (detect based on hardware), webgl, or canvas
}
const STRICT_IPV4_OCTET_PATTERN = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)';
export const URL_HIGHLIGHT_PATTERN =
"(?:\\bhttps?:\\/\\/\\[[0-9A-Fa-f:.]+\\](?::\\d+)?(?:[/?#][^\\s<>\"'`]*)?(?<![.,;:!?\\)}])|\\b(?:https?:\\/\\/|www\\.)[^\\s<>\"'`]+(?<![.,;:!?\\])}]))";
export const IPV4_HIGHLIGHT_PATTERN =
`(?<![\\w.])(?<!\\bver\\s)(?<!\\bversion\\s)(?:${STRICT_IPV4_OCTET_PATTERN}\\.){3}${STRICT_IPV4_OCTET_PATTERN}(?![\\w.])`;
export const MAC_ADDRESS_HIGHLIGHT_PATTERN =
'\\b([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\\b';
export const DEFAULT_KEYWORD_HIGHLIGHT_RULES: KeywordHighlightRule[] = [
{ id: 'error', label: 'Error', patterns: ['\\[error\\]', '\\[err\\]', '\\berror\\b', '\\bfail(ed)?\\b', '\\bfatal\\b', '\\bcritical\\b', '\\bexception\\b'], color: '#F87171', enabled: true },
{ id: 'warning', label: 'Warning', patterns: ['\\[warn(ing)?\\]', '\\bwarn(ing)?\\b', '\\bcaution\\b', '\\bdeprecated\\b'], color: '#FBBF24', enabled: true },
{ id: 'ok', label: 'OK', patterns: ['\\[ok\\]', '\\bok\\b', '\\bsuccess(ful)?\\b', '\\bpassed\\b', '\\bcompleted\\b', '\\bdone\\b'], color: '#34D399', enabled: true },
{ id: 'info', label: 'Info', patterns: ['\\[info\\]', '\\[notice\\]', '\\[note\\]', '\\bnotice\\b', '\\bnote\\b'], color: '#3B82F6', enabled: true },
{ id: 'debug', label: 'Debug', patterns: ['\\[debug\\]', '\\[trace\\]', '\\[verbose\\]', '\\bdebug\\b', '\\btrace\\b', '\\bverbose\\b'], color: '#A78BFA', enabled: true },
{ id: 'ip-mac', label: 'IP address & MAC', patterns: ['\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b', '\\b([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\\b'], color: '#EC4899', enabled: true },
{ id: 'ip-mac', label: 'URL, IP & MAC', patterns: [URL_HIGHLIGHT_PATTERN, IPV4_HIGHLIGHT_PATTERN, MAC_ADDRESS_HIGHLIGHT_PATTERN], color: '#EC4899', enabled: true },
];
const cloneKeywordHighlightRule = (rule: KeywordHighlightRule): KeywordHighlightRule => ({
...rule,
patterns: [...rule.patterns],
});
export const normalizeKeywordHighlightRules = (
rules?: KeywordHighlightRule[],
): KeywordHighlightRule[] => {
if (!rules || rules.length === 0) {
return DEFAULT_KEYWORD_HIGHLIGHT_RULES.map(cloneKeywordHighlightRule);
}
const defaultRulesById = new Map(
DEFAULT_KEYWORD_HIGHLIGHT_RULES.map((rule) => [rule.id, rule] as const),
);
const normalizedRules = rules.map((rule) => {
const defaultRule = defaultRulesById.get(rule.id);
if (!defaultRule) {
return cloneKeywordHighlightRule(rule);
}
return {
...defaultRule,
color: rule.color,
enabled: rule.enabled,
};
});
const existingRuleIds = new Set(normalizedRules.map((rule) => rule.id));
for (const defaultRule of DEFAULT_KEYWORD_HIGHLIGHT_RULES) {
if (!existingRuleIds.has(defaultRule.id)) {
normalizedRules.push(cloneKeywordHighlightRule(defaultRule));
}
}
return normalizedRules;
};
export const normalizeTerminalSettings = (
settings?: Partial<TerminalSettings> | null,
): TerminalSettings => {
const mergedSettings = {
...DEFAULT_TERMINAL_SETTINGS,
...(settings ?? {}),
};
return {
...mergedSettings,
keywordHighlightRules: normalizeKeywordHighlightRules(
mergedSettings.keywordHighlightRules,
),
};
};
export const DEFAULT_TERMINAL_SETTINGS: TerminalSettings = {
scrollback: 10000,
drawBoldInBrightColors: true,

View File

@@ -111,6 +111,17 @@ export interface ProviderConnection {
error?: string;
}
export const hasProviderConnectionData = (
connection: Pick<ProviderConnection, 'tokens' | 'config'>,
): boolean => Boolean(connection.tokens || connection.config);
export const isProviderReadyForSync = (
connection: Pick<ProviderConnection, 'status' | 'tokens' | 'config'>,
): boolean =>
connection.status === 'connected'
|| connection.status === 'syncing'
|| (connection.status === 'error' && hasProviderConnectionData(connection));
// ============================================================================
// Encrypted Sync File Schema
// ============================================================================
@@ -150,7 +161,8 @@ export interface SyncPayload {
identities?: import('./models').Identity[];
snippets: import('./models').Snippet[];
customGroups: string[];
snippetPackages?: string[];
// Port forwarding rules
portForwardingRules?: import('./models').PortForwardingRule[];

108
domain/syncPayload.ts Normal file
View File

@@ -0,0 +1,108 @@
/**
* Sync Payload Builders — Single source of truth for constructing and applying
* the encrypted cloud-sync payload.
*
* Both the main window (App.tsx) and the settings window (SettingsSyncTab.tsx)
* must use these helpers to guarantee every field is included and no data is
* silently dropped.
*/
import type {
Host,
Identity,
KnownHost,
PortForwardingRule,
Snippet,
SSHKey,
} from './models';
import type { SyncPayload } from './sync';
// ---------------------------------------------------------------------------
// Input types
// ---------------------------------------------------------------------------
/** All vault-owned data that participates in cloud sync. */
export interface SyncableVaultData {
hosts: Host[];
keys: SSHKey[];
identities: Identity[];
snippets: Snippet[];
customGroups: string[];
snippetPackages?: string[];
knownHosts: KnownHost[];
}
/** Callbacks used by `applySyncPayload` to import data into local state. */
export interface SyncPayloadImporters {
/** Import vault data (hosts, keys, identities, snippets, customGroups, snippetPackages, knownHosts). */
importVaultData: (jsonString: string) => void;
/** Import port-forwarding rules (lives outside the vault hook). */
importPortForwardingRules?: (rules: PortForwardingRule[]) => void;
}
// ---------------------------------------------------------------------------
// Builders
// ---------------------------------------------------------------------------
/**
* Build a complete `SyncPayload` from local data.
*
* Port-forwarding rules are optional because they are managed by a separate
* state hook (`usePortForwardingState`). Callers should strip transient
* runtime fields (status, error, lastUsedAt) before passing them in.
*/
export function buildSyncPayload(
vault: SyncableVaultData,
portForwardingRules?: PortForwardingRule[],
): SyncPayload {
return {
hosts: vault.hosts,
keys: vault.keys,
identities: vault.identities,
snippets: vault.snippets,
customGroups: vault.customGroups,
snippetPackages: vault.snippetPackages,
knownHosts: vault.knownHosts,
portForwardingRules,
syncedAt: Date.now(),
};
}
/**
* Apply a downloaded `SyncPayload` to local state via the provided importers.
*
* This ensures both vault data and port-forwarding rules are imported
* consistently across windows.
*/
export function applySyncPayload(
payload: SyncPayload,
importers: SyncPayloadImporters,
): void {
// Build the vault import object. knownHosts is only included when the
// payload explicitly carries the field (even if it's []). Legacy cloud
// snapshots may omit it entirely — in that case we leave the local
// known-hosts list untouched rather than destructively wiping it.
const vaultImport: Record<string, unknown> = {
hosts: payload.hosts,
keys: payload.keys,
identities: payload.identities,
snippets: payload.snippets,
customGroups: payload.customGroups,
};
if (payload.snippetPackages !== undefined) {
vaultImport.snippetPackages = payload.snippetPackages;
}
if (payload.knownHosts !== undefined) {
vaultImport.knownHosts = payload.knownHosts;
}
importers.importVaultData(JSON.stringify(vaultImport));
// Only import port-forwarding rules when the payload explicitly carries
// them. Absent field = "payload was created before this feature existed",
// so local rules are preserved. Explicitly present [] = "remote has no
// rules, clear local state".
if (payload.portForwardingRules !== undefined && importers.importPortForwardingRules) {
importers.importPortForwardingRules(payload.portForwardingRules);
}
}

44
domain/terminalScroll.ts Normal file
View File

@@ -0,0 +1,44 @@
import type { TerminalSettings } from "./models";
const hasPrintableTerminalInput = (data: string): boolean => {
if (data.includes("\x1b")) {
return false;
}
for (const char of data) {
const codePoint = char.codePointAt(0);
if (codePoint === undefined) {
continue;
}
if (codePoint >= 0x20 && codePoint !== 0x7f && codePoint !== 0x1b) {
return true;
}
}
return false;
};
export const shouldEnableNativeUserInputAutoScroll = (
settings?: Partial<TerminalSettings> | null,
): boolean => settings?.scrollOnInput ?? true;
export const shouldScrollOnTerminalInput = (
settings: Partial<TerminalSettings> | null | undefined,
data: string,
): boolean => {
const scrollOnInput = settings?.scrollOnInput ?? true;
const scrollOnKeyPress = settings?.scrollOnKeyPress ?? false;
if (!scrollOnInput && !scrollOnKeyPress) {
return false;
}
return hasPrintableTerminalInput(data) ? scrollOnInput : scrollOnKeyPress;
};
export const shouldScrollOnTerminalOutput = (
settings?: Partial<TerminalSettings> | null,
): boolean => settings?.scrollOnOutput ?? false;
export const shouldScrollOnTerminalPaste = (
settings?: Partial<TerminalSettings> | null,
): boolean => settings?.scrollOnPaste ?? true;

View File

@@ -90,5 +90,13 @@ module.exports = {
}
],
category: 'Development'
}
},
publish: [
{
provider: 'github',
owner: 'binaricat',
repo: 'Netcatty',
releaseType: 'release'
}
]
};

View File

@@ -0,0 +1,311 @@
/**
* Auto-Update Bridge
*
* Wraps electron-updater to provide IPC-driven update checks, downloads, and
* install-on-quit. Designed around a "prompt" model: the renderer asks to
* check, then explicitly triggers download and install.
*
* Platforms where auto-update is NOT supported (Linux deb/rpm/snap) get a
* graceful { available: false, error } response so the renderer can fall back
* to a manual "open GitHub releases" link.
*/
let _deps = null;
/**
* Returns true when the current packaging format supports electron-updater
* (macOS zip/dmg, Windows NSIS, Linux AppImage).
*/
function isAutoUpdateSupported() {
if (process.platform === "darwin" || process.platform === "win32") {
return true;
}
// Linux: only AppImage supports in-place update.
// The APPIMAGE env variable is set by the AppImage runtime.
if (process.platform === "linux" && process.env.APPIMAGE) {
return true;
}
return false;
}
/** Lazily resolved autoUpdater — avoids importing electron-updater in
* contexts where native modules might not be available. */
let _autoUpdater = null;
/** Guard against duplicate listener registration */
let _listenersRegistered = false;
/** Track whether a download is in progress to distinguish download errors from check errors */
let _isDownloading = false;
/** Track whether a checkForUpdates call is in flight (set before call, cleared on result event) */
let _isChecking = false;
/**
* Snapshot of the last known update status so newly opened windows can hydrate
* without waiting for the next IPC event.
* @type {{ status: 'idle' | 'downloading' | 'ready' | 'error', percent: number, error: string | null, version: string | null, isChecking: boolean }}
*/
let _lastStatus = { status: 'idle', percent: 0, error: null, version: null, isChecking: false };
function getAutoUpdater() {
if (_autoUpdater) return _autoUpdater;
try {
const { autoUpdater } = require("electron-updater");
autoUpdater.autoDownload = true;
autoUpdater.autoInstallOnAppQuit = false;
// Silence the default electron-log transport (we log ourselves).
autoUpdater.logger = null;
_autoUpdater = autoUpdater;
return autoUpdater;
} catch (err) {
console.error("[AutoUpdate] Failed to load electron-updater:", err?.message || err);
return null;
}
}
/**
* Register persistent global IPC event listeners for auto-download flow.
* Called once in init(). Forwards electron-updater events to the renderer
* even when no manual download was initiated.
*/
function setupGlobalListeners() {
if (_listenersRegistered) return;
const updater = getAutoUpdater();
if (!updater) return;
_listenersRegistered = true;
updater.on("update-not-available", () => {
_isChecking = false;
// Reset stale status so late-opening windows don't hydrate from a
// previous 'error' or 'ready' snapshot after a "no update" check.
_lastStatus = { status: 'idle', percent: 0, error: null, version: null, isChecking: false };
broadcastToAllWindows("netcatty:update:update-not-available", {});
});
updater.on("update-available", (info) => {
_isChecking = false;
// autoDownload=true means the download begins immediately after this event
_isDownloading = true;
_lastStatus = { status: 'downloading', percent: 0, error: null, version: info.version || null, isChecking: false };
broadcastToAllWindows("netcatty:update:update-available", {
version: info.version || "",
releaseNotes: typeof info.releaseNotes === "string" ? info.releaseNotes : "",
releaseDate: info.releaseDate || null,
});
});
updater.on("download-progress", (info) => {
_lastStatus.percent = Math.round(info.percent ?? 0);
broadcastToAllWindows("netcatty:update:download-progress", {
percent: info.percent ?? 0,
bytesPerSecond: info.bytesPerSecond ?? 0,
transferred: info.transferred ?? 0,
total: info.total ?? 0,
});
});
updater.on("update-downloaded", () => {
_isDownloading = false;
_lastStatus = { ..._lastStatus, status: 'ready', percent: 100 };
broadcastToAllWindows("netcatty:update:downloaded");
});
updater.on("error", (err) => {
_isChecking = false;
// Only broadcast download-phase errors; check-phase errors (e.g. network failures
// during checkForUpdates) are not download failures and must not set autoDownloadStatus.
if (!_isDownloading) {
_lastStatus = { ..._lastStatus, isChecking: false };
console.warn("[AutoUpdate] Check-phase error (not broadcast to renderer):", err?.message || err);
return;
}
_isDownloading = false;
const errorMsg = err?.message || "Unknown update error";
_lastStatus = { ..._lastStatus, status: 'error', error: errorMsg };
broadcastToAllWindows("netcatty:update:error", {
error: errorMsg,
});
});
console.log("[AutoUpdate] Global listeners registered");
}
/**
* Trigger an automatic update check after a delay.
* No-op on platforms that don't support auto-update (Linux deb/rpm/snap).
* Called from main process after the main window is created.
*
* @param {number} delayMs - Milliseconds to wait before checking (default: 5000)
*/
let _autoCheckTimer = null;
function startAutoCheck(delayMs = 5000) {
if (!isAutoUpdateSupported()) {
console.log("[AutoUpdate] Platform does not support auto-update, skipping auto-check");
return;
}
_autoCheckTimer = setTimeout(async () => {
_autoCheckTimer = null;
const updater = getAutoUpdater();
if (!updater) {
console.warn("[AutoUpdate] Auto-check skipped — updater not available");
return;
}
_isChecking = true;
_lastStatus = { ..._lastStatus, isChecking: true };
try {
console.log("[AutoUpdate] Starting automatic update check...");
await updater.checkForUpdates();
} catch (err) {
_isChecking = false;
_lastStatus = { ..._lastStatus, isChecking: false };
console.warn("[AutoUpdate] Auto-check failed:", err?.message || err);
}
}, delayMs);
}
/**
* Cancel a pending startAutoCheck timer. Called when the renderer triggers
* a manual check to avoid racing with the queued auto-check.
*/
function cancelAutoCheck() {
if (_autoCheckTimer) {
clearTimeout(_autoCheckTimer);
_autoCheckTimer = null;
}
}
function init(deps) {
_deps = deps;
setupGlobalListeners();
}
/**
* Broadcast an IPC event to all non-destroyed BrowserWindows.
* Ensures both the main window and settings window always receive
* auto-update events.
* @param {string} channel
* @param {unknown} [payload]
*/
function broadcastToAllWindows(channel, payload) {
try {
const { BrowserWindow } = _deps?.electronModule || {};
if (!BrowserWindow) return;
const windows = BrowserWindow.getAllWindows();
for (const win of windows) {
if (!win.isDestroyed()) {
if (payload !== undefined) {
win.webContents.send(channel, payload);
} else {
win.webContents.send(channel);
}
}
}
} catch (err) {
console.warn("[AutoUpdate] broadcastToAllWindows failed:", err?.message || err);
}
}
function registerHandlers(ipcMain) {
// ---- Check for updates ------------------------------------------------
ipcMain.handle("netcatty:update:check", async () => {
// Cancel any pending auto-check to prevent concurrent checkForUpdates()
// calls — electron-updater rejects them and surfaces false errors.
cancelAutoCheck();
if (!isAutoUpdateSupported()) {
return {
available: false,
supported: false,
error: "Auto-update is not supported on this platform/package format.",
};
}
const updater = getAutoUpdater();
if (!updater) {
return {
available: false,
supported: false,
error: "Update module failed to load.",
};
}
// If a check is already in flight (e.g. from startAutoCheck), don't
// start a concurrent one — electron-updater rejects it and surfaces a
// confusing error. Return a sentinel so the renderer knows to wait.
if (_isChecking) {
return { available: false, supported: true, checking: true };
}
try {
_isChecking = true;
_lastStatus = { ..._lastStatus, isChecking: true };
const result = await updater.checkForUpdates();
if (!result || !result.updateInfo) {
return { available: false, supported: true };
}
const { version, releaseNotes, releaseDate } = result.updateInfo;
// Compare with current version using semver ordering.
// Only report an update when the feed version is strictly newer,
// avoiding false positives for pre-release or nightly builds.
const { app } = _deps?.electronModule || {};
const currentVersion = app?.getVersion?.() || "0.0.0";
const isNewer = currentVersion.localeCompare(version, undefined, { numeric: true, sensitivity: 'base' }) < 0;
if (!isNewer) {
return { available: false, supported: true };
}
return {
available: true,
supported: true,
version,
releaseNotes: typeof releaseNotes === "string" ? releaseNotes : "",
releaseDate: releaseDate || null,
};
} catch (err) {
_isChecking = false;
_lastStatus = { ..._lastStatus, isChecking: false };
console.warn("[AutoUpdate] Check failed:", err?.message || err);
return {
available: false,
supported: true,
error: err?.message || "Unknown update check error",
};
}
});
// ---- Download update ---------------------------------------------------
ipcMain.handle("netcatty:update:download", async () => {
const updater = getAutoUpdater();
if (!updater) {
return { success: false, error: "Update module not available." };
}
try {
// Global listeners (registered in setupGlobalListeners) handle all
// progress/downloaded/error events. Just trigger the download.
await updater.downloadUpdate();
return { success: true };
} catch (err) {
console.error("[AutoUpdate] Download failed:", err?.message || err);
return { success: false, error: err?.message || "Download failed" };
}
});
// ---- Get current update status (for late-opening windows) ---------------
ipcMain.handle("netcatty:update:getStatus", () => {
return { ..._lastStatus };
});
// ---- Install (quit & install) ------------------------------------------
ipcMain.handle("netcatty:update:install", () => {
const updater = getAutoUpdater();
if (!updater) return;
updater.quitAndInstall(false, true);
});
console.log("[AutoUpdate] Handlers registered");
}
module.exports = { init, registerHandlers, isAutoUpdateSupported, startAutoCheck };

View File

@@ -100,6 +100,9 @@ async function startPortForward(event, payload) {
}));
return new Promise((resolve, reject) => {
// Track whether the Promise has been settled so conn.on('close')
// can reject if the tunnel was killed during SSH handshake.
let settled = false;
conn.on('ready', () => {
console.log(`[PortForward] SSH connection ready for tunnel ${tunnelId}`);
@@ -131,6 +134,7 @@ async function startPortForward(event, payload) {
sendStatus('error', err.message);
conn.end();
portForwardingTunnels.delete(tunnelId);
settled = true;
reject(err);
});
@@ -140,9 +144,11 @@ async function startPortForward(event, payload) {
type: 'local',
conn,
server,
status: 'active',
webContentsId: sender.id
});
sendStatus('active');
settled = true;
resolve({ tunnelId, success: true });
});
@@ -153,6 +159,7 @@ async function startPortForward(event, payload) {
console.error(`[PortForward] Remote forward error:`, err.message);
sendStatus('error', err.message);
conn.end();
settled = true;
reject(err);
return;
}
@@ -161,9 +168,11 @@ async function startPortForward(event, payload) {
portForwardingTunnels.set(tunnelId, {
type: 'remote',
conn,
status: 'active',
webContentsId: sender.id
});
sendStatus('active');
settled = true;
resolve({ tunnelId, success: true });
});
@@ -265,6 +274,7 @@ async function startPortForward(event, payload) {
sendStatus('error', err.message);
conn.end();
portForwardingTunnels.delete(tunnelId);
settled = true;
reject(err);
});
@@ -274,12 +284,15 @@ async function startPortForward(event, payload) {
type: 'dynamic',
conn,
server,
status: 'active',
webContentsId: sender.id
});
sendStatus('active');
settled = true;
resolve({ tunnelId, success: true });
});
} else {
settled = true;
reject(new Error(`Unknown forwarding type: ${type}`));
}
});
@@ -288,12 +301,15 @@ async function startPortForward(event, payload) {
console.error(`[PortForward] SSH error:`, err.message);
sendStatus('error', err.message);
portForwardingTunnels.delete(tunnelId);
settled = true;
reject(err);
});
conn.on('close', () => {
console.log(`[PortForward] SSH connection closed for tunnel ${tunnelId}`);
const tunnel = portForwardingTunnels.get(tunnelId);
// Capture the cancelled flag BEFORE cleanup deletes the entry.
const wasCancelled = !!tunnel?.cancelled;
if (tunnel) {
if (tunnel.server) {
try { tunnel.server.close(); } catch { }
@@ -301,9 +317,30 @@ async function startPortForward(event, payload) {
sendStatus('inactive');
portForwardingTunnels.delete(tunnelId);
}
// If the Promise was never settled (tunnel killed during
// handshake by stopPortForwardByRuleId), settle it.
if (!settled) {
settled = true;
if (wasCancelled) {
resolve({ tunnelId, success: false, cancelled: true });
} else {
reject(new Error(`Tunnel ${tunnelId} closed before connection established`));
}
}
});
sendStatus('connecting');
// Register the connection BEFORE the handshake starts so that
// stopPortForwardByRuleId can find and kill it at any point,
// including during the SSH handshake window. The conn.on('ready')
// handler updates the entry to include the server object later.
portForwardingTunnels.set(tunnelId, {
type,
conn,
server: null,
status: 'connecting',
webContentsId: sender.id,
});
conn.connect(connectOpts);
});
}
@@ -320,13 +357,17 @@ async function stopPortForward(event, payload) {
}
try {
// Mark as cancelled so conn.on('close') resolves gracefully
// instead of rejecting for in-flight handshakes.
tunnel.cancelled = true;
if (tunnel.server) {
tunnel.server.close();
}
if (tunnel.conn) {
tunnel.conn.end();
}
portForwardingTunnels.delete(tunnelId);
// Don't delete here — let conn.on('close') handle cleanup
// so it can read the cancelled flag.
return { tunnelId, success: true };
} catch (err) {
@@ -345,7 +386,7 @@ async function getPortForwardStatus(event, payload) {
return { tunnelId, status: 'inactive' };
}
return { tunnelId, status: 'active', type: tunnel.type };
return { tunnelId, status: tunnel.status || 'active', type: tunnel.type };
}
/**
@@ -357,7 +398,7 @@ async function listPortForwards() {
list.push({
tunnelId,
type: tunnel.type,
status: 'active',
status: tunnel.status || 'active',
});
}
return list;
@@ -370,21 +411,54 @@ function stopAllPortForwards() {
console.log(`[PortForward] Stopping all ${portForwardingTunnels.size} active tunnels...`);
for (const [tunnelId, tunnel] of portForwardingTunnels) {
try {
// Mark as cancelled so conn.on('close') resolves gracefully
// instead of rejecting with an error for in-flight handshakes.
tunnel.cancelled = true;
if (tunnel.server) {
tunnel.server.close();
}
if (tunnel.conn) {
tunnel.conn.end();
}
// Don't delete here — let conn.on('close') handle cleanup
// so it can read the cancelled flag.
console.log(`[PortForward] Stopped tunnel ${tunnelId}`);
} catch (err) {
console.warn(`[PortForward] Failed to stop tunnel ${tunnelId}:`, err.message);
}
}
portForwardingTunnels.clear();
console.log('[PortForward] All tunnels stopped');
}
/**
* Stop all active port forwards for a given rule ID.
* Tunnel IDs follow the format `pf-{ruleId}-{timestamp}`, so we match
* by checking if the tunnelId contains the ruleId.
* This catches tunnels in ANY state (connecting, active) because it
* operates on the main-process portForwardingTunnels map directly.
*/
function stopPortForwardByRuleId(_event, { ruleId }) {
let stopped = 0;
for (const [tunnelId, tunnel] of portForwardingTunnels) {
if (tunnelId.includes(ruleId)) {
try {
// Mark as intentionally cancelled BEFORE conn.end() so the
// close handler resolves gracefully instead of rejecting.
tunnel.cancelled = true;
if (tunnel.server) tunnel.server.close();
if (tunnel.conn) tunnel.conn.end();
// Don't delete here — let the conn.on('close') handler delete
// the entry so it can read tunnel.cancelled first.
console.log(`[PortForward] Stopped tunnel ${tunnelId} for rule ${ruleId}`);
stopped++;
} catch (err) {
console.warn(`[PortForward] Failed to stop tunnel ${tunnelId}:`, err.message);
}
}
}
return { stopped };
}
/**
* Register IPC handlers for port forwarding operations
*/
@@ -393,6 +467,8 @@ function registerHandlers(ipcMain) {
ipcMain.handle("netcatty:portforward:stop", stopPortForward);
ipcMain.handle("netcatty:portforward:status", getPortForwardStatus);
ipcMain.handle("netcatty:portforward:list", listPortForwards);
ipcMain.handle("netcatty:portforward:stopAll", () => stopAllPortForwards());
ipcMain.handle("netcatty:portforward:stopByRuleId", stopPortForwardByRuleId);
}
module.exports = {
@@ -402,4 +478,5 @@ module.exports = {
getPortForwardStatus,
listPortForwards,
stopAllPortForwards,
stopPortForwardByRuleId,
};

View File

@@ -29,6 +29,7 @@ const {
applyAuthToConnOpts,
safeSend: authSafeSend,
findAllDefaultPrivateKeys: findAllDefaultPrivateKeysFromHelper,
getAvailableAgentSocket,
} = require("./sshAuthHelper.cjs");
// SFTP clients storage - shared reference passed from main
@@ -427,7 +428,7 @@ function init(deps) {
/**
* Connect through a chain of jump hosts for SFTP
*/
async function connectThroughChainForSftp(event, options, jumpHosts, targetHost, targetPort, connId) {
async function connectThroughChainForSftp(event, options, jumpHosts, targetHost, targetPort, connId, agentSocket) {
const sender = event.sender;
const connections = [];
let currentSocket = null;
@@ -498,6 +499,7 @@ async function connectThroughChainForSftp(event, options, jumpHosts, targetHost,
logPrefix: `[SFTP Chain] Hop ${i + 1}`,
unlockedEncryptedKeys: options._unlockedEncryptedKeys || [],
defaultKeys,
sshAgentSocketOverride: agentSocket,
});
applyAuthToConnOpts(connOpts, authConfig);
@@ -521,6 +523,11 @@ async function connectThroughChainForSftp(event, options, jumpHosts, targetHost,
resolve();
});
conn.on('error', (err) => {
// Filter out non-fatal agent auth errors (same as in openSftp)
if (err.level === 'agent') {
console.log(`[SFTP Chain] Hop ${i + 1} non-fatal agent auth error (will try next method):`, err.message);
return;
}
console.error(`[SFTP Chain] Hop ${i + 1}/${jumpHosts.length}: ${hopLabel} error:`, err.message);
reject(err);
});
@@ -828,6 +835,10 @@ async function openSftp(event, options) {
let chainConnections = [];
let connectionSocket = null;
// Pre-fetch agent socket (async check for Windows SSH Agent service)
// This is used by both jump host chain auth and final host auth
const agentSocket = await getAvailableAgentSocket();
// Handle chain/proxy connections
if (hasJumpHosts) {
console.log(`[SFTP] Opening connection through ${jumpHosts.length} jump host(s) to ${options.hostname}:${options.port || 22}`);
@@ -841,7 +852,8 @@ async function openSftp(event, options) {
jumpHosts,
options.hostname,
options.port || 22,
connId
connId,
agentSocket
);
connectionSocket = chainResult.socket;
chainConnections = chainResult.connections;
@@ -895,6 +907,7 @@ async function openSftp(event, options) {
if (options.password) connectOpts.password = options.password;
// Build auth handler using shared helper
// Use pre-fetched agentSocket (validated async, including Windows service check)
const authConfig = buildAuthHandler({
privateKey: connectOpts.privateKey,
password: connectOpts.password,
@@ -903,6 +916,7 @@ async function openSftp(event, options) {
username: connectOpts.username,
logPrefix: "[SFTP]",
defaultKeys,
sshAgentSocketOverride: agentSocket,
});
applyAuthToConnOpts(connectOpts, authConfig);
@@ -922,44 +936,104 @@ async function openSftp(event, options) {
connectOpts.readyTimeout = 120000; // 2 minutes for 2FA input
try {
if (options.sudo) {
console.log(`[SFTP] Using sudo mode for connection: ${connId}`);
const sshClient = client.client;
// IMPORTANT: We bypass ssh2-sftp-client's connect() method and use the
// underlying ssh2 Client directly. This is because ssh2-sftp-client adds
// temporary error listeners that reject the entire connect promise on ANY
// error, including non-fatal auth errors (e.g. 'Failed to connect to agent'
// when ssh2 tries agent auth and falls through to the next method).
// By connecting directly, we can filter these non-fatal errors and allow
// the auth flow to continue to keyboard-interactive/password/etc.
const sshClient = client.client;
await new Promise((resolve, reject) => {
// Set up error handler for initial connection
const onConnectError = (err) => reject(err);
sshClient.once('error', onConnectError);
await new Promise((resolve, reject) => {
let settled = false;
const settle = (fn, val) => {
if (settled) return;
settled = true;
cleanup();
fn(val);
};
sshClient.once('ready', async () => {
sshClient.removeListener('error', onConnectError);
try {
// Use provided password or try empty if using key auth (and hope for nopasswd sudo)
const sudoPass = options.password || "";
const sftpWrapper = await connectSudoSftp(sshClient, sudoPass);
const onError = (err) => {
// Filter out non-fatal authentication errors.
// ssh2 sets err.level = 'agent' when agent auth fails — it then
// internally calls tryNextAuth() to proceed with the next method.
// We must NOT reject here, or the fallback won't execute.
if (err.level === 'agent') {
console.log('[SFTP] Non-fatal agent auth error (will try next method):', err.message);
return;
}
settle(reject, err);
};
// Inject into sftp-client
client.sftp = sftpWrapper;
const onEnd = () => {
settle(reject, new Error('Connection closed before SFTP session was ready'));
};
// Important: attach cleanup listener expected by sftp-client
client.sftp.on('close', () => client.end());
const onClose = () => {
settle(reject, new Error('Connection closed before SFTP session was ready'));
};
const cleanup = () => {
sshClient.removeListener('error', onError);
sshClient.removeListener('end', onEnd);
sshClient.removeListener('close', onClose);
};
sshClient.on('error', onError);
sshClient.on('end', onEnd);
sshClient.on('close', onClose);
sshClient.once('ready', () => {
cleanup();
if (options.sudo) {
console.log(`[SFTP] Using sudo mode for connection: ${connId}`);
(async () => {
try {
const sudoPass = options.password || "";
const sftpWrapper = await connectSudoSftp(sshClient, sudoPass);
client.sftp = sftpWrapper;
client.sftp.on('close', () => client.end());
resolve();
} catch (e) {
// Fallback: if sftp-server binary is missing (exit code 127),
// try standard SFTP subsystem instead of failing completely.
// This handles systems like ESXi that don't have sftp-server
// but support the SFTP subsystem natively.
if (e.message && e.message.includes('exit code 127')) {
console.warn('[SFTP] sftp-server not found, falling back to standard SFTP subsystem');
options.sudo = false; // Mark as non-sudo for downstream logic
sshClient.sftp((sftpErr, sftp) => {
if (sftpErr) {
sshClient.end();
return reject(sftpErr);
}
client.sftp = sftp;
resolve();
});
} else {
sshClient.end();
reject(e);
}
}
})();
} else {
// Open standard SFTP subsystem channel
sshClient.sftp((err, sftp) => {
if (err) return reject(err);
client.sftp = sftp;
resolve();
} catch (e) {
sshClient.end();
reject(e);
}
});
try {
sshClient.connect(connectOpts);
} catch (e) {
reject(e);
});
}
});
} else {
await client.connect(connectOpts);
}
try {
sshClient.connect(connectOpts);
} catch (e) {
settle(reject, e);
}
});
// Increase max listeners AFTER connect, when the internal ssh2 Client exists
// This prevents Node.js MaxListenersExceededWarning when performing many operations
// ssh2-sftp-client adds temporary listeners for each operation, so we need a high limit

View File

@@ -6,6 +6,7 @@
const fs = require("node:fs");
const path = require("node:path");
const os = require("node:os");
const { exec } = require("node:child_process");
const keyboardInteractiveHandler = require("./keyboardInteractiveHandler.cjs");
const passphraseHandler = require("./passphraseHandler.cjs");
@@ -123,14 +124,58 @@ async function findAllDefaultPrivateKeys(options = {}) {
}
/**
* Get ssh-agent socket path based on platform
* Check if Windows SSH Agent service is running
* @returns {Promise<boolean>}
*/
function checkWindowsSshAgentRunning() {
return new Promise((resolve) => {
if (process.platform !== "win32") {
resolve(true);
return;
}
exec("sc query ssh-agent", (err, stdout) => {
if (err) {
resolve(false);
return;
}
resolve(stdout.includes("RUNNING"));
});
});
}
/**
* Get ssh-agent socket path based on platform (synchronous, best-effort)
* @returns {string|null}
*/
function getSshAgentSocket() {
if (process.platform === "win32") {
// On Windows, always return the pipe path; the caller should use
// getAvailableAgentSocket() for a reliable async check.
return "\\\\.\\pipe\\openssh-ssh-agent";
}
return process.env.SSH_AUTH_SOCK || null;
const agentSocket = process.env.SSH_AUTH_SOCK;
if (!agentSocket) return null;
try {
const stats = fs.statSync(agentSocket);
return typeof stats.isSocket === "function" && stats.isSocket()
? agentSocket
: null;
} catch {
return null;
}
}
/**
* Get ssh-agent socket path with async validation (checks Windows service status)
* @returns {Promise<string|null>}
*/
async function getAvailableAgentSocket() {
if (process.platform === "win32") {
const running = await checkWindowsSshAgentRunning();
return running ? "\\\\.\\pipe\\openssh-ssh-agent" : null;
}
return getSshAgentSocket();
}
/**
@@ -146,7 +191,7 @@ function getSshAgentSocket() {
* @param {Array} [options.unlockedEncryptedKeys] - Array of unlocked encrypted keys with passphrases
*/
function buildAuthHandler(options) {
const { privateKey, password, passphrase, agent, username, logPrefix = "[SSH]", unlockedEncryptedKeys = [], defaultKeys = [] } = options;
const { privateKey, password, passphrase, agent, username, logPrefix = "[SSH]", unlockedEncryptedKeys = [], defaultKeys = [], sshAgentSocketOverride } = options;
// Determine what type of explicit auth the user configured
const hasExplicitKey = !!privateKey;
@@ -158,7 +203,10 @@ function buildAuthHandler(options) {
const isPasswordOnly = hasExplicitPassword && !hasExplicitKey && !hasExplicitAgent;
const isKeyOnly = hasExplicitKey && !hasExplicitAgent;
const sshAgentSocket = getSshAgentSocket();
// Allow callers to pass in a pre-validated agent socket (e.g. from async
// getAvailableAgentSocket). Fall back to synchronous getSshAgentSocket()
// which on Windows always returns the pipe path without checking the service.
const sshAgentSocket = sshAgentSocketOverride !== undefined ? sshAgentSocketOverride : getSshAgentSocket();
// Only use system ssh-agent BEFORE user's auth when:
// - User explicitly configured agent, OR
@@ -512,6 +560,7 @@ module.exports = {
findDefaultPrivateKey,
findAllDefaultPrivateKeys,
getSshAgentSocket,
getAvailableAgentSocket,
buildAuthHandler,
createKeyboardInteractiveHandler,
applyAuthToConnOpts,

View File

@@ -20,6 +20,7 @@ const {
safeSend: authSafeSend,
requestPassphrasesForEncryptedKeys,
findAllDefaultPrivateKeys: findAllDefaultPrivateKeysFromHelper,
getSshAgentSocket,
} = require("./sshAuthHelper.cjs");
// Default SSH key names in priority order
@@ -165,6 +166,16 @@ function checkWindowsSshAgent() {
});
}
async function getAvailableAgentSocket() {
if (process.platform === "win32") {
const agentStatus = await checkWindowsSshAgent();
log("Windows SSH Agent check", agentStatus);
return agentStatus.running ? "\\\\.\\pipe\\openssh-ssh-agent" : null;
}
return getSshAgentSocket();
}
const DEBUG_SSH = process.env.NETCATTY_SSH_DEBUG === "1";
// Debug logger (disabled by default)
@@ -592,14 +603,7 @@ async function startSSHSession(event, options) {
// If no primary auth method configured, try ssh-agent first, then ALL default keys
if (!connectOpts.privateKey && !connectOpts.password && !connectOpts.agent) {
// First, try to use ssh-agent if available (this is what regular SSH does)
let sshAgentSocket;
if (process.platform === "win32") {
const agentStatus = await checkWindowsSshAgent();
log("Windows SSH Agent check", agentStatus);
sshAgentSocket = agentStatus.running ? "\\\\.\\pipe\\openssh-ssh-agent" : null;
} else {
sshAgentSocket = process.env.SSH_AUTH_SOCK;
}
const sshAgentSocket = await getAvailableAgentSocket();
if (sshAgentSocket) {
log("No auth method configured, trying ssh-agent first", { agentSocket: sshAgentSocket });
@@ -627,15 +631,7 @@ async function startSSHSession(event, options) {
// Agent forwarding
if (options.agentForwarding) {
if (!connectOpts.agent) {
if (process.platform === "win32") {
const agentStatus = await checkWindowsSshAgent();
log("Windows SSH Agent check (agentForwarding)", agentStatus);
if (agentStatus.running) {
connectOpts.agent = "\\\\.\\pipe\\openssh-ssh-agent";
}
} else {
connectOpts.agent = process.env.SSH_AUTH_SOCK;
}
connectOpts.agent = await getAvailableAgentSocket();
}
// Only enable forwarding when an agent is actually available
if (connectOpts.agent) {

View File

@@ -1094,7 +1094,10 @@ function registerWindowHandlers(ipcMain, nativeTheme) {
ipcMain.handle("netcatty:setTheme", (_event, theme) => {
currentTheme = theme;
nativeTheme.themeSource = theme;
const themeConfig = THEME_COLORS[theme] || THEME_COLORS.light;
const effectiveTheme = theme === "system"
? (nativeTheme?.shouldUseDarkColors ? "dark" : "light")
: theme;
const themeConfig = THEME_COLORS[effectiveTheme] || THEME_COLORS.light;
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.setBackgroundColor(themeConfig.background);
}

View File

@@ -82,6 +82,7 @@ const sessionLogsBridge = require("./bridges/sessionLogsBridge.cjs");
const compressUploadBridge = require("./bridges/compressUploadBridge.cjs");
const globalShortcutBridge = require("./bridges/globalShortcutBridge.cjs");
const credentialBridge = require("./bridges/credentialBridge.cjs");
const autoUpdateBridge = require("./bridges/autoUpdateBridge.cjs");
const windowManager = require("./bridges/windowManager.cjs");
// GPU settings
@@ -405,6 +406,8 @@ const registerBridges = (win) => {
compressUploadBridge.registerHandlers(ipcMain);
globalShortcutBridge.registerHandlers(ipcMain);
credentialBridge.registerHandlers(ipcMain, electronModule);
autoUpdateBridge.init(deps);
autoUpdateBridge.registerHandlers(ipcMain);
// Settings window handler
ipcMain.handle("netcatty:settings:open", async () => {
@@ -791,7 +794,11 @@ if (!gotLock) {
});
// Create the main window
void createWindow().catch((err) => {
void createWindow().then(() => {
// Trigger auto-update check 5 s after window creation.
// startAutoCheck() is a no-op on unsupported platforms (Linux deb/rpm/snap).
autoUpdateBridge.startAutoCheck(5000);
}).catch((err) => {
console.error("[Main] Failed to create main window:", err);
showStartupError(err);
try {

View File

@@ -14,6 +14,11 @@ 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);
@@ -131,6 +136,57 @@ ipcRenderer.on("netcatty:passphrase-timeout", (_event, payload) => {
});
});
// 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);
@@ -656,6 +712,12 @@ const api = {
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());
@@ -878,6 +940,32 @@ const api = {
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"),
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);
},
};
// Merge with existing netcatty (if any) to avoid stale objects on hot reload

View File

@@ -7,7 +7,7 @@ import reactHooks from "eslint-plugin-react-hooks";
export default [
js.configs.recommended,
{
ignores: ["node_modules/**", "dist/**", "electron/**", "scripts/**", "public/monaco/**", ".github/**"],
ignores: ["node_modules/**", "dist/**", "electron/**", "scripts/**", "public/monaco/**", ".github/**", ".claude/**"],
},
{
files: ["**/*.{ts,tsx}"],

32
global.d.ts vendored
View File

@@ -375,7 +375,7 @@ declare global {
getHomeDir?(): Promise<string>;
getSystemInfo?(): Promise<{ username: string; hostname: string }>;
setTheme?(theme: 'light' | 'dark'): Promise<boolean>;
setTheme?(theme: 'light' | 'dark' | 'system'): Promise<boolean>;
setBackgroundColor?(color: string): Promise<boolean>;
setLanguage?(language: string): Promise<boolean>;
// Window controls for custom title bar (Windows/Linux)
@@ -429,6 +429,8 @@ declare global {
stopPortForward?(tunnelId: string): Promise<PortForwardResult>;
getPortForwardStatus?(tunnelId: string): Promise<PortForwardStatusResult>;
listPortForwards?(): Promise<{ tunnelId: string; type: string; status: string }[]>;
stopAllPortForwards?(): Promise<void>;
stopPortForwardByRuleId?(ruleId: string): Promise<{ stopped: number }>;
onPortForwardStatus?(tunnelId: string, cb: PortForwardStatusCallback): () => void;
// Known Hosts
@@ -609,6 +611,34 @@ declare global {
credentialsEncrypt?(plaintext: string): Promise<string>;
credentialsDecrypt?(value: string): Promise<string>;
// Auto-update
checkForUpdate?(): Promise<{
available: boolean;
supported?: boolean;
version?: string;
releaseNotes?: string;
releaseDate?: string | null;
error?: string;
}>;
downloadUpdate?(): Promise<{ success: boolean; error?: string }>;
installUpdate?(): void;
getUpdateStatus?(): Promise<{ status: 'idle' | 'downloading' | 'ready' | 'error'; percent: number; error: string | null; version: string | null; isChecking?: boolean }>;
onUpdateDownloadProgress?(cb: (progress: {
percent: number;
bytesPerSecond: number;
transferred: number;
total: number;
}) => void): () => void;
onUpdateAvailable?(cb: (info: {
version: string;
releaseNotes: string;
releaseDate: string | null;
}) => void): () => void;
onUpdateNotAvailable?(cb: () => void): () => void;
onUpdateDownloaded?(cb: () => void): () => void;
onUpdateError?(cb: (payload: { error: string }) => void): () => void;
// Global Toggle Hotkey (Quake Mode)
registerGlobalHotkey?(hotkey: string): Promise<{ success: boolean; enabled?: boolean; error?: string; accelerator?: string }>;
unregisterGlobalHotkey?(): Promise<{ success: boolean }>;

View File

@@ -158,9 +158,14 @@
var lang = localStorage.getItem('netcatty_ui_language_v1');
var root = document.documentElement;
if (theme === 'dark' || theme === 'light') {
// Resolve 'system' (or absent — default is 'system') via OS preference
var resolved = theme;
if (!theme || theme === 'system') {
resolved = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
}
if (resolved === 'dark' || resolved === 'light') {
root.classList.remove('light', 'dark');
root.classList.add(theme);
root.classList.add(resolved);
}
if (accentMode === 'custom' && accentColor) {
@@ -169,7 +174,7 @@
root.style.setProperty('--ring', accentColor);
var parts = accentColor.split(/\s+/);
var lightness = parseFloat((parts[2] || '').replace('%', ''));
var accentForeground = theme === 'dark'
var accentForeground = resolved === 'dark'
? '220 40% 96%'
: (!isNaN(lightness) && lightness < 55 ? '0 0% 98%' : '222 47% 12%');
root.style.setProperty('--accent-foreground', accentForeground);

View File

@@ -37,6 +37,7 @@ export const STORAGE_KEY_VAULT_KNOWN_HOSTS_VIEW_MODE = 'netcatty_vault_known_hos
// Update check
export const STORAGE_KEY_UPDATE_LAST_CHECK = 'netcatty_update_last_check_v1';
export const STORAGE_KEY_UPDATE_DISMISSED_VERSION = 'netcatty_update_dismissed_version_v1';
export const STORAGE_KEY_UPDATE_LATEST_RELEASE = 'netcatty_update_latest_release_v1';
// SFTP File Opener Associations
export const STORAGE_KEY_SFTP_FILE_ASSOCIATIONS = 'netcatty_sftp_file_associations_v1';

View File

@@ -31,6 +31,7 @@ import {
SYNC_STORAGE_KEYS,
generateDeviceId,
getDefaultDeviceName,
isProviderReadyForSync,
} from '../../domain/sync';
import packageJson from '../../package.json';
import { EncryptionService } from './EncryptionService';
@@ -911,7 +912,6 @@ export class CloudSyncManager {
* Helper: Check for conflicts with a specific provider
*/
private async checkProviderConflict(
provider: CloudProvider,
adapter: CloudAdapter
): Promise<{
conflict: boolean;
@@ -946,6 +946,7 @@ export class CloudSyncManager {
): Promise<SyncResult> {
try {
await adapter.upload(syncedFile);
this.state.lastError = null;
// Update local state (safe to do multiple times if values are same)
this.state.localVersion = syncedFile.meta.version;
@@ -985,6 +986,7 @@ export class CloudSyncManager {
this.emit({ type: 'SYNC_COMPLETED', provider, result });
return result;
} catch (error) {
this.state.lastError = String(error);
this.updateProviderStatus(provider, 'error', String(error));
// Add to sync history
@@ -1017,6 +1019,7 @@ export class CloudSyncManager {
keys: SyncPayload['keys'];
snippets: SyncPayload['snippets'];
customGroups: SyncPayload['customGroups'];
snippetPackages?: SyncPayload['snippetPackages'];
portForwardingRules?: SyncPayload['portForwardingRules'];
knownHosts?: SyncPayload['knownHosts'];
settings?: SyncPayload['settings'];
@@ -1065,12 +1068,13 @@ export class CloudSyncManager {
}
this.updateProviderStatus(provider, 'syncing');
this.state.lastError = null;
this.state.syncState = 'SYNCING';
this.emit({ type: 'SYNC_STARTED', provider });
try {
// 1. Check for conflict
const checkResult = await this.checkProviderConflict(provider, adapter);
const checkResult = await this.checkProviderConflict(adapter);
if (checkResult.error) {
throw new Error(checkResult.error);
@@ -1253,17 +1257,15 @@ export class CloudSyncManager {
}
const connectedProviders = Object.entries(this.state.providers)
.filter(([p, conn]) => {
if (conn.status === 'connected') return true;
// Auto-recover: retry providers stuck in 'error' if tokens/config still exist
if (conn.status === 'error' && (conn.tokens || conn.config)) {
this.state.providers[p as CloudProvider].status = 'connected';
this.state.providers[p as CloudProvider].error = undefined;
.filter(([provider, connection]) => {
if (!isProviderReadyForSync(connection)) return false;
if (connection.status === 'error') {
this.state.providers[provider as CloudProvider].status = 'connected';
this.state.providers[provider as CloudProvider].error = undefined;
// Clear cached adapter so a fresh one is created with current (decrypted) tokens
this.adapters.delete(p as CloudProvider);
return true;
this.adapters.delete(provider as CloudProvider);
}
return false;
return true;
})
.map(([p]) => p as CloudProvider);
@@ -1271,6 +1273,7 @@ export class CloudSyncManager {
return results;
}
this.state.lastError = null;
this.state.syncState = 'SYNCING';
// 1. Parallel Checks
@@ -1281,7 +1284,7 @@ export class CloudSyncManager {
this.updateProviderStatus(provider, 'syncing');
this.emit({ type: 'SYNC_STARTED', provider });
const check = await this.checkProviderConflict(provider, adapter);
const check = await this.checkProviderConflict(adapter);
return { provider, adapter, check };
} catch (error) {
return { provider, error: String(error) };

View File

@@ -563,7 +563,6 @@ export class OneDriveAdapter {
}
private async runWithAuthRetry<T>(
context: string,
operation: (accessToken: string) => Promise<T>
): Promise<T> {
const accessToken = await this.ensureValidToken();
@@ -593,7 +592,7 @@ export class OneDriveAdapter {
* Initialize or find sync file
*/
async initializeSync(): Promise<string | null> {
return this.runWithAuthRetry('initializeSync', async (accessToken) => {
return this.runWithAuthRetry(async (accessToken) => {
this.fileId = await findSyncFile(accessToken);
return this.fileId;
});
@@ -603,7 +602,7 @@ export class OneDriveAdapter {
* Upload sync file
*/
async upload(syncedFile: SyncedFile): Promise<string> {
return this.runWithAuthRetry('upload', async (accessToken) => {
return this.runWithAuthRetry(async (accessToken) => {
this.fileId = await uploadSyncFile(accessToken, syncedFile);
return this.fileId;
});
@@ -613,7 +612,7 @@ export class OneDriveAdapter {
* Download sync file
*/
async download(): Promise<SyncedFile | null> {
return this.runWithAuthRetry('download', async (accessToken) => {
return this.runWithAuthRetry(async (accessToken) => {
if (!this.fileId) {
this.fileId = await findSyncFile(accessToken);
}
@@ -629,7 +628,7 @@ export class OneDriveAdapter {
return;
}
await this.runWithAuthRetry('deleteSync', async (accessToken) => {
await this.runWithAuthRetry(async (accessToken) => {
await deleteSyncFile(accessToken, this.fileId as string);
this.fileId = null;
});

View File

@@ -52,6 +52,53 @@ export const clearReconnectTimer = (ruleId: string): void => {
}
};
// Cross-window reconnect cancellation via localStorage broadcast.
// When one window deletes/replaces a rule, it writes to this key so
// other windows (with pending reconnect timers) can cancel them.
const RECONNECT_CANCEL_KEY = '__netcatty_pf_cancel_reconnect';
const broadcastReconnectCancel = (ruleId: string): void => {
try {
// Write then immediately remove so the storage event fires on
// other windows without leaving stale data.
window.localStorage.setItem(RECONNECT_CANCEL_KEY, ruleId);
window.localStorage.removeItem(RECONNECT_CANCEL_KEY);
} catch {
// localStorage may be unavailable in some contexts
}
};
/**
* Start listening for cross-window reconnect cancellation events.
* Should be called once at app init (e.g. in the port-forwarding state hook).
* Returns a cleanup function.
*/
export const initReconnectCancelListener = (): (() => void) => {
const handler = (e: StorageEvent) => {
if (e.key !== RECONNECT_CANCEL_KEY || !e.newValue) return;
const ruleId = e.newValue;
clearReconnectTimer(ruleId);
const conn = activeConnections.get(ruleId);
if (conn) {
conn.unsubscribe?.();
activeConnections.delete(ruleId);
}
// Also ask the backend to stop any tunnel for this rule.
// This catches tunnels still in SSH handshake that aren't yet
// in the renderer's activeConnections or the backend's list output.
const bridge = netcattyBridge.get();
if (bridge?.stopPortForwardByRuleId) {
bridge.stopPortForwardByRuleId(ruleId).catch((err: unknown) => {
logger.warn(`[PortForwardingService] Cross-window stopByRuleId failed for ${ruleId}:`, err);
});
}
};
window.addEventListener('storage', handler);
return () => window.removeEventListener('storage', handler);
};
/**
* Helper function to schedule a reconnection attempt
* Returns true if a reconnect was scheduled, false otherwise
@@ -69,16 +116,22 @@ const scheduleReconnectIfNeeded = (
const attempts = (currentConn?.reconnectAttempts ?? 0) + 1;
if (attempts <= MAX_RECONNECT_ATTEMPTS) {
// If the activeConnections entry was already deleted (e.g. by
// stopAndCleanupRule while the handshake was in-flight), we
// can't actually schedule a reconnect. Return false so the
// caller transitions to 'inactive' instead of stuck 'connecting'.
if (!currentConn) {
return false;
}
logger.info(`[PortForwardingService] Scheduling reconnect ${attempts}/${MAX_RECONNECT_ATTEMPTS}`);
if (currentConn) {
currentConn.reconnectAttempts = attempts;
currentConn.reconnectTimeoutId = setTimeout(() => {
if (reconnectCallback) {
reconnectCallback(ruleId, onStatusChange);
}
}, RECONNECT_DELAY_MS);
}
currentConn.reconnectAttempts = attempts;
currentConn.reconnectTimeoutId = setTimeout(() => {
if (reconnectCallback) {
reconnectCallback(ruleId, onStatusChange);
}
}, RECONNECT_DELAY_MS);
onStatusChange('connecting', `Reconnecting (${attempts}/${MAX_RECONNECT_ATTEMPTS})...`);
return true;
@@ -108,6 +161,39 @@ export const getActiveRuleIds = (): string[] => {
.map(([ruleId]) => ruleId);
};
/**
* Stop and clean up a single rule's tunnel.
* Used when a rule is deleted or replaced via import, where we need to ensure
* the backend tunnel is torn down and all reconnect timers are cancelled.
* This is a fire-and-forget cleanup — errors are logged but not propagated.
*/
export const stopAndCleanupRule = (ruleId: string): void => {
clearReconnectTimer(ruleId);
// Broadcast to other windows so they cancel any pending reconnect
// timers for this rule (e.g. main window has a reconnect scheduled
// but settings window just deleted the rule).
broadcastReconnectCancel(ruleId);
const conn = activeConnections.get(ruleId);
if (conn) {
// Unsubscribe from status events
conn.unsubscribe?.();
activeConnections.delete(ruleId);
}
// Use stopPortForwardByRuleId exclusively — it sets tunnel.cancelled = true
// before conn.end(), so the close handler resolves gracefully. The old
// stopPortForward(tunnelId) IPC deletes the tunnel entry immediately,
// which makes the cancelled flag invisible to the close handler.
const bridge = netcattyBridge.get();
if (bridge?.stopPortForwardByRuleId) {
bridge.stopPortForwardByRuleId(ruleId).catch((err: unknown) => {
logger.warn(`[PortForwardingService] Backend stopByRuleId failed for ${ruleId}:`, err);
});
}
};
// Tunnel ID prefix and UUID regex pattern for parsing
const TUNNEL_ID_PREFIX = 'pf-';
// UUID format: 8-4-4-4-12 hexadecimal characters
@@ -166,7 +252,7 @@ export const syncWithBackend = async (): Promise<void> => {
activeConnections.set(ruleId, {
ruleId,
tunnelId: tunnel.tunnelId,
status: 'active',
status: (tunnel.status === 'active' ? 'active' : 'connecting') as 'active' | 'connecting',
});
logger.info(`[PortForwardingService] Synced active tunnel for rule ${ruleId}`);
@@ -177,6 +263,93 @@ export const syncWithBackend = async (): Promise<void> => {
}
};
/**
* Reconcile renderer-side connection state with the backend (heartbeat).
*
* Returns the set of ruleIds whose status changed so the caller can update
* React state accordingly.
*
* Cases handled:
* 1. Renderer thinks a tunnel is active, but backend says it's gone
* → clean up activeConnections, return ruleId as "gone"
* 2. Backend has an active tunnel that the renderer doesn't track
* → add to activeConnections, return ruleId as "appeared"
*/
export const reconcileWithBackend = async (): Promise<{
gone: string[];
appeared: string[];
}> => {
const result = { gone: [] as string[], appeared: [] as string[] };
const bridge = netcattyBridge.get();
if (!bridge?.listPortForwards) return result;
try {
const backendTunnels = await bridge.listPortForwards();
const backendRuleIds = new Set<string>();
for (const tunnel of backendTunnels) {
const ruleId = parseRuleIdFromTunnelId(tunnel.tunnelId);
if (ruleId) {
backendRuleIds.add(ruleId);
// Case 2: backend has it, renderer doesn't — insert it
if (!activeConnections.has(ruleId)) {
activeConnections.set(ruleId, {
ruleId,
tunnelId: tunnel.tunnelId,
status: (tunnel.status === 'active' ? 'active' : 'connecting') as 'active' | 'connecting',
});
result.appeared.push(ruleId);
} else {
// Case 3: renderer tracks it, but status may have changed
// (e.g. connecting → active after SSH handshake completed
// in another window).
const existing = activeConnections.get(ruleId)!;
const backendStatus = (tunnel.status === 'active' ? 'active' : 'connecting') as 'active' | 'connecting';
if (existing.status !== backendStatus) {
existing.status = backendStatus;
existing.tunnelId = tunnel.tunnelId;
result.appeared.push(ruleId);
}
}
}
}
// Case 1: renderer thinks tunnel is active/connecting, but backend
// says it's gone. For 'connecting' entries seeded by a previous
// reconcile (observing another window's handshake), also evict if the
// backend no longer reports them — the handshake failed or was
// cancelled. Only skip 'connecting' entries that this renderer
// initiated itself (they have an unsubscribe callback because this
// renderer called startPortForward and registered a status listener).
for (const [ruleId, conn] of activeConnections) {
if (!backendRuleIds.has(ruleId)) {
// Skip locally-initiated connecting tunnels (have unsubscribe)
// — the backend hasn't reported them yet because the handshake
// is still in progress.
if (conn.status === 'connecting' && conn.unsubscribe) {
continue;
}
conn.unsubscribe?.();
clearReconnectTimer(ruleId);
activeConnections.delete(ruleId);
result.gone.push(ruleId);
}
}
if (result.gone.length || result.appeared.length) {
logger.info(
`[PortForwardingService] Reconcile: ${result.gone.length} gone, ${result.appeared.length} appeared`,
);
}
} catch (err) {
logger.warn('[PortForwardingService] Reconcile failed:', err);
}
return result;
};
/**
* Start a port forwarding tunnel
* @param enableReconnect - If true, will automatically attempt to reconnect on disconnect
@@ -259,6 +432,15 @@ export const startPortForward = async (
});
if (!result.success) {
// Intentional cancellation (rule deleted/replaced during handshake).
// Clean up quietly — no error state, no reconnect.
if ((result as { cancelled?: boolean }).cancelled) {
activeConnections.delete(rule.id);
unsubscribe?.();
onStatusChange('inactive');
return { success: false, error: undefined };
}
// Check if we should attempt reconnect
const reconnectScheduled = scheduleReconnectIfNeeded(rule.id, enableReconnect, onStatusChange);
if (reconnectScheduled) {
@@ -360,6 +542,7 @@ export const isBackendAvailable = (): boolean => {
export const stopAllPortForwards = async (): Promise<void> => {
const bridge = netcattyBridge.get();
// Stop everything the renderer knows about
for (const [ruleId, conn] of activeConnections) {
// Clear any pending reconnect timer
clearReconnectTimer(ruleId);
@@ -375,6 +558,18 @@ export const stopAllPortForwards = async (): Promise<void> => {
}
activeConnections.clear();
// Also ask the backend to stop ALL tunnels it knows about.
// This covers tunnels that were started by other windows or that
// this renderer doesn't have in its activeConnections map (e.g.
// settings window opened before initializeStore finished).
if (bridge?.stopAllPortForwards) {
try {
await bridge.stopAllPortForwards();
} catch (err) {
logger.warn('[PortForwardingService] Backend stopAllPortForwards failed:', err);
}
}
};
/**

View File

@@ -1,66 +0,0 @@
import { Host,SSHKey,Snippet } from '../../domain/models';
interface BackupData {
hosts: Host[];
keys: SSHKey[];
snippets: Snippet[];
customGroups: string[];
timestamp: number;
version: number;
}
export const syncToGist = async (token: string, gistId: string | undefined, data: Omit<BackupData, 'timestamp' | 'version'>): Promise<string> => {
const payload = {
description: "Netcatty SSH Config Backup",
public: false,
files: {
"netcatty-config.json": {
content: JSON.stringify({ ...data, timestamp: Date.now(), version: 1 }, null, 2)
}
}
};
const url = gistId
? `https://api.github.com/gists/${gistId}`
: `https://api.github.com/gists`;
const method = gistId ? 'PATCH' : 'POST';
const response = await fetch(url, {
method,
headers: {
'Authorization': `token ${token}`,
'Accept': 'application/vnd.github.v3+json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`Failed to sync: ${response.statusText}`);
}
const result = await response.json();
return result.id;
};
export const loadFromGist = async (token: string, gistId: string): Promise<BackupData> => {
const response = await fetch(`https://api.github.com/gists/${gistId}`, {
headers: {
'Authorization': `token ${token}`,
'Accept': 'application/vnd.github.v3+json'
}
});
if (!response.ok) {
throw new Error(`Failed to load: ${response.statusText}`);
}
const result = await response.json();
const file = result.files["netcatty-config.json"];
if (!file || !file.content) {
throw new Error("Invalid Gist format: netcatty-config.json not found");
}
return JSON.parse(file.content);
};

View File

@@ -1,7 +1,17 @@
/**
* Update Service - Checks GitHub releases for new versions
* Update Service
*
* Combines two update mechanisms:
* 1. GitHub API-based version comparison (used by useUpdateCheck for notification banner)
* 2. electron-updater bridge (used by SettingsSystemTab for download/install)
*/
import { netcattyBridge } from "./netcattyBridge";
// ================================
// Part 1: GitHub API Version Check
// ================================
const GITHUB_API_URL = 'https://api.github.com/repos/binaricat/Netcatty/releases/latest';
const RELEASES_PAGE_URL = 'https://github.com/binaricat/Netcatty/releases';
@@ -60,69 +70,46 @@ export function compareVersions(a: string, b: string): number {
}
/**
* Fetch the latest release info from GitHub
* Check for updates via GitHub API (compares version strings).
* Used by useUpdateCheck for the notification banner.
*/
export async function fetchLatestRelease(): Promise<ReleaseInfo | null> {
export async function checkForUpdates(currentVersion: string): Promise<UpdateCheckResult> {
try {
const response = await fetch(GITHUB_API_URL, {
headers: {
'Accept': 'application/vnd.github.v3+json',
// Using anonymous access - rate limited to 60 requests/hour
},
headers: { Accept: 'application/vnd.github.v3+json' },
});
if (!response.ok) {
if (response.status === 404) {
// No releases yet
return null;
}
throw new Error(`GitHub API error: ${response.status}`);
throw new Error(`GitHub API returned ${response.status}`);
}
const data = await response.json();
const latestVersion = (data.tag_name as string).replace(/^v/i, '');
return {
version: data.tag_name?.replace(/^v/i, '') || '0.0.0',
tagName: data.tag_name || '',
name: data.name || data.tag_name || '',
const latestRelease: ReleaseInfo = {
version: latestVersion,
tagName: data.tag_name,
name: data.name || data.tag_name,
body: data.body || '',
htmlUrl: data.html_url || RELEASES_PAGE_URL,
publishedAt: data.published_at || '',
assets: (data.assets || []).map((asset: { name?: string; browser_download_url?: string; size?: number }) => ({
name: asset.name || '',
browserDownloadUrl: asset.browser_download_url || '',
size: asset.size || 0,
htmlUrl: data.html_url,
publishedAt: data.published_at,
assets: (data.assets || []).map((a: { name: string; browser_download_url: string; size: number }) => ({
name: a.name,
browserDownloadUrl: a.browser_download_url,
size: a.size,
})),
};
const hasUpdate = compareVersions(latestVersion, currentVersion) > 0;
return { hasUpdate, currentVersion, latestRelease };
} catch (error) {
console.warn('[UpdateService] Failed to fetch latest release:', error);
return null;
}
}
/**
* Check for updates
*/
export async function checkForUpdates(currentVersion: string): Promise<UpdateCheckResult> {
const result: UpdateCheckResult = {
hasUpdate: false,
currentVersion,
latestRelease: null,
};
try {
const release = await fetchLatestRelease();
if (!release) {
return result;
}
result.latestRelease = release;
result.hasUpdate = compareVersions(release.version, currentVersion) > 0;
return result;
} catch (error) {
result.error = error instanceof Error ? error.message : 'Unknown error';
return result;
return {
hasUpdate: false,
currentVersion,
latestRelease: null,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
}
@@ -144,7 +131,7 @@ export function getDownloadUrlForPlatform(
platform: string
): string | null {
const assets = release.assets;
// Platform-specific file patterns
const patterns: Record<string, RegExp[]> = {
win32: [/\.exe$/i, /win.*\.zip$/i, /windows/i],
@@ -153,7 +140,7 @@ export function getDownloadUrlForPlatform(
};
const platformPatterns = patterns[platform] || [];
for (const pattern of platformPatterns) {
const asset = assets.find((a) => pattern.test(a.name));
if (asset) {
@@ -164,3 +151,73 @@ export function getDownloadUrlForPlatform(
// Fallback to release page
return null;
}
// =============================================
// Part 2: electron-updater Bridge (IPC-based)
// =============================================
export interface ElectronUpdateCheckResult {
available: boolean;
supported?: boolean;
version?: string;
releaseNotes?: string;
releaseDate?: string | null;
error?: string;
}
export interface UpdateDownloadProgress {
percent: number;
bytesPerSecond: number;
transferred: number;
total: number;
}
export async function checkForUpdate(): Promise<ElectronUpdateCheckResult> {
const bridge = netcattyBridge.get();
if (!bridge?.checkForUpdate) {
return { available: false, supported: false, error: "Bridge unavailable" };
}
try {
return await bridge.checkForUpdate();
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "Unknown error";
return { available: false, error: message };
}
}
export async function downloadUpdate(): Promise<{ success: boolean; error?: string }> {
const bridge = netcattyBridge.get();
if (!bridge?.downloadUpdate) {
return { success: false, error: "Bridge unavailable" };
}
return bridge.downloadUpdate();
}
export function installUpdate(): void {
const bridge = netcattyBridge.get();
bridge?.installUpdate?.();
}
export function onDownloadProgress(
cb: (progress: UpdateDownloadProgress) => void,
): (() => void) | undefined {
return netcattyBridge.get()?.onUpdateDownloadProgress?.(cb);
}
export function onDownloaded(cb: () => void): (() => void) | undefined {
return netcattyBridge.get()?.onUpdateDownloaded?.(cb);
}
export function onError(
cb: (payload: { error: string }) => void,
): (() => void) | undefined {
return netcattyBridge.get()?.onUpdateError?.(cb);
}
/** Returns the GitHub Releases page URL, optionally for a specific version tag. */
export function getReleasesUrl(version?: string): string {
if (version) {
return `${RELEASES_PAGE_URL}/tag/v${version}`;
}
return `${RELEASES_PAGE_URL}/latest`;
}

View File

@@ -342,7 +342,7 @@ export async function uploadFromDataTransfer(
if (folderEntries.length > 0) {
try {
const compressedResults = await uploadFoldersCompressed(folderEntries, entries, targetPath, sftpId, callbacks, controller);
const compressedResults = await uploadFoldersCompressed(folderEntries, targetPath, sftpId, callbacks, controller);
// Check if any folders failed due to lack of compression support
const failedFolders = compressedResults.filter(result =>
@@ -429,7 +429,7 @@ export async function uploadFromFileList(
if (folderEntries.length > 0) {
try {
const compressedResults = await uploadFoldersCompressed(folderEntries, entries, targetPath, sftpId, callbacks, controller);
const compressedResults = await uploadFoldersCompressed(folderEntries, targetPath, sftpId, callbacks, controller);
// Check if any folders failed due to lack of compression support
const failedFolders = compressedResults.filter(result =>
@@ -931,7 +931,6 @@ export async function uploadEntriesDirect(
*/
async function uploadFoldersCompressed(
folderEntries: Array<[string, DropEntry[]]>,
allEntries: DropEntry[],
targetPath: string,
sftpId: string,
callbacks?: UploadCallbacks,

78
package-lock.json generated
View File

@@ -32,6 +32,7 @@
"@xterm/addon-webgl": "^0.18.0",
"@xterm/xterm": "^5.5.0",
"clsx": "2.1.1",
"electron-updater": "^6.8.3",
"iconv-lite": "^0.6.3",
"lucide-react": "0.560.0",
"monaco-editor": "^0.55.1",
@@ -6297,7 +6298,6 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"dev": true,
"license": "Python-2.0"
},
"node_modules/aria-hidden": {
@@ -6609,7 +6609,6 @@
"version": "9.5.1",
"resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-9.5.1.tgz",
"integrity": "sha512-qt41tMfgHTllhResqM5DcnHyDIWNgzHvuY2jDcYP9iaGpkWxTUzV6GQjDeLnlR1/DtdlcsWQbA7sByMpmJFTLQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"debug": "^4.3.4",
@@ -7685,6 +7684,57 @@
"dev": true,
"license": "ISC"
},
"node_modules/electron-updater": {
"version": "6.8.3",
"resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-6.8.3.tgz",
"integrity": "sha512-Z6sgw3jgbikWKXei1ENdqFOxBP0WlXg3TtKfz0rgw2vIZFJUyI4pD7ZN7jrkm7EoMK+tcm/qTnPUdqfZukBlBQ==",
"license": "MIT",
"dependencies": {
"builder-util-runtime": "9.5.1",
"fs-extra": "^10.1.0",
"js-yaml": "^4.1.0",
"lazy-val": "^1.0.5",
"lodash.escaperegexp": "^4.1.2",
"lodash.isequal": "^4.5.0",
"semver": "~7.7.3",
"tiny-typed-emitter": "^2.1.0"
}
},
"node_modules/electron-updater/node_modules/fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
"integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/electron-updater/node_modules/jsonfile": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz",
"integrity": "sha512-FGuPw30AdOIUTRMC2OMRtQV+jkVj2cfPqSeWXv1NEAJ1qZ5zb1X6z1mFhbfOB/iy3ssJCD+3KuZ8r8C3uVFlAg==",
"license": "MIT",
"dependencies": {
"universalify": "^2.0.0"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
},
"node_modules/electron-updater/node_modules/universalify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
"integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
"license": "MIT",
"engines": {
"node": ">= 10.0.0"
}
},
"node_modules/electron-winstaller": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/electron-winstaller/-/electron-winstaller-5.4.0.tgz",
@@ -8818,7 +8868,6 @@
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"dev": true,
"license": "ISC"
},
"node_modules/gtoken": {
@@ -9318,7 +9367,6 @@
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz",
"integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==",
"dev": true,
"license": "MIT",
"dependencies": {
"argparse": "^2.0.1"
@@ -9482,7 +9530,6 @@
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.5.tgz",
"integrity": "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q==",
"dev": true,
"license": "MIT"
},
"node_modules/levn": {
@@ -9783,6 +9830,19 @@
"dev": true,
"license": "MIT"
},
"node_modules/lodash.escaperegexp": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz",
"integrity": "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==",
"license": "MIT"
},
"node_modules/lodash.isequal": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
"integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==",
"deprecated": "This package is deprecated. Use require('node:util').isDeepStrictEqual instead.",
"license": "MIT"
},
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
@@ -11318,7 +11378,6 @@
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.4.4.tgz",
"integrity": "sha512-1n3r/tGXO6b6VXMdFT54SHzT9ytu9yr7TaELowdYpMqY/Ao7EnlQGmAQ1+RatX7Tkkdm6hONI2owqNx2aZj5Sw==",
"dev": true,
"license": "BlueOak-1.0.0",
"engines": {
"node": ">=11.0.0"
@@ -11334,7 +11393,6 @@
"version": "7.7.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz",
"integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
@@ -11926,6 +11984,12 @@
"semver": "bin/semver"
}
},
"node_modules/tiny-typed-emitter": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz",
"integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==",
"license": "MIT"
},
"node_modules/tinyglobby": {
"version": "0.2.15",
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz",

View File

@@ -50,6 +50,7 @@
"@xterm/addon-webgl": "^0.18.0",
"@xterm/xterm": "^5.5.0",
"clsx": "2.1.1",
"electron-updater": "^6.8.3",
"iconv-lite": "^0.6.3",
"lucide-react": "0.560.0",
"monaco-editor": "^0.55.1",
@@ -87,4 +88,4 @@
"cpu-features": "npm:empty-npm-package@1.0.0",
"axios": "1.13.5"
}
}
}

View File

@@ -0,0 +1,2 @@
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>AlmaLinux</title><path d="M23.994 15.133c.079 1.061-.668 1.927-1.69 2.005a1.8 1.8 0 0 1-1.928-1.651c-.078-1.062.63-1.849 1.691-1.967c1.023-.078 1.849.59 1.927 1.613m-12.623 4.955c-.944 0-1.73.786-1.73 1.809c0 1.14.747 1.848 1.887 1.848c.904-.04 1.691-.865 1.691-1.809c0-.983-.904-1.848-1.848-1.848m1.061-9.675c-.039-.865-.078-1.73.08-2.556c.156-.944.314-1.887.904-2.674c.707-.983 1.809-.944 2.399.118c.314.511.432 1.062.471 1.652c0 .354.158.432.472.393c.944-.157 1.888-.157 2.792.197c.118.039.236.118.394 0c.314-.276.393-1.652.196-2.006c-.354-.63-.904-.55-1.455-.55c-.629.039-1.18-.158-1.612-.67c-.393-.471-.511-1.06-.59-1.65c-.04-.276-.079-.512-.315-.709c-.55-.55-1.809-.432-2.477.118c-2.556 2.045-2.989 5.467-1.534 8.18c.04.118.118.236.275.157m7.984 3.658c.354-.511.865-.747 1.415-.983a.97.97 0 0 0 .59-.472c.354-.669-.078-1.81-.747-2.36c-2.595-2.006-5.938-1.612-8.18.433c-.118.078-.157.196-.078.314c.786-.236 1.612-.472 2.477-.51c.905-.08 1.848-.158 2.753.235c1.14.472 1.337 1.534.472 2.36c-.393.393-.905.668-1.455.825c-.315.08-.354.236-.236.551c.354.865.59 1.77.472 2.753c-.04.157-.079.275.078.393c.354.236 1.691 0 1.967-.275c.511-.472.314-1.023.196-1.534c-.157-.63-.078-1.219.276-1.73m-7.197-2.045c-.118-.079-.197-.118-.315 0c.472.708.905 1.455 1.259 2.241c.314.866.668 1.73.55 2.714c-.118 1.18-1.1 1.69-2.123 1.101c-.511-.275-.905-.669-1.22-1.14c-.196-.276-.393-.276-.629-.08c-.747.63-1.533 1.102-2.516 1.26c-.158 0-.315 0-.394.157c-.118.393.472 1.612.826 1.809c.59.354 1.062 0 1.534-.276c.55-.314 1.101-.432 1.73-.236c.59.197.983.63 1.337 1.102c.158.196.315.353.63.432c.747.197 1.77-.59 2.084-1.376c1.18-3.028-.157-6.135-2.753-7.708m-2.556 2.438c.472-.669.826-1.416.983-2.202c-.157-.04-.197.04-.315.078c-.904.944-1.848 1.849-3.067 2.478c-.472.236-.983.433-1.534.433c-.865 0-1.376-.551-1.298-1.416a2.92 2.92 0 0 1 .787-1.849c.236-.275.236-.432-.04-.668c-.786-.55-1.494-1.22-1.848-2.124c-.078-.275-.275-.275-.51-.157a4 4 0 0 0-.434.236c-1.022.63-1.14 1.416-.275 2.28c.63.63.944 1.338.708 2.203c-.118.433-.354.747-.63 1.101a.95.95 0 0 0-.235.787c.079.747.826 1.494 1.73 1.573c2.517.236 4.562-.63 5.978-2.753m-4.68-5.152c1.376 1.18 3.067 1.455 4.837 1.377c.157 0 .315 0 .354-.118c.04-.197-.157-.197-.275-.236c-.826-.354-1.691-.63-2.438-1.14S6.848 8.25 6.534 7.266c-.236-.747.078-1.415.825-1.651c.669-.236 1.337-.236 1.967 0c.393.157.55.078.629-.354c.118-.747.354-1.455.826-2.085c.55-.786.55-.865-.354-1.376c-.04 0-.04-.04-.079-.04c-.865-.471-1.534-.196-1.848.709c-.472 1.376-1.377 1.887-2.832 1.612a4 4 0 0 0-.472-.079c-.747.118-1.18.55-1.297 1.14c-.158 1.81.786 3.107 2.084 4.17m-2.32 3.658c-.079-.944-1.023-1.652-2.045-1.534c-.905.079-1.691 1.022-1.613 1.966c.08.983 1.023 1.77 1.967 1.652c1.14-.079 1.73-1.18 1.69-2.084zm15.18-8.298c.943-.079 1.73-.983 1.651-1.927c-.078-.983-1.022-1.77-2.005-1.691c-1.023.079-1.73.983-1.652 1.966s.983 1.73 2.006 1.652m-12.27-.826c1.062-.157 1.77-1.023 1.652-2.045C8.107.897 7.163.149 6.18.267c-1.062.118-1.691.944-1.573 2.085c.118.865 1.061 1.612 1.966 1.494"/>
</svg>

After

Width:  |  Height:  |  Size: 3.0 KiB