feat(desktop): Electron shell M2 — embedded server, desktop login, instance lock (#173)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Yaowei ZhengandClaude Fable 5 authored and GitHub committed 2026-08-04 16:57:28 +08:00
1 parent 045ac250e0
commit 7015fb0153
35 files changed
+1477 -112

No files matched your search

+12 -2
View File
@@ -28,15 +28,25 @@ export function meRoutes(deps: AppDeps): Hono<AppEnv> {
return c.json({
user: toUserInfo(c.var.user),
previewIsolated: target !== null,
desktopMode: deps.desktop !== null,
sessionVia: c.var.sessionVia,
} satisfies MeResponse);
});
// Self-service password change (user settings): validates the old password; on success, the initial-password prompt disappears from GET /api/me.
// Desktop sessions may omit oldPassword: the seed password of a desktop-created root is
// random and never shown, so its holder has nothing to type — the shell's redeemed
// token already proved machine ownership (see design § "桌面端原型 · 桌面登录").
app.put("/password", async (c) => {
const body = await readJson(c);
const oldPassword = requireString(body, "oldPassword", { label: "oldPassword" });
const newPassword = requireString(body, "newPassword", { label: "newPassword" });
await deps.authService.changePassword(c.var.user.userId, oldPassword, newPassword);
const desktopSession = deps.desktop !== null && c.var.sessionVia === "desktop";
if (desktopSession && body.oldPassword === undefined) {
await deps.authService.setPasswordDesktop(c.var.user.userId, newPassword);
} else {
const oldPassword = requireString(body, "oldPassword", { label: "oldPassword" });
await deps.authService.changePassword(c.var.user.userId, oldPassword, newPassword);
}
return c.body(null, 204);
});