Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): select libsecret on Hyprland Linux (#4575)

Dashcb1e947449e1
diff --git a/apps/desktop/src/main/__tests__/linuxPasswordStore.test.ts b/apps/desktop/src/main/__tests__/linuxPasswordStore.test.ts
new file mode 100644
index 0000000000..009a3ef2a2
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/linuxPasswordStore.test.ts
@@ -0,0 +1,63 @@
+import { describe, expect, it, vi } from 'vitest';
+import { configureLinuxPasswordStore } from '../linuxPasswordStore.js';
+
+function configure(
+ env: NodeJS.ProcessEnv,
+ platform: NodeJS.Platform = 'linux',
+ explicitStore?: string,
+) {
+ const switches = new Map<string, string>();
+ if (explicitStore !== undefined) switches.set('password-store', explicitStore);
+ const appendSwitch = vi.fn((name: string, value: string) => switches.set(name, value));
+ configureLinuxPasswordStore({
+ platform,
+ env,
+ commandLine: { hasSwitch: (name) => switches.has(name), appendSwitch },
+ });
+ return { switches, appendSwitch };
+}
+
+describe('Hyprland password store startup selection', () => {
+ it.each([
+ { XDG_CURRENT_DESKTOP: 'Hyprland' },
+ { XDG_CURRENT_DESKTOP: 'Hyprland:wlroots' },
+ { XDG_CURRENT_DESKTOP: ' hyprland ' },
+ { XDG_SESSION_DESKTOP: 'Hyprland' },
+ { DESKTOP_SESSION: 'hyprland' },
+ { XDG_CURRENT_DESKTOP: ' ', XDG_SESSION_DESKTOP: 'Hyprland' },
+ ])('selects libsecret for %j', (env) => {
+ const { switches, appendSwitch } = configure(env);
+ expect(switches.get('password-store')).toBe('gnome-libsecret');
+ expect(appendSwitch).toHaveBeenCalledExactlyOnceWith('password-store', 'gnome-libsecret');
+ });
+
+ it.each(['kwallet', 'kwallet5', 'kwallet6', 'gnome-libsecret', 'basic', ''])(
+ 'preserves an explicit --password-store=%s, including an empty switch',
+ (store) => {
+ const { switches, appendSwitch } = configure(
+ { XDG_CURRENT_DESKTOP: 'Hyprland' },
+ 'linux',
+ store,
+ );
+ expect(switches.get('password-store')).toBe(store);
+ expect(appendSwitch).not.toHaveBeenCalled();
+ },
+ );
+
+ it.each([
+ {},
+ { XDG_CURRENT_DESKTOP: 'GNOME', DESKTOP_SESSION: 'hyprland' },
+ { XDG_CURRENT_DESKTOP: 'KDE', XDG_SESSION_DESKTOP: 'Hyprland' },
+ { XDG_CURRENT_DESKTOP: 'sway' },
+ { XDG_CURRENT_DESKTOP: 'not-hyprland' },
+ { XDG_SESSION_TYPE: 'wayland' },
+ ])('leaves other or unknown desktops to Electron: %j', (env) => {
+ expect(configure(env).appendSwitch).not.toHaveBeenCalled();
+ });
+
+ it.each(['darwin', 'win32'] as const)('leaves %s unchanged', (platform) => {
+ expect(
+ configure({ XDG_CURRENT_DESKTOP: 'Hyprland' }, platform).appendSwitch,
+ ).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 18e8c0f5f3..05ca864805 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -13,6 +13,15 @@ import { resolveRegionUserDataDirName } from './regionUserData.js';
import { createLogger, initLogger } from './logger.js';
import { beginDesktopDevInstance, type DesktopDevMode } from './devStartupStatus.js';
import { ensureSystemBinPathForMachineId } from './deviceId.js';
+import { configureLinuxPasswordStore } from './linuxPasswordStore.js';
+
+// Backend selection must precede ready and the dynamic bootstrap/auth imports.
+// This default never overrides --password-store; no plaintext fallback is added.
+configureLinuxPasswordStore({
+ platform: process.platform,
+ env: process.env,
+ commandLine: app.commandLine,
+});
// 正式目录保持历史兼容:global 构建继续使用 CindyGlobal,cn 版继续使用
// productName 默认的 Cindy;dev 也按构建区域选择对应 profile。必须在
diff --git a/apps/desktop/src/main/linuxPasswordStore.ts b/apps/desktop/src/main/linuxPasswordStore.ts
new file mode 100644
index 0000000000..be8ba7e6fb
--- /dev/null
+++ b/apps/desktop/src/main/linuxPasswordStore.ts
@@ -0,0 +1,27 @@
+/** Configure before Electron's ready event, without probing or opening the keyring. */
+export function configureLinuxPasswordStore({
+ platform,
+ env,
+ commandLine,
+}: {
+ platform: NodeJS.Platform;
+ env: NodeJS.ProcessEnv;
+ commandLine: {
+ hasSwitch(name: string): boolean;
+ appendSwitch(name: string, value: string): void;
+ };
+}): void {
+ if (platform !== 'linux' || commandLine.hasSwitch('password-store')) return;
+
+ // Chromium does not recognize Hyprland (including Omarchy) as a desktop
+ // with a secret store. Prefer the active desktop over legacy session hints
+ // so a stale DESKTOP_SESSION cannot override GNOME/KDE's native selection.
+ const desktop =
+ env.XDG_CURRENT_DESKTOP?.trim() ||
+ env.XDG_SESSION_DESKTOP?.trim() ||
+ env.DESKTOP_SESSION?.trim() ||
+ '';
+ if (desktop.split(':').some((name) => name.trim().toLowerCase() === 'hyprland')) {
+ commandLine.appendSwitch('password-store', 'gnome-libsecret');
+ }
+}
diff --git a/docs/dev-rules/credentials-and-local-storage.md b/docs/dev-rules/credentials-and-local-storage.md
index 0c748b86f6..ede77dbe5e 100644
--- a/docs/dev-rules/credentials-and-local-storage.md
+++ b/docs/dev-rules/credentials-and-local-storage.md
@@ -35,6 +35,20 @@
- 测试只使用明显无效的假凭证,不读取或复制开发者真实的 `HOME`、Agent home、
Electron userData 或系统凭证目录。
+## Linux Hyprland / Omarchy 凭证后端
+
+- Desktop 在 Electron `ready` 之前为 Hyprland 默认选择 `gnome-libsecret`,避免桌面
+ 自动识别失败导致登录回调收到令牌后无法加密保存。桌面身份依次取非空的
+ `XDG_CURRENT_DESKTOP`、`XDG_SESSION_DESKTOP`、`DESKTOP_SESSION`;其他桌面保持
+ Electron 原有选择。实现见
+ [linuxPasswordStore.ts](../../apps/desktop/src/main/linuxPasswordStore.ts),回归见
+ [linuxPasswordStore.test.ts](../../apps/desktop/src/main/__tests__/linuxPasswordStore.test.ts)。
+- 显式 `--password-store` 优先于此默认值。系统仍需提供可用且已解锁的 Secret Service
+ (例如 GNOME Keyring);此修复不安装或解锁钥匙串,也不新增明文降级。现有仅限开发版的
+ `XDT_DEV_SAFE_STORAGE_BASIC=1` 调试行为保持不变。
+- 旧版临时处理:完全退出 Cindy 后运行 `cindy --password-store=gnome-libsecret`。
+ 实机验收需覆盖登录、退出应用后正常启动仍保持登录,以及 `cindy://` 回调启动路径。
+
## macOS safeStorage 钥匙串条目
- macOS 上 Electron `safeStorage` 的钥匙串条目名由 `app.name` 派生