Skip to content

Allow Connect to run in background#58575

Merged
gzdunek merged 23 commits intomasterfrom
gzdunek/connect-tray
Sep 5, 2025
Merged

Allow Connect to run in background#58575
gzdunek merged 23 commits intomasterfrom
gzdunek/connect-tray

Conversation

@gzdunek
Copy link
Copy Markdown
Contributor

@gzdunek gzdunek commented Sep 2, 2025

Closes #54275

Connect will now run in the background, in a system tray:
image

When the app window is closed, we terminate all active foreground sessions (SSH, local terminal, Windows desktop).
To implement this, the UI listens to window visibility events emitted by the main process. When the window is hidden, the UI unmounts active documents; when it becomes visible again, the documents are remounted.

This required addressing a few edge cases:

  • Mounting documents caused multiple per-season MFA prompts in a row
    Our documents automatically reconnect when mounted. This led to multiple per-session MFA prompts being triggered in a row, which caused them to fail (there is a mutex in the daemon, but maybe YubiKey needs some delay between prompts?). The same issue also appeared when reopening a previous session. To fix this, documents now only mount when they are visible. This should also improve UX, being hit by multiple dialogs when launching the app feels annoying.
    EDIT: Only DocumentTerminal and DocumentDesktopSession documents will mount when visible.
  • Per-session MFA dialogs were conflicting with dialogs triggered by tshd events
    When the app receives a tshd event, it makes the window visible and usually shows a dialog. That dialog conflicted with an MFA dialog triggered by document activation. As a workaround, certain documents are now only activated when no dialogs are visible. Additionally, the order of tshd event handling was updated: we now open the dialog first and then focus (and show) the window.

Best to review commit by commit.

changelog: Teleport Connect now runs in the background by default on macOS and Windows. On Linux, this behavior can be enabled in the app configuration

TODO: add docs

@gzdunek gzdunek force-pushed the gzdunek/connect-tray branch from 202f0d2 to b17147c Compare September 2, 2025 08:59
Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed until "Notify UI when window visibility changes", so far I only looked at the code.

Comment thread web/packages/teleterm/src/tray.ts Outdated
Comment thread web/packages/teleterm/src/tray.ts
Comment thread web/packages/teleterm/src/main.ts Outdated
Comment thread web/packages/teleterm/src/mainProcess/windowsManager.ts Outdated
Comment thread web/packages/teleterm/src/mainProcess/types.ts Outdated
@ravicious ravicious self-requested a review September 2, 2025 15:56
Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine, I just need to test how this works on Windows and Linux too.

Comment thread web/packages/teleterm/src/ui/Documents/DocumentsRenderer.tsx Outdated
Comment thread web/packages/teleterm/src/ui/Documents/DocumentsRenderer.tsx Outdated
@ravicious ravicious self-requested a review September 3, 2025 17:06
Comment thread web/packages/teleterm/src/tray.ts Outdated
Comment thread web/packages/teleterm/src/mainProcess/windowsManager.ts
Comment thread web/packages/teleterm/src/mainProcess/windowsManager.ts
Comment thread web/packages/teleterm/src/mainProcess/types.ts Outdated
Comment thread web/packages/teleterm/src/mainProcess/windowsManager.ts Outdated
Comment thread web/packages/teleterm/src/ui/hooks/useIsInBackgroundMode.ts Outdated
Comment thread web/packages/teleterm/src/tray.ts
@gzdunek gzdunek requested a review from ravicious September 5, 2025 12:33
Comment thread web/packages/teleterm/src/mainProcess/windowsManager.ts Outdated
@gzdunek gzdunek enabled auto-merge September 5, 2025 14:35
@gzdunek gzdunek added this pull request to the merge queue Sep 5, 2025
Merged via the queue into master with commit 6cef4f3 Sep 5, 2025
40 checks passed
@gzdunek gzdunek deleted the gzdunek/connect-tray branch September 5, 2025 15:04
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@gzdunek See the table below for backport results.

Branch Result
branch/v17 Failed
branch/v18 Create PR

gzdunek added a commit that referenced this pull request Sep 9, 2025
* Add tray icons for Mac and Linux

* Fix resources path

* Add config option

* Set tray when the app launches

* Integrate app with tray

* Notify UI when window visibility changes

* Terminate foreground sessions when window is hidden

* Open dialogs first before showing window

* Improve docs

* Rely on `window.isVisible()` to tell if window is hidden or not

