mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-08-12 06:00:23 +02:00
refactor: cleanup
This commit is contained in:
@@ -78,6 +78,11 @@ export type BackendErrorCode =
|
||||
| "REMOTE_SESSION_CONFLICT"
|
||||
| "REMOTE_SYNC_IN_PROGRESS"
|
||||
| "REMOTE_HOURS_EXHAUSTED"
|
||||
| "PROFILE_RUNNING_REMOTELY"
|
||||
| "PROFILE_REMOTE_SYNC_PENDING"
|
||||
| "PROFILE_LOCKED_BY_MEMBER"
|
||||
| "PROFILE_LOCKED_ELSEWHERE"
|
||||
| "PROFILE_LOCK_UNAVAILABLE"
|
||||
| "NOT_TEAM_MEMBER"
|
||||
| "COOKIE_BOT_NOT_ENTITLED"
|
||||
| "COOKIE_BOT_NOT_ENROLLED"
|
||||
@@ -314,6 +319,18 @@ export function translateBackendError(t: TFunction, err: unknown): string {
|
||||
granted: parsed.params?.granted ?? "0",
|
||||
used: parsed.params?.used ?? "0",
|
||||
});
|
||||
case "PROFILE_RUNNING_REMOTELY":
|
||||
return t("backendErrors.profileRunningRemotely");
|
||||
case "PROFILE_REMOTE_SYNC_PENDING":
|
||||
return t("backendErrors.profileRemoteSyncPending");
|
||||
case "PROFILE_LOCKED_BY_MEMBER":
|
||||
return t("backendErrors.profileLockedByMember", {
|
||||
email: parsed.params?.email ?? "",
|
||||
});
|
||||
case "PROFILE_LOCKED_ELSEWHERE":
|
||||
return t("backendErrors.profileLockedElsewhere");
|
||||
case "PROFILE_LOCK_UNAVAILABLE":
|
||||
return t("backendErrors.profileLockUnavailable");
|
||||
case "NOT_TEAM_MEMBER":
|
||||
return t("backendErrors.notTeamMember");
|
||||
case "COOKIE_BOT_NOT_ENTITLED":
|
||||
|
||||
@@ -47,6 +47,19 @@ export interface RemoteSessionEnded {
|
||||
billed_seconds: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a profile cannot be opened on this computer right now.
|
||||
*
|
||||
* - `running`: a browser is open on the fleet holding this profile.
|
||||
* - `pending_sync`: a session has finished and what it wrote is still being
|
||||
* pulled down. Opening the local copy now would make the local files look
|
||||
* newer than the host's push, and the next sync would then upload the stale
|
||||
* copy over the session's work and delete the rest of it.
|
||||
*
|
||||
* Both states are temporary and neither is an error.
|
||||
*/
|
||||
export type RemoteHandoffState = "running" | "pending_sync";
|
||||
|
||||
/**
|
||||
* States a session cannot leave under its own steam.
|
||||
*
|
||||
@@ -83,8 +96,31 @@ export const REMOTE_SESSION_EVENTS = {
|
||||
snapshot: "remote-session-snapshot",
|
||||
/** Stream connectivity. Payload: `RemoteSessionStreamStatus`. */
|
||||
stream: "remote-session-stream",
|
||||
/**
|
||||
* The set of profiles that cannot be launched locally changed.
|
||||
* Payload: `Record<profileId, RemoteHandoffState>`.
|
||||
*/
|
||||
handoff: "remote-handoff-changed",
|
||||
} as const;
|
||||
|
||||
/** Which profiles are blocked from launching locally, and why. */
|
||||
export function getRemoteHandoffStates(): Promise<
|
||||
Record<string, RemoteHandoffState>
|
||||
> {
|
||||
return invoke<Record<string, RemoteHandoffState>>(
|
||||
"get_remote_handoff_states",
|
||||
);
|
||||
}
|
||||
|
||||
export function onRemoteHandoffChanged(
|
||||
handler: (states: Record<string, RemoteHandoffState>) => void,
|
||||
): Promise<UnlistenFn> {
|
||||
return listen<Record<string, RemoteHandoffState>>(
|
||||
REMOTE_SESSION_EVENTS.handoff,
|
||||
(event) => handler(event.payload),
|
||||
);
|
||||
}
|
||||
|
||||
export function listRemoteSessions(): Promise<RemoteSessionState[]> {
|
||||
return invoke<RemoteSessionState[]>("list_remote_sessions");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user