Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: combine desktop connection and login form

tianma-ifcf08b5dc9d61
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 0a2dbada..b80d7160 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -1,6 +1,6 @@
{
"name": "@edgeever/desktop",
- "version": "1.6.40",
+ "version": "1.6.41",
"desktopName": "EdgeEver",
"private": true,
"description": "Native EdgeEver desktop client",
diff --git a/apps/mobile/app.json b/apps/mobile/app.json
index 24620903..b629a1e2 100644
--- a/apps/mobile/app.json
+++ b/apps/mobile/app.json
@@ -3,7 +3,7 @@
"name": "EdgeEver",
"slug": "edgeever",
"scheme": "edgeever",
- "version": "1.6.39",
+ "version": "1.6.41",
"runtimeVersion": {
"policy": "appVersion"
},
@@ -28,7 +28,7 @@
},
"android": {
"package": "org.edgeever.mobile",
- "versionCode": 49,
+ "versionCode": 50,
"adaptiveIcon": {
"backgroundColor": "#d1fae5",
"backgroundImage": "./assets/icon.png",
diff --git a/apps/web/src/app/App.tsx b/apps/web/src/app/App.tsx
index 0e90f9fa..2f7f050d 100644
--- a/apps/web/src/app/App.tsx
+++ b/apps/web/src/app/App.tsx
@@ -1,4 +1,4 @@
-import { lazy, Suspense, useEffect, useState, type FormEvent } from "react";
+import { lazy, Suspense, useEffect, useState } from "react";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { Navigate, Route, Routes, useNavigate } from "react-router";
import { useTranslation } from "react-i18next";
@@ -7,7 +7,6 @@ import { ReleaseUpdateNotice } from "@/components/ReleaseUpdateNotice";
import { PwaInstallProvider } from "@/components/PwaInstallContext";
import { PwaIosPrompt } from "@/components/PwaIosPrompt";
import { Button } from "@/components/ui/button";
-import { Input } from "@/components/ui/input";
import {
api,
ApiRequestError,
@@ -15,8 +14,6 @@ import {
clearCachedDesktopSession,
getConfiguredDesktopApiBaseUrl,
getCachedDesktopSession,
- isDesktopInstanceConfigurationRequired,
- resetDesktopApiBaseUrl,
saveDesktopApiBaseUrl,
} from "@/lib/api";
import { EVERNOTE_MIGRATION_PATH } from "@/lib/routes";
@@ -38,53 +35,6 @@ const AuthLoadingScreen = ({ title = "EdgeEver", detail }: { title?: string; det
</div>
);
-const DesktopInstanceSetup = ({ onConfigured }: { onConfigured: () => void }) => {
- const { t } = useTranslation();
- const [value, setValue] = useState("");
- const [error, setError] = useState<string | null>(null);
- const [isSaving, setIsSaving] = useState(false);
-
- const save = async (event: FormEvent<HTMLFormElement>) => {
- event.preventDefault();
- setError(null);
- setIsSaving(true);
- try {
- await saveDesktopApiBaseUrl(value);
- onConfigured();
- } catch {
- setError(t("login.desktopInstanceUrlInvalid"));
- setIsSaving(false);
- }
- };
-
- return (
- <main className="flex h-[100dvh] items-center justify-center bg-gradient-to-tr from-emerald-50/70 via-emerald-50 to-emerald-100 px-4 py-8 text-slate-950">
- <section className="w-full max-w-[440px] rounded-2xl border border-emerald-500/15 bg-white/95 p-8 shadow-[0_20px_50px_rgb(var(--brand-green-rgb)/0.08)]">
- <h1 className="text-xl font-bold tracking-tight text-slate-900">{t("login.desktopInstanceTitle")}</h1>
- <form className="mt-6 space-y-4" onSubmit={save}>
- <label className="block">
- <span className="mb-2 block text-sm font-semibold text-slate-700">{t("login.desktopInstanceUrl")}</span>
- <Input
- autoFocus
- className="h-11 rounded-lg bg-slate-50/50 px-3.5 focus-visible:bg-white focus-visible:ring-4 focus-visible:ring-emerald-500/10"
- placeholder="https://notes.example.com"
- value={value}
- onChange={(event) => {
- setValue(event.target.value);
- setError(null);
- }}
- />
- </label>
- {error && <p className="text-sm text-rose-700">{error}</p>}
- <Button className="h-11 w-full justify-center rounded-lg bg-emerald-500 font-semibold text-white transition hover:bg-emerald-600" disabled={isSaving} type="submit" variant="solid">
- {t("login.desktopInstanceContinue")}
- </Button>
- </form>
- </section>
- </main>
- );
-};
-
const EvernoteMigrationRoute = () => {
const navigate = useNavigate();
@@ -111,6 +61,7 @@ const AuthenticatedWorkspace = () => {
const [desktopScopeReady, setDesktopScopeReady] = useState(() => !desktopBridge?.isAvailable);
const [desktopScopeError, setDesktopScopeError] = useState<Error | null>(null);
const [desktopScopeAttempt, setDesktopScopeAttempt] = useState(0);
+ const configuredDesktopApiBaseUrl = getConfiguredDesktopApiBaseUrl();
const sessionQuery = useQuery({
queryKey: ["auth", "session"],
@@ -125,6 +76,7 @@ const AuthenticatedWorkspace = () => {
throw error;
}
},
+ enabled: !desktopBridge?.isAvailable || Boolean(configuredDesktopApiBaseUrl),
retry: false,
});
@@ -150,7 +102,16 @@ const AuthenticatedWorkspace = () => {
}, [desktopAccountId, desktopBridge, desktopScopeAttempt, sessionQuery.isLoading]);
const loginMutation = useMutation({
- mutationFn: api.login,
+ mutationFn: async (payload: { instanceUrl?: string; username: string; password: string }) => {
+ if (desktopBridge?.isAvailable && payload.instanceUrl !== undefined) {
+ try {
+ await saveDesktopApiBaseUrl(payload.instanceUrl);
+ } catch {
+ throw new Error(t("login.desktopInstanceUrlInvalid"));
+ }
+ }
+ return api.login({ username: payload.username, password: payload.password });
+ },
onSuccess: (session) => {
cacheDesktopSession(session);
queryClient.clear();
@@ -235,11 +196,8 @@ const AuthenticatedWorkspace = () => {
<LoginScreen
configurationError={configurationError}
error={loginError}
+ instanceUrl={desktopBridge?.isAvailable ? configuredDesktopApiBaseUrl : undefined}
isSubmitting={loginMutation.isPending}
- onChangeInstance={desktopBridge?.isAvailable ? () => {
- resetDesktopApiBaseUrl();
- window.location.reload();
- } : undefined}
onSubmit={(payload) => loginMutation.mutate(payload)}
/>
</Suspense>
@@ -263,20 +221,12 @@ const AuthenticatedWorkspace = () => {
};
export const App = () => {
- const [desktopInstanceConfigured, setDesktopInstanceConfigured] = useState(
- () => !isDesktopInstanceConfigurationRequired(),
- );
-
useEffect(() => {
const bridge = window.edgeeverDesktop;
const baseUrl = getConfiguredDesktopApiBaseUrl();
if (bridge?.isAvailable && baseUrl) void bridge.setApiBaseUrl(baseUrl);
}, []);
- if (!desktopInstanceConfigured) {
- return <DesktopInstanceSetup onConfigured={() => setDesktopInstanceConfigured(true)} />;
- }
-
return (
<PwaInstallProvider>
<Routes>
diff --git a/apps/web/src/components/LoginScreen.tsx b/apps/web/src/components/LoginScreen.tsx
index 2ac689b1..d746e76b 100644
--- a/apps/web/src/components/LoginScreen.tsx
+++ b/apps/web/src/components/LoginScreen.tsx
@@ -8,9 +8,9 @@ import { Input } from "@/components/ui/input";
interface LoginScreenProps {
configurationError: string | null;
error: string | null;
+ instanceUrl?: string;
isSubmitting: boolean;
- onChangeInstance?: () => void;
- onSubmit: (payload: { username: string; password: string }) => void;
+ onSubmit: (payload: { instanceUrl?: string; username: string; password: string }) => void;
}
const DEMO_LOGIN_CREDENTIALS = {
@@ -25,19 +25,24 @@ const getDefaultLoginCredentials = () => {
return isDemoHost ? DEMO_LOGIN_CREDENTIALS : { username: "admin", password: "" };
};
-export const LoginScreen = ({ configurationError, error, isSubmitting, onChangeInstance, onSubmit }: LoginScreenProps) => {
+export const LoginScreen = ({ configurationError, error, instanceUrl: initialInstanceUrl, isSubmitting, onSubmit }: LoginScreenProps) => {
const { t } = useTranslation();
+ const [instanceUrl, setInstanceUrl] = useState(initialInstanceUrl ?? "");
const [username, setUsername] = useState(() => getDefaultLoginCredentials().username);
const [password, setPassword] = useState(() => getDefaultLoginCredentials().password);
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
- if (!username.trim() || !password) {
+ if ((initialInstanceUrl !== undefined && !instanceUrl.trim()) || !username.trim() || !password) {
return;
}
- onSubmit({ username: username.trim(), password });
+ onSubmit({
+ ...(initialInstanceUrl !== undefined ? { instanceUrl: instanceUrl.trim() } : {}),
+ username: username.trim(),
+ password,
+ });
};
return (
@@ -57,23 +62,34 @@ export const LoginScreen = ({ configurationError, error, isSubmitting, onChangeI
</div>
</div>
- {configurationError ? (
- <div className="space-y-3">
+ <form className="space-y-5" onSubmit={handleSubmit}>
+ {configurationError ? (
<div className="rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm font-medium leading-6 text-amber-900">
{configurationError}
</div>
- {onChangeInstance ? (
- <Button className="h-10 w-full justify-center" type="button" variant="outline" onClick={onChangeInstance}>
- {t("login.desktopChangeInstance")}
- </Button>
- ) : null}
- </div>
- ) : <form className="space-y-5" onSubmit={handleSubmit}>
+ ) : null}
+
+ {initialInstanceUrl !== undefined ? (
+ <label className="block">
+ <span className="mb-2 block text-sm font-semibold text-slate-700">{t("login.desktopInstanceUrl")}</span>
+ <Input
+ autoComplete="url"
+ className="h-11 rounded-lg bg-slate-50/50 px-3.5 focus-visible:bg-white focus-visible:ring-4 focus-visible:ring-emerald-500/10"
+ placeholder="https://notes.example.com"
+ required
+ type="url"
+ value={instanceUrl}
+ onChange={(event) => setInstanceUrl(event.target.value)}
+ />
+ </label>
+ ) : null}
+
<label className="block">
<span className="mb-2 block text-sm font-semibold text-slate-700">{t("login.username")}</span>
<Input
autoComplete="username"
className="h-11 rounded-lg bg-slate-50/50 px-3.5 focus-visible:bg-white focus-visible:ring-4 focus-visible:ring-emerald-500/10"
+ required
value={username}
onChange={(event) => setUsername(event.target.value)}
/>
@@ -84,6 +100,7 @@ export const LoginScreen = ({ configurationError, error, isSubmitting, onChangeI
<Input
autoComplete="current-password"
className="h-11 rounded-lg bg-slate-50/50 px-3.5 focus-visible:bg-white focus-visible:ring-4 focus-visible:ring-emerald-500/10"
+ required
type="password"
value={password}
onChange={(event) => setPassword(event.target.value)}
@@ -106,12 +123,7 @@ 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>}
+ </form>
</section>
</main>
);
diff --git a/apps/web/src/lib/api.test.mjs b/apps/web/src/lib/api.test.mjs
index 779c4d3c..53bd2751 100644
--- a/apps/web/src/lib/api.test.mjs
+++ b/apps/web/src/lib/api.test.mjs
@@ -42,8 +42,8 @@ const {
DESKTOP_API_BASE_URL_STORAGE_KEY,
api,
cacheDesktopSession,
+ getConfiguredDesktopApiBaseUrl,
getCachedDesktopSession,
- resetDesktopApiBaseUrl,
saveDesktopApiBaseUrl,
} = await import("./api.ts");
@@ -66,8 +66,9 @@ 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 () => {
+ test("clears the cached session when the login form changes instances", async () => {
calls.length = 0;
+ window.edgeeverDesktop.apiBaseUrl = "https://notes.example.com";
storage.set(DESKTOP_API_BASE_URL_STORAGE_KEY, "https://notes.example.com");
cacheDesktopSession({
authRequired: true,
@@ -76,16 +77,21 @@ describe("desktop instance setup", () => {
sessionToken: "old-instance-session",
user: { id: "user-1", username: "admin", displayName: null, role: "owner" },
});
+ calls.length = 0;
- resetDesktopApiBaseUrl();
+ const saving = saveDesktopApiBaseUrl("https://other.example.com");
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", ""],
+ expect(calls).toEqual([
+ ["bridge:start", "https://other.example.com"],
]);
+
+ completeSave();
+ await expect(saving).resolves.toBe("https://other.example.com");
+ expect(storage.get(DESKTOP_API_BASE_URL_STORAGE_KEY)).toBe("https://other.example.com");
+ expect(getConfiguredDesktopApiBaseUrl()).toBe("https://other.example.com");
+ window.edgeeverDesktop.apiBaseUrl = "";
});
test("uses the desktop session token and stops network retries after a 401", async () => {
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index 916dbbe7..30631f9e 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -93,21 +93,15 @@ export const clearCachedDesktopSession = () => {
export const getConfiguredDesktopApiBaseUrl = () => {
if (typeof window === "undefined") return "";
- const bridgeUrl = (window.edgeeverDesktop?.apiBaseUrl ?? "").trim();
- if (bridgeUrl) return bridgeUrl.replace(/\/$/, "");
try {
- return (window.localStorage.getItem(DESKTOP_API_BASE_URL_STORAGE_KEY) ?? "").trim().replace(/\/$/, "");
- } catch {
- return "";
- }
-};
+ const savedUrl = (window.localStorage.getItem(DESKTOP_API_BASE_URL_STORAGE_KEY) ?? "").trim();
+ if (savedUrl) return savedUrl.replace(/\/$/, "");
+ } catch {}
-export const isDesktopInstanceConfigurationRequired = () =>
- typeof window !== "undefined" &&
- Boolean(window.edgeeverDesktop?.isAvailable) &&
- window.location.protocol === "file:" &&
- !getConfiguredDesktopApiBaseUrl();
+ const bridgeUrl = (window.edgeeverDesktop?.apiBaseUrl ?? "").trim();
+ return bridgeUrl.replace(/\/$/, "");
+};
export const saveDesktopApiBaseUrl = async (value: string) => {
const normalized = value.trim().replace(/\/$/, "");
@@ -116,18 +110,14 @@ export const saveDesktopApiBaseUrl = async (value: string) => {
throw new Error("Desktop instance URL must use http or https");
}
+ if (getConfiguredDesktopApiBaseUrl() !== normalized) {
+ clearCachedDesktopSession();
+ }
await window.edgeeverDesktop?.setApiBaseUrl(normalized);
window.localStorage.setItem(DESKTOP_API_BASE_URL_STORAGE_KEY, normalized);
return normalized;
};
-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("");
-};
-
const createWebDeviceId = () => {
const uuid = globalThis.crypto?.randomUUID?.();
return uuid
diff --git a/package.json b/package.json
index d520ab3b..76c8989c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "edgeever",
- "version": "1.6.40",
+ "version": "1.6.41",
"private": true,
"type": "module",
"workspaces": [