mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-07-15 08:57:24 +02:00
refactor: better error handling and prevention of creating ephemeral password protected profiles
This commit is contained in:
@@ -11,6 +11,7 @@ export type BackendErrorCode =
|
||||
| "PROFILE_NOT_PROTECTED"
|
||||
| "PROFILE_ALREADY_PROTECTED"
|
||||
| "PROFILE_RUNNING"
|
||||
| "PROFILE_EPHEMERAL"
|
||||
| "PROFILE_MISSING_SALT"
|
||||
| "PROFILE_LOCKED"
|
||||
| "INVALID_PROFILE_ID"
|
||||
@@ -74,6 +75,8 @@ export function translateBackendError(t: TFunction, err: unknown): string {
|
||||
return t("backendErrors.profileAlreadyProtected");
|
||||
case "PROFILE_RUNNING":
|
||||
return t("backendErrors.profileRunning");
|
||||
case "PROFILE_EPHEMERAL":
|
||||
return t("backendErrors.profileEphemeral");
|
||||
case "PROFILE_MISSING_SALT":
|
||||
return t("backendErrors.profileMissingSalt");
|
||||
case "PROFILE_LOCKED":
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
FaFire,
|
||||
FaFirefox,
|
||||
} from "react-icons/fa";
|
||||
import { LuLock } from "react-icons/lu";
|
||||
|
||||
/**
|
||||
* Map internal browser names to display names
|
||||
@@ -42,7 +43,13 @@ export function getBrowserIcon(browserType: string) {
|
||||
export function getProfileIcon(profile: {
|
||||
browser: string;
|
||||
ephemeral?: boolean;
|
||||
password_protected?: boolean;
|
||||
}) {
|
||||
// `password_protected` and `ephemeral` are mutually exclusive (the backend
|
||||
// rejects setting a password on an ephemeral profile), so the order here
|
||||
// doesn't matter — checking lock first only matters if the invariant is
|
||||
// ever violated, in which case showing the lock is the safer default.
|
||||
if (profile.password_protected) return LuLock;
|
||||
if (profile.ephemeral) return FaFire;
|
||||
return getBrowserIcon(profile.browser);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user