fix: keep desktop instance switching accessible

This commit is contained in:
tianma-if committed 2026-07-29 01:43:24 +08:00
1 parent 3e54ab97d1
commit 75b27fa42d
5 files changed
+36 -2

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@edgeever/desktop",
"version": "1.6.39",
"version": "1.6.40",
"desktopName": "EdgeEver",
"private": true,
"description": "Native EdgeEver desktop client",
+5
View File
@@ -106,6 +106,11 @@ export const LoginScreen = ({ configurationError, error, isSubmitting, onChangeI
<LockKeyhole className="h-4 w-4 mr-1" />
{isSubmitting ? t("login.submitting") : t("login.submit")}
</Button>
{onChangeInstance ? (
<Button className="h-10 w-full justify-center" type="button" variant="ghost" onClick={onChangeInstance}>
{t("login.desktopChangeInstance")}
</Button>
) : null}
</form>}
</section>
</main>
+28
View File
@@ -11,6 +11,10 @@ globalThis.window = {
apiBaseUrl: "",
setApiBaseUrl: async (value) => {
calls.push(["bridge:start", value]);
if (!value) {
calls.push(["bridge:complete", value]);
return value;
}
await new Promise((resolve) => {
completeSave = resolve;
});
@@ -39,6 +43,7 @@ const {
api,
cacheDesktopSession,
getCachedDesktopSession,
resetDesktopApiBaseUrl,
saveDesktopApiBaseUrl,
} = await import("./api.ts");
@@ -61,9 +66,32 @@ describe("desktop instance setup", () => {
expect(storage.get(DESKTOP_API_BASE_URL_STORAGE_KEY)).toBe("https://notes.example.com");
});
test("clears the saved instance and cached session before switching", async () => {
calls.length = 0;
storage.set(DESKTOP_API_BASE_URL_STORAGE_KEY, "https://notes.example.com");
cacheDesktopSession({
authRequired: true,
authenticated: true,
demoMode: false,
sessionToken: "old-instance-session",
user: { id: "user-1", username: "admin", displayName: null, role: "owner" },
});
resetDesktopApiBaseUrl();
await Promise.resolve();
expect(storage.has(DESKTOP_API_BASE_URL_STORAGE_KEY)).toBe(false);
expect(getCachedDesktopSession()).toBeNull();
expect(calls.slice(-2)).toEqual([
["bridge:start", ""],
["bridge:complete", ""],
]);
});
test("uses the desktop session token and stops network retries after a 401", async () => {
calls.length = 0;
events.length = 0;
storage.set(DESKTOP_API_BASE_URL_STORAGE_KEY, "https://notes.example.com");
cacheDesktopSession({
authRequired: true,
authenticated: true,
+1
View File
@@ -123,6 +123,7 @@ export const saveDesktopApiBaseUrl = async (value: string) => {
export const resetDesktopApiBaseUrl = () => {
if (typeof window === "undefined" || !window.edgeeverDesktop?.isAvailable) return;
clearCachedDesktopSession();
window.localStorage.removeItem(DESKTOP_API_BASE_URL_STORAGE_KEY);
void window.edgeeverDesktop.setApiBaseUrl("");
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "edgeever",
"version": "1.6.39",
"version": "1.6.40",
"private": true,
"type": "module",
"workspaces": [