* Change `WindowsManagerIpc.WindowVisibility` to `RendererIpc.WindowVisibility`

* Rename "window visibility" to "background mode"

* Revert "Open dialogs first before showing window"

This reverts commit b17147c.

* Simplify mounting/unmounting documents

* Use different GUIDs for packaged and dev app

* Make sure window is not destroyed before using it

* Renames

* Improve dialog message

* Add `isDestroyed` to window mock

* Fix comment

* `database` -> `databases`

* Improve readability

(cherry picked from commit 6cef4f3)
gzdunek added a commit that referenced this pull request Sep 9, 2025
* Add tray icons for Mac and Linux

* Fix resources path

* Add config option

* Set tray when the app launches

* Integrate app with tray

* Notify UI when window visibility changes

* Terminate foreground sessions when window is hidden

* Open dialogs first before showing window

* Improve docs

* Rely on `window.isVisible()` to tell if window is hidden or not

* Change `WindowsManagerIpc.WindowVisibility` to `RendererIpc.WindowVisibility`

* Rename "window visibility" to "background mode"

* Revert "Open dialogs first before showing window"

This reverts commit b17147c.

* Simplify mounting/unmounting documents

* Use different GUIDs for packaged and dev app

* Make sure window is not destroyed before using it

* Renames

* Improve dialog message

* Add `isDestroyed` to window mock

* Fix comment

* `database` -> `databases`

* Improve readability

(cherry picked from commit 6cef4f3)
github-merge-queue bot pushed a commit that referenced this pull request Sep 10, 2025
* Allow Connect to run in background (#58575)

* Add tray icons for Mac and Linux

* Fix resources path

* Add config option

* Set tray when the app launches

* Integrate app with tray

* Notify UI when window visibility changes

* Terminate foreground sessions when window is hidden

* Open dialogs first before showing window

* Improve docs

* Rely on `window.isVisible()` to tell if window is hidden or not

* Change `WindowsManagerIpc.WindowVisibility` to `RendererIpc.WindowVisibility`

* Rename "window visibility" to "background mode"

* Revert "Open dialogs first before showing window"

This reverts commit b17147c.

* Simplify mounting/unmounting documents

* Use different GUIDs for packaged and dev app

* Make sure window is not destroyed before using it

* Renames

* Improve dialog message

* Add `isDestroyed` to window mock

* Fix comment

* `database` -> `databases`

* Improve readability

(cherry picked from commit 6cef4f3)

* Dialog improvements from #58858
github-merge-queue bot pushed a commit that referenced this pull request Sep 10, 2025
* Allow Connect to run in background (#58575)

* Add tray icons for Mac and Linux

* Fix resources path

* Add config option

* Set tray when the app launches

* Integrate app with tray

* Notify UI when window visibility changes

* Terminate foreground sessions when window is hidden

* Open dialogs first before showing window

* Improve docs

* Rely on `window.isVisible()` to tell if window is hidden or not

* Change `WindowsManagerIpc.WindowVisibility` to `RendererIpc.WindowVisibility`

* Rename "window visibility" to "background mode"

* Revert "Open dialogs first before showing window"

This reverts commit b17147c.

* Simplify mounting/unmounting documents

* Use different GUIDs for packaged and dev app

* Make sure window is not destroyed before using it

* Renames

* Improve dialog message

* Add `isDestroyed` to window mock

* Fix comment

* `database` -> `databases`

* Improve readability

(cherry picked from commit 6cef4f3)

* Dialog improvements from #58858
mmcallister pushed a commit that referenced this pull request Sep 22, 2025
* Add tray icons for Mac and Linux

* Fix resources path

* Add config option

* Set tray when the app launches

* Integrate app with tray

* Notify UI when window visibility changes

* Terminate foreground sessions when window is hidden

* Open dialogs first before showing window

* Improve docs

* Rely on `window.isVisible()` to tell if window is hidden or not

* Change `WindowsManagerIpc.WindowVisibility` to `RendererIpc.WindowVisibility`

* Rename "window visibility" to "background mode"

* Revert "Open dialogs first before showing window"

This reverts commit b17147c.

* Simplify mounting/unmounting documents

* Use different GUIDs for packaged and dev app

* Make sure window is not destroyed before using it

* Renames

* Improve dialog message

* Add `isDestroyed` to window mock

* Fix comment

* `database` -> `databases`

* Improve readability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Teleport Connect to run in the background

3 participants