From 9a8280ded4d937ffd6951bea31b3ff7cb30600fe Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 17 Mar 2026 11:18:48 +0800 Subject: [PATCH] feat(cli): switch desktop sync to folocli --- apps/cli/package.json | 22 +- apps/cli/skill.md | 11 +- apps/cli/src/browser-login.ts | 2 +- apps/cli/src/cli.e2e.test.ts | 4 +- apps/cli/src/client.ts | 2 +- apps/cli/src/commands/auth.ts | 180 ++++++++------ apps/desktop/forge.config.cts | 5 +- .../layer/main/src/ipc/services/auth.ts | 4 +- .../layer/main/src/ipc/services/cli.ts | 235 ++++-------------- .../layer/main/src/lib/cli-session-sync.ts | 82 +++++- apps/desktop/layer/main/src/manager/app.ts | 2 +- .../src/modules/settings/tabs/cli.tsx | 77 ++++-- .../src/pages/settings/(settings)/cli.tsx | 3 +- apps/desktop/package.json | 3 +- apps/desktop/scripts/prepare-cli.ts | 27 -- locales/settings/en.json | 28 ++- locales/settings/fr-FR.json | 28 ++- locales/settings/ja.json | 28 ++- locales/settings/zh-CN.json | 28 ++- locales/settings/zh-TW.json | 28 ++- 20 files changed, 398 insertions(+), 401 deletions(-) delete mode 100644 apps/desktop/scripts/prepare-cli.ts diff --git a/apps/cli/package.json b/apps/cli/package.json index a51130e24..89d25b905 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -1,9 +1,22 @@ { - "name": "@follow/cli", + "name": "folocli", "type": "module", "version": "0.1.0", - "private": true, - "description": "Folo CLI for AI agents and power users", + "description": "Folo CLI for terminal workflows and automation", + "author": "Folo Team", + "license": "AGPL-3.0-only", + "homepage": "https://github.com/RSSNext/Folo", + "repository": { + "type": "git", + "url": "git+https://github.com/RSSNext/Folo.git" + }, + "keywords": [ + "folo", + "rss", + "reader", + "cli", + "automation" + ], "bin": { "folo": "./dist/index.js" }, @@ -11,6 +24,9 @@ "dist", "skill.md" ], + "engines": { + "node": ">=18" + }, "scripts": { "build": "tsup --config tsup.config.ts && chmod +x dist/index.js", "dev": "tsx src/index.ts", diff --git a/apps/cli/skill.md b/apps/cli/skill.md index 1aa187a64..ecca568e9 100644 --- a/apps/cli/skill.md +++ b/apps/cli/skill.md @@ -16,8 +16,8 @@ Use this skill when a user asks to: 1. Folo CLI is installed and executable as `folo`. 2. Authentication is configured: - - `folo auth login` (recommended, opens browser and auto-logins) - - or `folo auth login --token ` + - `folo login` (recommended, opens browser and auto-logins) + - or `folo login --token ` - or set `FOLO_TOKEN=` ## Output Contract @@ -114,6 +114,9 @@ Loop until `hasNext` is `false`: ## Command Reference +- `folo login [--timeout ] [--token ]` +- `folo logout` +- `folo whoami` - `folo auth login [--timeout ] [--token ]` - `folo auth logout` - `folo auth whoami` @@ -164,8 +167,8 @@ Loop until `hasNext` is `false`: ## Error Recovery - `UNAUTHORIZED` - - Re-login: `folo auth login` - - or `folo auth login --token ` + - Re-login: `folo login` + - or `folo login --token ` - Or set `FOLO_TOKEN` - `HTTP_4xx` / `HTTP_5xx` - Retry with `--verbose` for request details diff --git a/apps/cli/src/browser-login.ts b/apps/cli/src/browser-login.ts index 2a14e232a..7ffd07387 100644 --- a/apps/cli/src/browser-login.ts +++ b/apps/cli/src/browser-login.ts @@ -210,7 +210,7 @@ export const loginWithBrowser = async ( reject( new CLIError( "TIMEOUT", - "Timed out waiting for browser login. Please run `folo auth login` again.", + "Timed out waiting for browser login. Please run `folo login` again.", ), ) }) diff --git a/apps/cli/src/cli.e2e.test.ts b/apps/cli/src/cli.e2e.test.ts index fb486d52f..df16a47dd 100644 --- a/apps/cli/src/cli.e2e.test.ts +++ b/apps/cli/src/cli.e2e.test.ts @@ -10,7 +10,7 @@ import { describe, expect, it } from "vitest" const execFileAsync = promisify(execFile) const cliPath = resolve(process.cwd(), "dist/index.js") const testToken = process.env.FOLO_TEST_TOKEN -const isolatedHome = mkdtempSync(resolve(tmpdir(), "folo-cli-test-")) +const isolatedHome = mkdtempSync(resolve(tmpdir(), "folocli-test-")) type CLIExecution = { code: number @@ -64,7 +64,7 @@ describe("cli e2e", () => { }) it.runIf(Boolean(testToken))("can fetch session with test token", async () => { - const result = await runCLI(["--token", testToken!, "auth", "whoami"]) + const result = await runCLI(["--token", testToken!, "whoami"]) expect(result.code).toBe(0) const payload = JSON.parse(result.stdout) as { diff --git a/apps/cli/src/client.ts b/apps/cli/src/client.ts index 2f8cb7965..2cfa020d0 100644 --- a/apps/cli/src/client.ts +++ b/apps/cli/src/client.ts @@ -82,7 +82,7 @@ export const createCommandContext = async ( if (requireAuth && !token) { throw new CLIError( "UNAUTHORIZED", - "Missing token. Run `folo auth login` (browser sign-in) or set FOLO_TOKEN.", + "Missing token. Run `folo login` (browser sign-in) or set FOLO_TOKEN.", ) } diff --git a/apps/cli/src/commands/auth.ts b/apps/cli/src/commands/auth.ts index 872b88c81..19c92ad15 100644 --- a/apps/cli/src/commands/auth.ts +++ b/apps/cli/src/commands/auth.ts @@ -12,92 +12,110 @@ interface AuthLoginOptions { timeout?: number } -export const registerAuthCommand = (program: Command) => { - const authCommand = program.command("auth").description("Authentication commands") +const runLoginAction = async function (this: Command, options: AuthLoginOptions) { + await runCommand( + this, + async ({ client, options: globalOptions }) => { + let token = options.token ?? getGlobalOptions(this).token + if (!token) { + const timeoutMs = (options.timeout ?? 180) * 1000 + const browserLogin = await loginWithBrowser({ + apiUrl: globalOptions.apiUrl, + timeoutMs, + onStatus: (message) => { + console.error(`[auth] ${message}`) + }, + }) + token = browserLogin.token + } - authCommand - .command("login") - .description("Sign in via browser (or save a provided token) and verify authentication") + client.setAuthToken(token) + const session = await client.api.auth.getSession() + + if (!session.user || !session.session) { + throw new CLIError("UNAUTHORIZED", "Token is invalid or expired.") + } + + await updateConfig({ + token, + apiUrl: globalOptions.apiUrl, + }) + + return { + message: "Login successful.", + configPath: getConfigPath(), + user: session.user, + } + }, + { requireAuth: false }, + ) +} + +const runLogoutAction = async function (this: Command) { + await runCommand( + this, + async () => { + await clearToken() + return { + message: "Logged out.", + configPath: getConfigPath(), + } + }, + { requireAuth: false }, + ) +} + +const runWhoamiAction = async function (this: Command) { + await runCommand(this, async ({ client }) => { + const session = await client.api.auth.getSession() + if (!session.user || !session.session) { + throw new CLIError("UNAUTHORIZED", "Token is invalid or expired.") + } + + return { + user: session.user, + session: session.session, + role: session.role, + roleEndAt: session.roleEndAt ?? null, + feedSubscriptionLimit: session.feedSubscriptionLimit, + rsshubSubscriptionLimit: session.rsshubSubscriptionLimit, + } + }) +} + +const registerLoginCommand = (program: Command, name: string, description: string) => { + program + .command(name) + .description(description) .option("--token ", "Session token from Folo") .option( "--timeout ", "Browser login timeout in seconds (default: 180)", parsePositiveInt, ) - .action(async function (this: Command, options: AuthLoginOptions) { - await runCommand( - this, - async ({ client, options: globalOptions }) => { - let token = options.token ?? getGlobalOptions(this).token - if (!token) { - const timeoutMs = (options.timeout ?? 180) * 1000 - const browserLogin = await loginWithBrowser({ - apiUrl: globalOptions.apiUrl, - timeoutMs, - onStatus: (message) => { - console.error(`[auth] ${message}`) - }, - }) - token = browserLogin.token - } - - client.setAuthToken(token) - const session = await client.api.auth.getSession() - - if (!session.user || !session.session) { - throw new CLIError("UNAUTHORIZED", "Token is invalid or expired.") - } - - await updateConfig({ - token, - apiUrl: globalOptions.apiUrl, - }) - - return { - message: "Login successful.", - configPath: getConfigPath(), - user: session.user, - } - }, - { requireAuth: false }, - ) - }) - - authCommand - .command("logout") - .description("Clear stored token") - .action(async function (this: Command) { - await runCommand( - this, - async () => { - await clearToken() - return { - message: "Logged out.", - configPath: getConfigPath(), - } - }, - { requireAuth: false }, - ) - }) - - authCommand - .command("whoami") - .description("Show current session user") - .action(async function (this: Command) { - await runCommand(this, async ({ client }) => { - const session = await client.api.auth.getSession() - if (!session.user || !session.session) { - throw new CLIError("UNAUTHORIZED", "Token is invalid or expired.") - } - - return { - user: session.user, - session: session.session, - role: session.role, - roleEndAt: session.roleEndAt ?? null, - feedSubscriptionLimit: session.feedSubscriptionLimit, - rsshubSubscriptionLimit: session.rsshubSubscriptionLimit, - } - }) - }) + .action(runLoginAction) +} + +const registerLogoutCommand = (program: Command, name: string, description: string) => { + program.command(name).description(description).action(runLogoutAction) +} + +const registerWhoamiCommand = (program: Command, name: string, description: string) => { + program.command(name).description(description).action(runWhoamiAction) +} + +export const registerAuthCommand = (program: Command) => { + const authCommand = program.command("auth").description("Authentication commands") + + registerLoginCommand( + authCommand, + "login", + "Sign in via browser (or save a provided token) and verify authentication", + ) + registerLogoutCommand(authCommand, "logout", "Clear stored token") + registerWhoamiCommand(authCommand, "whoami", "Show current session user") + + registerLoginCommand(program, "login", "Sign in and store a CLI session") + registerLogoutCommand(program, "logout", "Clear the stored CLI session") + registerWhoamiCommand(program, "whoami", "Show the current CLI session user") } diff --git a/apps/desktop/forge.config.cts b/apps/desktop/forge.config.cts index 688a499c1..8237ffa68 100644 --- a/apps/desktop/forge.config.cts +++ b/apps/desktop/forge.config.cts @@ -102,10 +102,7 @@ const config: ForgeConfig = { buildVersion: process.env.BUILD_VERSION || undefined, appBundleId: "is.follow", icon: isStaging ? "resources/icon-staging" : "resources/icon", - extraResource: [ - "./resources/app-update.yml", - ...(fs.existsSync("./resources/cli") ? ["./resources/cli"] : []), - ], + extraResource: ["./resources/app-update.yml"], protocols: [ { name: "Folo", diff --git a/apps/desktop/layer/main/src/ipc/services/auth.ts b/apps/desktop/layer/main/src/ipc/services/auth.ts index 5426fa08b..33896a3f9 100644 --- a/apps/desktop/layer/main/src/ipc/services/auth.ts +++ b/apps/desktop/layer/main/src/ipc/services/auth.ts @@ -109,7 +109,7 @@ export class AuthService extends IpcService { async sessionChanged(_context: IpcContext): Promise { await updateNotificationsToken() - // Sync session token to CLI config + // Sync the current desktop session to the npm CLI login. const token = await getSessionTokenFromCookies() await syncSessionToCliConfig(token).catch((err) => { logger.error("Failed to sync session to CLI config:", err) @@ -120,7 +120,7 @@ export class AuthService extends IpcService { async signOut(_context: IpcContext): Promise { await deleteNotificationsToken() - // Clear CLI config token on sign out + // Clear the synced CLI login on sign out. await syncSessionToCliConfig().catch((err) => { logger.error("Failed to clear CLI config token:", err) }) diff --git a/apps/desktop/layer/main/src/ipc/services/cli.ts b/apps/desktop/layer/main/src/ipc/services/cli.ts index 4c5656731..feef0aa8d 100644 --- a/apps/desktop/layer/main/src/ipc/services/cli.ts +++ b/apps/desktop/layer/main/src/ipc/services/cli.ts @@ -1,51 +1,25 @@ -import { execSync } from "node:child_process" -import { existsSync, lstatSync, readlinkSync } from "node:fs" -import { unlink, writeFile } from "node:fs/promises" -import { tmpdir } from "node:os" - -import { app } from "electron" import type { IpcContext } from "electron-ipc-decorator" import { IpcMethod, IpcService } from "electron-ipc-decorator" -import path from "pathe" -import { logger } from "../../logger" - -const CLI_BINARY_NAME = "folo" - -const getDefaultInstallDir = (): string => { - switch (process.platform) { - case "win32": { - return path.join(process.env.LOCALAPPDATA || "", "Folo", "bin") - } - default: { - return "/usr/local/bin" - } - } -} - -const getCliSourcePath = (): string => { - if (app.isPackaged) { - return path.join(process.resourcesPath, "cli", "index.js") - } - // In dev, read from the cli workspace directly - return path.resolve(app.getAppPath(), "../../cli/dist/index.js") -} - -const getCliInstallPath = (): string => { - return path.join(getDefaultInstallDir(), CLI_BINARY_NAME) -} - -/** Check whether the CLI is present at the given path (also checks .cmd on Windows). */ -const cliExistsAt = (installPath: string): boolean => { - if (existsSync(installPath)) return true - if (process.platform === "win32" && existsSync(`${installPath}.cmd`)) return true - return false -} +import { + CLI_NPM_PACKAGE_NAME, + getCliConfigPath, + getCliInstallCommand, + getCliLoginCommand, + getSessionTokenFromCookies, + isCliRunnerAvailable, + readCliConfig, + syncSessionToCliConfig, +} from "../../lib/cli-session-sync" export interface CliInstallStatus { - installed: boolean - installPath: string | null - cliSourceAvailable: boolean + connected: boolean + configPath: string + hasDesktopSession: boolean + installCommand: string + loginCommand: string + npxAvailable: boolean + packageName: string } export class CliService extends IpcService { @@ -53,169 +27,54 @@ export class CliService extends IpcService { @IpcMethod() async getInstallStatus(_context: IpcContext): Promise { - const installPath = getCliInstallPath() - const cliSourcePath = getCliSourcePath() - const cliSourceAvailable = existsSync(cliSourcePath) + const [config, npxAvailable, desktopToken] = await Promise.all([ + readCliConfig(), + isCliRunnerAvailable(), + getSessionTokenFromCookies(), + ]) - try { - if (!cliExistsAt(installPath)) { - return { installed: false, installPath: null, cliSourceAvailable } - } - - if (existsSync(installPath)) { - const stats = lstatSync(installPath) - if (stats.isSymbolicLink()) { - const target = readlinkSync(installPath) - const isOurs = target.includes("Folo") || target.includes("cli/index.js") - return { installed: isOurs, installPath, cliSourceAvailable } - } - } - - // Exists as a regular file (wrapper script or .cmd on Windows) - return { installed: true, installPath, cliSourceAvailable } - } catch { - return { installed: false, installPath: null, cliSourceAvailable } + return { + connected: Boolean(config.token), + configPath: getCliConfigPath(), + hasDesktopSession: Boolean(desktopToken), + installCommand: getCliInstallCommand(), + loginCommand: getCliLoginCommand(), + npxAvailable, + packageName: CLI_NPM_PACKAGE_NAME, } } @IpcMethod() async installCli(_context: IpcContext): Promise<{ success: boolean; error?: string }> { - const cliSource = getCliSourcePath() - if (!existsSync(cliSource)) { - return { success: false, error: "CLI bundle not found in app resources" } - } - - const installPath = getCliInstallPath() - const wrapperContent = `#!/bin/sh\nexec /usr/bin/env node "${cliSource}" "$@"\n` - - if (process.platform === "win32") { - return this.installCliWindows(cliSource, installPath) - } - try { - // Try without elevated permissions first - await writeFile(installPath, wrapperContent, { mode: 0o755 }) - logger.info(`CLI installed at ${installPath}`) + if (!(await isCliRunnerAvailable())) { + return { success: false, error: "npx is not available. Install Node.js and npm first." } + } + + const token = await getSessionTokenFromCookies() + if (!token) { + return { success: false, error: "Sign in to Folo Desktop first." } + } + + await syncSessionToCliConfig(token) return { success: true } - } catch { - // Write to a temp file first, then use admin privileges to copy it. - // This avoids shell-expansion issues with $@ in the wrapper content. - const tmpFile = path.join(tmpdir(), `folo-cli-wrapper-${Date.now()}`) - try { - await writeFile(tmpFile, wrapperContent, { mode: 0o755 }) - - if (process.platform === "darwin") { - execSync( - `osascript -e 'do shell script "cp \\"${tmpFile}\\" \\"${installPath}\\" && chmod +x \\"${installPath}\\"" with administrator privileges'`, - ) - } else { - // Linux: use pkexec - execSync(`pkexec sh -c 'cp "${tmpFile}" "${installPath}" && chmod +x "${installPath}"'`) - } - - logger.info(`CLI installed at ${installPath} (with elevated privileges)`) - return { success: true } - } catch (err) { - logger.error("Failed to install CLI with elevated privileges:", err) - return { - success: false, - error: err instanceof Error ? err.message : "Failed to install CLI", - } - } finally { - await unlink(tmpFile).catch(() => {}) + } catch (error) { + return { + success: false, + error: error instanceof Error ? error.message : "Failed to sync CLI login", } } } @IpcMethod() async uninstallCli(_context: IpcContext): Promise<{ success: boolean; error?: string }> { - const installPath = getCliInstallPath() - - if (!cliExistsAt(installPath)) { - return { success: true } - } - - if (process.platform === "win32") { - return this.uninstallCliWindows(installPath) - } - try { - await unlink(installPath) - logger.info(`CLI uninstalled from ${installPath}`) + await syncSessionToCliConfig() return { success: true } - } catch { - // Needs elevated permissions - if (process.platform === "darwin") { - try { - execSync( - `osascript -e 'do shell script "rm -f \\"${installPath}\\"" with administrator privileges'`, - ) - logger.info(`CLI uninstalled from ${installPath} (with admin privileges)`) - return { success: true } - } catch (err) { - logger.error("Failed to uninstall CLI with admin privileges:", err) - return { - success: false, - error: err instanceof Error ? err.message : "Failed to uninstall CLI", - } - } - } - - try { - execSync(`pkexec rm -f "${installPath}"`) - logger.info(`CLI uninstalled from ${installPath} (with pkexec)`) - return { success: true } - } catch (err) { - logger.error("Failed to uninstall CLI:", err) - return { - success: false, - error: err instanceof Error ? err.message : "Failed to uninstall CLI", - } - } - } - } - - private async installCliWindows( - cliSource: string, - installPath: string, - ): Promise<{ success: boolean; error?: string }> { - const installDir = path.dirname(installPath) - const cmdContent = `@echo off\r\nnode "${cliSource}" %*\r\n` - - try { - const { mkdirSync, writeFileSync } = await import("node:fs") - mkdirSync(installDir, { recursive: true }) - writeFileSync(`${installPath}.cmd`, cmdContent) - logger.info(`CLI installed at ${installPath}.cmd`) - return { success: true } - } catch (err) { - logger.error("Failed to install CLI on Windows:", err) + } catch (error) { return { success: false, - error: err instanceof Error ? err.message : "Failed to install CLI", - } - } - } - - private async uninstallCliWindows( - installPath: string, - ): Promise<{ success: boolean; error?: string }> { - try { - const { unlinkSync } = await import("node:fs") - const cmdPath = `${installPath}.cmd` - if (existsSync(cmdPath)) { - unlinkSync(cmdPath) - } - if (existsSync(installPath)) { - unlinkSync(installPath) - } - logger.info(`CLI uninstalled from ${installPath}`) - return { success: true } - } catch (err) { - logger.error("Failed to uninstall CLI on Windows:", err) - return { - success: false, - error: err instanceof Error ? err.message : "Failed to uninstall CLI", + error: error instanceof Error ? error.message : "Failed to clear CLI login", } } } diff --git a/apps/desktop/layer/main/src/lib/cli-session-sync.ts b/apps/desktop/layer/main/src/lib/cli-session-sync.ts index dfe9141a0..134af8bc7 100644 --- a/apps/desktop/layer/main/src/lib/cli-session-sync.ts +++ b/apps/desktop/layer/main/src/lib/cli-session-sync.ts @@ -1,5 +1,7 @@ +import { execFile } from "node:child_process" import { mkdir, readFile, writeFile } from "node:fs/promises" import { homedir } from "node:os" +import { promisify } from "node:util" import { env } from "@follow/shared/env.desktop" import { join } from "pathe" @@ -9,15 +11,18 @@ import { WindowManager } from "~/manager/window" import { logger } from "../logger" +const execFileAsync = promisify(execFile) +export const CLI_NPM_PACKAGE_NAME = "folocli" const CLI_CONFIG_DIR = join(homedir(), ".folo") const CLI_CONFIG_PATH = join(CLI_CONFIG_DIR, "config.json") +const getNpxCommand = () => (process.platform === "win32" ? "npx.cmd" : "npx") -interface CliConfig { +export interface CliConfig { token?: string apiUrl?: string } -const readCliConfig = async (): Promise => { +export const readCliConfig = async (): Promise => { try { const raw = await readFile(CLI_CONFIG_PATH, "utf8") return JSON.parse(raw) as CliConfig @@ -31,6 +36,44 @@ const writeCliConfig = async (config: CliConfig): Promise => { await writeFile(CLI_CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`, "utf8") } +export const getCliConfigPath = () => CLI_CONFIG_PATH + +export const getCliInstallCommand = () => `npm install -g ${CLI_NPM_PACKAGE_NAME}` + +export const getCliLoginCommand = () => + `npx --yes ${CLI_NPM_PACKAGE_NAME} login --token ` + +const runCliCommand = async (args: string[]) => { + await execFileAsync(getNpxCommand(), ["--yes", CLI_NPM_PACKAGE_NAME, ...args], { + windowsHide: true, + timeout: 120_000, + maxBuffer: 1024 * 1024, + }) +} + +export const isCliRunnerAvailable = async (): Promise => { + try { + await execFileAsync(getNpxCommand(), ["--version"], { + windowsHide: true, + timeout: 10_000, + maxBuffer: 128 * 1024, + }) + return true + } catch { + return false + } +} + +const clearCliConfigToken = async () => { + const config = await readCliConfig() + if (!config.token) { + return + } + + delete config.token + await writeCliConfig(config) +} + export const getSessionTokenFromCookies = async (): Promise => { const window = WindowManager.getMainWindow() if (!window) return undefined @@ -47,15 +90,34 @@ export const getSessionTokenFromCookies = async (): Promise } export const syncSessionToCliConfig = async (token?: string): Promise => { - const config = await readCliConfig() - if (token) { - config.token = token - config.apiUrl = env.VITE_API_URL - } else { - delete config.token + const config = await readCliConfig() + if (config.token === token && config.apiUrl === env.VITE_API_URL) { + return + } + + if (!(await isCliRunnerAvailable())) { + throw new Error("npx is not available") + } + + await runCliCommand(["login", "--token", token, "--api-url", env.VITE_API_URL]) + logger.info("CLI login synced via npx") + return } - await writeCliConfig(config) - logger.info(`CLI config synced (token ${token ? "set" : "cleared"})`) + if (await isCliRunnerAvailable()) { + try { + await runCliCommand(["logout"]) + logger.info("CLI login cleared via npx") + return + } catch (error) { + logger.error( + "Failed to clear CLI login via npx, falling back to local config cleanup:", + error, + ) + } + } + + await clearCliConfigToken() + logger.info("CLI login cleared from local config") } diff --git a/apps/desktop/layer/main/src/manager/app.ts b/apps/desktop/layer/main/src/manager/app.ts index 3e8124266..c9691e3db 100644 --- a/apps/desktop/layer/main/src/manager/app.ts +++ b/apps/desktop/layer/main/src/manager/app.ts @@ -49,7 +49,7 @@ class AppManagerStatic { registerUpdater() registerAppTray() - // Sync session to CLI config after window and cookies are ready + // Sync the desktop session to the npm CLI after cookies are ready. setTimeout(async () => { try { const token = await getSessionTokenFromCookies() diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/cli.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/cli.tsx index 78f579c45..0ff314e64 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/cli.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/cli.tsx @@ -10,9 +10,13 @@ import { SettingSectionTitle } from "../section" export const SettingCli = () => { interface CliInstallStatus { - installed: boolean - installPath: string | null - cliSourceAvailable: boolean + connected: boolean + configPath: string + hasDesktopSession: boolean + installCommand: string + loginCommand: string + npxAvailable: boolean + packageName: string } const { t } = useTranslation("settings") const [status, setStatus] = useState(null) @@ -72,9 +76,9 @@ export const SettingCli = () => { {status && (
-
+
Status: - {status.installed ? ( + {status.connected ? ( {t("cli.installed")} @@ -84,31 +88,68 @@ export const SettingCli = () => { {t("cli.not_installed")} )} + + + {status.npxAvailable ? t("cli.runtime_ready") : t("cli.runtime_missing")} +
- {status.installed && status.installPath && ( +
+
+
+ {t("cli.package")} +
+ {status.packageName} +
+ +
+
+ {t("cli.global_install")} +
+ {status.installCommand} +
+ +
+
+ {t("cli.desktop_sync")} +
+ {status.loginCommand} +
+
+ +
{t("cli.path")}: - {status.installPath} + {status.configPath}
- )} +
- {!status.cliSourceAvailable && ( + {!status.npxAvailable && (

{t("cli.not_available")}

)} + {!status.hasDesktopSession && ( +

{t("cli.require_login")}

+ )} +
- {!status.installed ? ( - - ) : ( + + + {status.connected && (