Files
archived-orca/src/preload/api/orca-profiles-bridge.ts
T
Jinwoo Hong c4730d692f fix(cloud-auth): show that a sign-in is in progress, with copy-link and cancel, on every Orca sign-in button (#30410)
* fix(cloud-auth): show the browser sign-in wait and offer its link from Relay sign-in

Clicking 'Sign in for Relay' handed the sign-in page to the OS browser and
then showed nothing, so a browser that never came forward looked like a dead
button, and the 5-minute wait ended silently. The Relay sign-in row now shows
the wait with a Copy sign-in link button, and a wait that times out toasts.

STA-10940

* fix(cloud-auth): show the sign-in wait on every Orca sign-in button

The waiting text and Copy sign-in link now come from one shared notice used by
Mobile Relay, Orca Account, Artifacts (settings, page and publish popover),
Share Skills, the unexpected sign-out card and dev tools. The copyable link is
dropped as soon as the browser answers, and a copy with no waiting link
reports a failure instead of doing nothing.

STA-10940

* refactor(cloud-auth): main owns the waiting sign-in link; renderer only mirrors it

The notice now shows exactly while main holds a live link: main announces the
link when the browser wait starts and clears it the moment the browser
answers, so 'Waiting for sign-in in your browser' no longer outlives the wait
during the token exchange. Only the newest attempt may publish its link, so an
older attempt reporting late cannot replace or later wipe it. The renderer's
separate pending flag and its resets are gone.

STA-10940

* fix(cloud-auth): tolerate a sign-in link read that returns no promise

The app-wide IPC tests stub every bridge method as returning nothing, and the
one-time link read called .then on that result.

STA-10940

* fix(cloud-auth): a torn-down link subscription ignores its late snapshot; restore auth bridge tests

A window's one-time sign-in link read could land after its subscription was
disposed and overwrite a newer value from the replacement subscription. The
auth-status refresh tests the earlier rewrite dropped are back, alongside the
link cases.

STA-10940

* feat(cloud-auth): sign-in buttons show Signing in… with copy-link and cancel links

Every Orca sign-in button greys out to 'Signing in…' with a spinner until the
sign-in ends. While the browser has not answered, a line offers 'Copy sign-in
link' and 'Cancel'; Cancel aborts the browser wait so a lost tab never locks
the button. Main owns the in-flight sign-in (waiting on the browser, then
finishing) and every window mirrors it.

STA-10940
2026-10-18 19:28:04 -04:00

69 lines
3.3 KiB
TypeScript

import { ipcRenderer } from 'electron'
import type { PreloadApi } from '../api-types'
import {
ORCA_PROFILE_AUTH_STATUS_CHANGED_CHANNEL,
ORCA_PROFILE_SIGN_IN_PROGRESS_CHANGED_CHANNEL,
type OrcaCloudSignInProgress,
type OrcaProfileListResult,
type SwitchOrcaProfileResult,
type TransferOrcaProfileProjectResult
} from '../../shared/orca-profiles'
import { prepareAndInvokeAppRestart } from '../renderer-restart-wiring'
import { awaitBeforeUnloadCheckpoint } from '../preload-runtime-support'
export const orcaProfilesApi = {
list: () => ipcRenderer.invoke('orcaProfiles:list'),
authStatus: () => ipcRenderer.invoke('orcaProfiles:authStatus'),
onAuthStatusChanged: (callback: () => void): (() => void) => {
const listener = (): void => callback()
ipcRenderer.on(ORCA_PROFILE_AUTH_STATUS_CHANGED_CHANNEL, listener)
return () => ipcRenderer.removeListener(ORCA_PROFILE_AUTH_STATUS_CHANGED_CHANNEL, listener)
},
onSignInProgressChanged: (
callback: (progress: OrcaCloudSignInProgress | null) => void
): (() => void) => {
const listener = (_event: unknown, progress: OrcaCloudSignInProgress | null): void =>
callback(progress)
ipcRenderer.on(ORCA_PROFILE_SIGN_IN_PROGRESS_CHANGED_CHANNEL, listener)
return () => ipcRenderer.removeListener(ORCA_PROFILE_SIGN_IN_PROGRESS_CHANGED_CHANNEL, listener)
},
createLocal: (args) => ipcRenderer.invoke('orcaProfiles:createLocal', args),
createCloudLinked: (args) => ipcRenderer.invoke('orcaProfiles:createCloudLinked', args),
switchProfile: (args) =>
prepareAndInvokeAppRestart(
window,
(): Promise<SwitchOrcaProfileResult> => ipcRenderer.invoke('orcaProfiles:switch', args),
awaitBeforeUnloadCheckpoint,
(result) => result.status === 'relaunching'
),
transferProject: async (args) => {
const invoke = (): Promise<TransferOrcaProfileProjectResult> =>
ipcRenderer.invoke('orcaProfiles:transferProject', args)
if (args.mode !== 'move') {
return invoke()
}
const current: OrcaProfileListResult = await ipcRenderer.invoke('orcaProfiles:list')
if (args.sourceProfileId !== current.activeProfileId) {
return invoke()
}
return prepareAndInvokeAppRestart(
window,
invoke,
awaitBeforeUnloadCheckpoint,
(result) => result.status === 'transferred' && result.willRelaunch === true
)
},
findProjectProfiles: (args) => ipcRenderer.invoke('orcaProfiles:findProjectProfiles', args),
connectCurrent: () => ipcRenderer.invoke('orcaProfiles:connectCurrent'),
signInProgress: () => ipcRenderer.invoke('orcaProfiles:signInProgress'),
cancelSignIn: () => ipcRenderer.invoke('orcaProfiles:cancelSignIn'),
refreshAuth: () => ipcRenderer.invoke('orcaProfiles:refreshAuth'),
signOutCurrent: () => ipcRenderer.invoke('orcaProfiles:signOutCurrent'),
selectOrg: (args) => ipcRenderer.invoke('orcaProfiles:selectOrg', args),
orgMembersList: (args) => ipcRenderer.invoke('orcaProfiles:orgMembersList', args),
orgMemberInvite: (args) => ipcRenderer.invoke('orcaProfiles:orgMemberInvite', args),
orgInviteRevoke: (args) => ipcRenderer.invoke('orcaProfiles:orgInviteRevoke', args),
orgMemberChangeRole: (args) => ipcRenderer.invoke('orcaProfiles:orgMemberChangeRole', args),
orgMemberRemove: (args) => ipcRenderer.invoke('orcaProfiles:orgMemberRemove', args)
} satisfies PreloadApi['orcaProfiles']