Backup before continuing from Codex 5.2 session - User storage, compaction suggestions, streaming improvements
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
import { BrowserWindow, dialog, ipcMain, type OpenDialogOptions } from "electron"
|
||||
import path from "path"
|
||||
import type { CliProcessManager, CliStatus } from "./process-manager"
|
||||
import {
|
||||
listUsers,
|
||||
createUser,
|
||||
updateUser,
|
||||
deleteUser,
|
||||
verifyPassword,
|
||||
setActiveUser,
|
||||
createGuestUser,
|
||||
getActiveUser,
|
||||
getUserDataRoot,
|
||||
} from "./user-store"
|
||||
|
||||
interface DialogOpenRequest {
|
||||
mode: "directory" | "file"
|
||||
@@ -40,6 +52,41 @@ export function setupCliIPC(mainWindow: BrowserWindow, cliManager: CliProcessMan
|
||||
return cliManager.start({ dev: devMode })
|
||||
})
|
||||
|
||||
ipcMain.handle("users:list", async () => listUsers())
|
||||
ipcMain.handle("users:active", async () => getActiveUser())
|
||||
ipcMain.handle("users:create", async (_, payload: { name: string; password: string }) => {
|
||||
const user = createUser(payload.name, payload.password)
|
||||
return user
|
||||
})
|
||||
ipcMain.handle("users:update", async (_, payload: { id: string; name?: string; password?: string }) => {
|
||||
const user = updateUser(payload.id, { name: payload.name, password: payload.password })
|
||||
return user
|
||||
})
|
||||
ipcMain.handle("users:delete", async (_, payload: { id: string }) => {
|
||||
deleteUser(payload.id)
|
||||
return { success: true }
|
||||
})
|
||||
ipcMain.handle("users:createGuest", async () => {
|
||||
const user = createGuestUser()
|
||||
return user
|
||||
})
|
||||
ipcMain.handle("users:login", async (_, payload: { id: string; password?: string }) => {
|
||||
const ok = verifyPassword(payload.id, payload.password ?? "")
|
||||
if (!ok) {
|
||||
return { success: false }
|
||||
}
|
||||
const user = setActiveUser(payload.id)
|
||||
const root = getUserDataRoot(user.id)
|
||||
cliManager.setUserEnv({
|
||||
CODENOMAD_USER_DIR: root,
|
||||
CLI_CONFIG: path.join(root, "config.json"),
|
||||
})
|
||||
await cliManager.stop()
|
||||
const devMode = process.env.NODE_ENV === "development"
|
||||
await cliManager.start({ dev: devMode })
|
||||
return { success: true, user }
|
||||
})
|
||||
|
||||
ipcMain.handle("dialog:open", async (_, request: DialogOpenRequest): Promise<DialogOpenResult> => {
|
||||
const properties: OpenDialogOptions["properties"] =
|
||||
request.mode === "directory" ? ["openDirectory", "createDirectory"] : ["openFile"]
|
||||
|
||||
Reference in New Issue
Block a user