Desktop window management and navigation
The desktop shell gives users one main application window through which they enter Teams, switch between account profiles, and follow meeting or chat links. It keeps each profile session separate while routing actions from the correct profile surface, so a link or IPC request does not cross into another account. This page complements application lifecycle with the window and navigation view of startup.
Window model
The application uses one main BrowserWindow for the desktop experience. The window restores its last size and position, starts hidden while startup work completes, and then shows or hides according to the user's startup settings. A single-instance lock sends later launches back to this window instead of creating a second application instance. This preserves one place for menus, tray behavior, and global app state. ADR 010 records why the app does not provide separate chat or meeting windows.
The main window is the host for the normal Teams session. Other windows can exist for focused system tasks such as screen sharing, but they are not extra Teams account windows. This distinction keeps account navigation inside one desktop surface.
Profile surfaces
When multi-account mode is enabled, each profile represents one Teams account session. Profile 0 uses the main window's existing legacy session; each additional profile gets its own in-window view and session. The active profile fills the content area, while inactive profile views stay warm and hidden so switching does not require a new login or a page reload.
The profile manager persists profile identity and the active profile. The view manager listens for profile changes and keeps the visible view set aligned with that state. A bottom-left profile switcher and the Profiles menu provide the user entry points for adding, selecting, and managing profiles. See user profiles and workspaces for the profile data model and user-facing profile lifecycle.
Profile entry and first-run migration
Profile setup is opt-in through multiAccount.enabled. On first use, the app checks the existing Teams session and can register it as Profile 0 without asking the user to sign in again. New profiles start separate sessions, which lets users authenticate to another tenant without replacing the current session. Multi-account mode is disabled for the session when Intune SSO is enabled because the identity broker does not support the required concurrent account flow.
The entry path is therefore:
- The app creates and shows the main window.
- The profile manager reads saved profiles.
- The view manager attaches views for non-legacy profiles.
- The existing legacy session becomes Profile 0 when its authenticated state is found.
- The active profile is shown and the switcher state is published.
References: app/index.js• L96-107 app/index.js• L141-150 app/index.js• L696-722 app/…/profileViewManager.js• L141-241 app/…/profileViewManager.js• L267-315
Profile switching
Switching changes which profile surface is visible. It does not reload the Teams page, so each profile keeps its session and current page state. The main window remains the same host, and the switcher stays above the active profile content so it remains available after every switch.
The switcher supports mouse selection from its profile list. Pinned profiles also receive focused-window keyboard slots on supported platforms. The profile menu and switcher both read the same active-profile state, so a change from either surface updates the other.
References: app/…/profileViewManager.js• L404-427 app/…/profileViewManager.js• L612-645 app/…/profileViewManager.js• L663-733 app/…/profilesMenu.js• L13-65
Sender-to-profile mapping
Main-process handlers need to know which profile sent a message because more than one Teams surface now runs inside the same application window. The sender map links each webContents identity to its owning profile and lets handlers resolve either a profile ID or the full profile record.
The mapping follows ownership rather than trusting a profile ID supplied by a renderer:
| Sender surface | Profile result |
|---|---|
| Main window and its descendants | Profile 0 while the legacy profile exists |
| Additional profile view | That profile |
| Popup or webview created by a profile | The profile that created it |
| Profile switcher, dialogs, or unknown sender | Unattributed |
Mappings are removed when a surface is destroyed or a profile is removed. A removed profile also closes its live descendants, which prevents an old authenticated popup from continuing to act for a deleted account. An unattributed sender is not treated as safe; callers must handle the missing profile explicitly.
References: app/…/senderProfileMap.js• L1-27 app/…/senderProfileMap.js• L51-124 app/…/profileViewManager.js• L361-387 app/…/profileViewManager.js• L505-610
Window-open policies
Window-open handling decides whether a link stays in the app, opens outside it, or is denied. The root window owns the older account and authentication behavior. Profile views use a narrower policy so their links remain tied to the profile that produced them.
For profile views and their descendants, Teams launcher links that match the configured deep-link pattern are denied as new popups. When in-app opening is enabled, the same URL loads into the originating profile view. Ordinary profile links keep the default Electron allow behavior until profile-specific authentication and external-link rules can be applied safely. The root window continues to handle authentication popups and external links through its main policy. See authentication and SSO for the sign-in and recovery behavior around these popups.
When a matching link comes from a background profile, the app activates that profile after starting the navigation. The user therefore sees the profile that owns the meeting, chat, or channel link rather than a different active tenant.
References: app/…/profileWindowOpenPolicy.js• L1-30 app/…/profileWindowOpenPolicy.js• L32-105 app/…/profileViewManager.js• L490-503 app/…/profileViewManager.js• L518-546 app/…/index.js• L1280-1326
Deep-link routing
Deep links are entry points into Teams conversations, meetings, and channels. The app accepts configured HTTPS Teams links and msteams:// protocol links, converts protocol links to an HTTPS Teams URL, and sends the result to the existing main or profile surface.
For an already loaded main Teams page, the router first tries an in-page launcher route. This avoids replacing the running Teams session. If the page is not on the expected Teams origin or does not consume the route, the app falls back to a full navigation. Chat links without a recipient are not routed in-page because they do not identify a useful chat target.
The launch path differs by source:
| Source | Result |
|---|---|
| App startup argument | The main window receives the valid Teams URL during startup |
| Second app launch | The existing window is restored, focused, and given the link |
| Link from a profile surface | The link loads into the originating profile and activates it when needed |
The routing flow keeps sensitive link data out of diagnostic messages because chat recipients and meeting context can appear in the URL.
flowchart TD
A[Teams HTTPS or msteams link] --> B[Validate and normalize link]
B --> C{Link source}
C -->|Startup or second launch| D[Main window]
C -->|Profile view or descendant| E[Originating profile view]
D --> F{Loaded Teams page can consume route?}
F -->|Yes| G[In-page Teams navigation]
F -->|No| H[Full page navigation]
E --> I[Load link in profile]
I --> J[Activate owning profile]
References: app/…/index.js• L884-925 app/…/index.js• L1052-1098 app/…/deepLinkRouter.js• L1-17 app/…/deepLinkRouter.js• L24-55 app/…/deepLinkRouter.js• L76-147
Navigation boundaries
The desktop shell keeps several boundaries clear. The single-instance boundary sends new launches to the existing app. The profile boundary keeps cookies and page state with one account. The sender boundary ties main-process work to the surface that requested it. The deep-link boundary chooses in-page navigation, profile navigation, or a full reload.
These boundaries work together during common actions. A notification or external protocol starts at the app boundary, becomes a Teams URL, and then follows the active or originating profile path. A profile switch changes visibility only, so it does not change the identity of existing surfaces or their stored session data.
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to the root window's
webContentsownership must update the Profile 0 mapping and all root descendants. - Changes to profile creation or removal must keep view attachment, sender mappings, and partition cleanup in the same lifecycle.
- Changes to a profile descendant's window-open behavior must preserve the originating profile as the deep-link load target.
- Changes to the deep-link patterns must keep HTTPS links,
msteams://protocol links, and in-page launcher routes aligned. - Changes to profile activation must update both the visible content view and the menu or switcher state.
- Changes to authentication popup handling must account for the separate root-window policy and the narrower profile-view policy.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Profile 0 is not registered after a successful first login | The existing Teams session has no profile entry and root senders remain unattributed | Bootstrap on Teams post-login navigation and keep the legacy profile check idempotent |
| A deep link from a background profile loads into the active root surface | The user can join or open content in the wrong tenant | Load matching profile links into the originating view and activate that profile |
| A popup or webview is not mapped to its owner | IPC from that surface cannot be safely tied to an account | Track descendants recursively and remove mappings when they are destroyed |
| A removed profile leaves a popup alive | A deleted account keeps an authenticated surface running | Close and unregister all profile descendants during removal |
| In-page routing receives a non-Teams frame or an unsupported launcher link | The target route is ignored or applied to the wrong page | Check the Teams origin and fall back to full navigation |
| A malformed profile deep-link pattern reaches the window-open handler | A bad user setting can break main-process link handling | Treat an invalid pattern as no profile-link interception |
| Multi-account mode runs with Intune SSO | Concurrent identity sessions can conflict in the identity broker | Force multi-account off for that startup session |
Key files
| File | Why to read it |
|---|---|
| app/…/browserWindowManager.js | Shows the main window's creation, restored bounds, startup visibility, and legacy session. |
| app/…/index.js | Connects app startup, the single-instance handoff, root window-open policy, and deep-link entry points. |
| app/…/profileViewManager.js | Coordinates profile view creation, visibility, activation, bootstrap, and descendant ownership. |
| app/…/index.js | Defines saved profile identity, active-profile state, and profile lifecycle events. |
| app/…/senderProfileMap.js | Defines how a main-process sender resolves to its owning profile. |
| app/…/profileWindowOpenPolicy.js | Defines deep-link behavior for profile views and their descendants. |
| app/…/deepLinkRouter.js | Defines in-page route handling and the full-navigation fallback. |
| app/…/profilesMenu.js | Shows the menu entry points and focused-window profile shortcuts. |
| docs-site/…/010-multiple-windows-support.md | Explains the single-window boundary and the rejected pop-out model. |
| docs-site/…/020-multi-account-profile-switcher.md | Gives the product-level model and scope for in-window account profiles. |