remoteConnectionDialogState.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import type { RemoteWizardStep } from "@/RemoteConnectionWizardChrome.js";
  2. interface RemoteConnectionDialogSnapshot {
  3. currentStep: RemoteWizardStep;
  4. loading: boolean;
  5. connectedSessionId: string | null;
  6. }
  7. type RemoteConnectionCompletionStatus = "success" | "error";
  8. interface RemoteConnectionCompletionDialogState {
  9. open: boolean;
  10. step: RemoteWizardStep;
  11. }
  12. interface RemoteConnectionDirectoryFailureState {
  13. connectedSessionId: string | null;
  14. step: RemoteWizardStep;
  15. }
  16. export function isRemoteConnectionFlowActive(snapshot: RemoteConnectionDialogSnapshot): boolean {
  17. return snapshot.loading || Boolean(snapshot.connectedSessionId);
  18. }
  19. export function shouldResetRemoteConnectionOnOpen(
  20. snapshot: RemoteConnectionDialogSnapshot,
  21. ): boolean {
  22. return !isRemoteConnectionFlowActive(snapshot);
  23. }
  24. export function getRemoteConnectionCompletionDialogState(
  25. status: RemoteConnectionCompletionStatus,
  26. ): RemoteConnectionCompletionDialogState {
  27. return {
  28. // 远程连接弹窗收起后,连接完成只更新内部步骤但没有重新展示弹窗,
  29. // 用户会停留在其它页面且看不到选目录或失败原因。连接完成后统一拉起弹窗到结果步骤。
  30. open: true,
  31. step: status === "success" ? "directory" : "connecting",
  32. };
  33. }
  34. export function getRemoteConnectionDirectoryFailureState(params: {
  35. connectedSessionId: string;
  36. sessionStillRegistered: boolean;
  37. }): RemoteConnectionDirectoryFailureState {
  38. if (params.sessionStillRegistered) {
  39. return {
  40. connectedSessionId: params.connectedSessionId,
  41. step: "directory",
  42. };
  43. }
  44. // workspace 初始化失败会回收未确认 logical session。
  45. // 目录步骤继续持有旧 sessionId 时只能拿到空 services,并永久显示“加载中”。
  46. return {
  47. connectedSessionId: null,
  48. step: "settings",
  49. };
  50. }