|
1 | | -# Codex Account Switch |
| 1 | +# Codex 账号切换工具 |
2 | 2 |
|
3 | | -中文文档: [README.zh-CN.md](./README.zh-CN.md) |
| 3 | +Codex 账号切换工具是一个本地桌面应用,用来在同一台机器上管理多个 Codex 账号。它通过本地账号备份目录保存不同账号状态,支持切换当前账号、查看账号状态和额度信息,并提供 macOS 与 Windows 原生 Tauri 桌面界面。 |
4 | 4 |
|
5 | | -This repository packages a local multi-account Codex switching workflow: macOS now keeps the retained command-line flow under `macOS-backup/`, with `macOS-backup/install.sh` acting as a compatibility entry that prefers the native desktop runtime when available and falls back to the legacy shell flow, while Windows uses a native desktop app. |
| 5 | +`macOS-backup/` 里的 shell 脚本仍然保留,作为兼容旧流程的入口;当前主要方向是原生桌面端。 |
6 | 6 |
|
7 | | -## Features |
| 7 | +## 当前功能 |
8 | 8 |
|
9 | | -- Automatically save the current active account after login, then switch accounts with one click |
10 | | -- Close the Codex desktop app before switching and relaunch it afterward when needed |
11 | | -- Use the Windows control panel for switching, login, opening folders, adding profiles, and related actions |
| 9 | +- 仪表盘:显示当前账号、账号总数、可用账号和待登录账号数量。 |
| 10 | +- 账号页:每页 4 张账号卡片,支持切换、登录刷新、重命名、删除或清空、打开账号目录、编辑 Base URL。 |
| 11 | +- 运行时页:先放置运行时可视化界面,后续再接入更多后端能力。 |
| 12 | +- 设置页:包含语言、主题、端口、开机自启占位、更新地址、配置备份、版本、许可证、检查更新和 GitHub 入口。 |
| 13 | +- 引导页:展示添加账号、登录、切换账号的基础流程。 |
| 14 | +- 支持多套浅色和深色主题、中英文界面,以及没有 Tauri API 时的本地预览数据。 |
12 | 15 |
|
13 | | -## Platform support |
| 16 | +部分设置项和运行时条目目前只完成前端界面,后续再接入后端。 |
14 | 17 |
|
15 | | -- macOS: compatibility shell scripts under [`macOS-backup/`](./macOS-backup) |
16 | | -- Windows: the `.exe` desktop application from the repository release |
| 18 | +## 平台支持 |
17 | 19 |
|
18 | | -## Repository layout |
| 20 | +- macOS:原生 Tauri 桌面端,同时保留 `macOS-backup/` 下的兼容脚本。 |
| 21 | +- Windows:原生 Tauri 桌面端,通过 Release 中的 `.exe` 分发。 |
19 | 22 |
|
20 | | -- [`macOS-backup/`](./macOS-backup): retained macOS compatibility installer, native desktop bridge scripts, and legacy shell fallback |
21 | | -- [`src-tauri/`](./src-tauri/): Rust/Tauri runtime root |
22 | | - - [`src-tauri/win/front/`](./src-tauri/win/front/): Windows desktop frontend shell |
23 | | - - [`src-tauri/mac/front/`](./src-tauri/mac/front/): macOS desktop frontend shell |
24 | | - - [`src-tauri/shared/front/`](./src-tauri/shared/front/): shared frontend bridge modules and font assets |
25 | | - - [`src-tauri/win/runtime/`](./src-tauri/win/runtime/): Windows-only runtime code |
26 | | - - [`src-tauri/mac/runtime/`](./src-tauri/mac/runtime/): macOS-only runtime code |
27 | | - - [`src-tauri/shared/runtime/`](./src-tauri/shared/runtime/): shared CLI, models, errors, and runtime logic |
28 | | - - [`src-tauri/shared/platform/`](./src-tauri/shared/platform/): cross-platform lifecycle hook layer |
29 | | - - [`src-tauri/shared/commands/`](./src-tauri/shared/commands/): shared Tauri command handlers |
30 | | - - [`src-tauri/src/`](./src-tauri/src/): crate entrypoints kept for Cargo/Tauri conventions |
31 | | -- [`examples/account_backup/demo/`](./examples/account_backup/demo/): placeholder `auth.json` template |
32 | | -- [`docs/`](./docs/): implementation and security notes |
33 | | -- [`windows/`](./windows/): historical Windows note |
| 23 | +平台专属逻辑优先放在 `src-tauri/mac/**` 或 `src-tauri/win/**` 下。`src-tauri/shared/**` 只放共享前端模块、命令契约、运行时模型和中立的跨平台逻辑。 |
34 | 24 |
|
35 | | -## macOS installation |
| 25 | +## 仓库结构 |
| 26 | + |
| 27 | +- `src-tauri/`:Rust 与 Tauri 应用根目录。 |
| 28 | +- `src-tauri/mac/front/`:macOS HTML 壳、样式和窗口控制。 |
| 29 | +- `src-tauri/win/front/`:Windows HTML 壳、样式和窗口控制。 |
| 30 | +- `src-tauri/shared/front/`:共享前端状态、渲染、动作、主题、国际化和 Tauri 桥接。 |
| 31 | +- `src-tauri/mac/runtime/`:macOS 运行时集成。 |
| 32 | +- `src-tauri/win/runtime/`:Windows 运行时集成。 |
| 33 | +- `src-tauri/shared/runtime/`:共享模型、账号数据处理、更新检查、路径、元数据和切换核心逻辑。 |
| 34 | +- `src-tauri/shared/commands/`:暴露给前端的 Tauri 命令处理层。 |
| 35 | +- `macOS-backup/`:旧 shell 流程和桌面桥接的兼容安装、卸载脚本。 |
| 36 | +- `examples/account_backup/demo/`:示例 `auth.json` 模板。 |
| 37 | +- `scripts/`:版本同步、macOS 产物布局和 macOS `.pkg` 生成脚本。 |
| 38 | + |
| 39 | +生成文件不进仓库。前端网页构建输出放在 `dist/web/`,macOS 桌面端打包产物直接落到 `dist/` 根目录。 |
| 40 | + |
| 41 | +## 开发 |
| 42 | + |
| 43 | +安装依赖: |
36 | 44 |
|
37 | 45 | ```bash |
38 | | -cd ~/.../Codex_Account_Switch |
39 | | -bash macOS-backup/install.sh |
40 | | -source ~/.zshrc |
| 46 | +npm install |
41 | 47 | ``` |
42 | 48 |
|
43 | | -The compatibility installer supports three modes: |
| 49 | +启动前端和 Tauri 开发应用: |
44 | 50 |
|
45 | | -- `auto` (default): prefer the native desktop installer when a macOS runtime binary is available, otherwise fall back to the legacy shell installer |
46 | | -- `desktop`: require the native desktop installer path and fail if it cannot be found |
47 | | -- `legacy`: force the original shell-based `codex-switch.sh` flow |
| 51 | +```bash |
| 52 | +npm run tauri:dev |
| 53 | +``` |
48 | 54 |
|
49 | | -Examples: |
| 55 | +只构建前端: |
50 | 56 |
|
51 | 57 | ```bash |
52 | | -bash macOS-backup/install.sh --mode auto |
53 | | -bash macOS-backup/install.sh --mode desktop |
54 | | -bash macOS-backup/install.sh --mode legacy |
| 58 | +npm run build |
55 | 59 | ``` |
56 | 60 |
|
57 | | -In desktop mode, the installer: |
| 61 | +运行 Rust 测试: |
58 | 62 |
|
59 | | -- delegates to the native `codex_switch` installer |
60 | | -- keeps the real runtime under `~/.codex/account_backup/macos/` |
61 | | -- writes the managed `~/.codex/bin/codex` shim through the native runtime |
62 | | -- injects a PATH hook into `~/.zshrc` so the managed shim is available in the shell |
| 63 | +```bash |
| 64 | +npm run test:rust |
| 65 | +``` |
63 | 66 |
|
64 | | -In legacy mode, the installer keeps the original shell behavior: |
| 67 | +## 桌面端打包 |
65 | 68 |
|
66 | | -- copies `macOS-backup/codex-switch.sh` to `~/.codex/account_backup/codex-switch.sh` |
67 | | -- creates `~/.codex/account_backup/a` through `~/.codex/account_backup/d` |
68 | | -- writes the example auth template into any missing `~/.codex/account_backup/<profile>/auth.json` |
69 | | -- copies the current `~/.codex/auth.json` to `~/.codex/account_backup/a/auth.json` when available |
70 | | -- initializes profile `a` as the active profile if a real root auth file exists and no active profile is set yet |
71 | | -- injects a `codex()` wrapper into `~/.zshrc` |
| 69 | +Tauri 2 没有提供 bundle 输出目录配置。macOS 打包脚本会在运行 Tauri 前,把 `src-tauri/target/release/bundle/macos` 和 `src-tauri/target/release/bundle/dmg` 准备成指向 `dist/` 的链接。Tauri 仍然写入它自己的固定 bundle 路径,但实际 `.app` 和 `.dmg` 会直接落到 `dist/`;`.pkg` 生成脚本也直接写入 `dist/`。 |
72 | 70 |
|
73 | | -## Windows installation |
| 71 | +本地测试阶段只打包 `.app`: |
74 | 72 |
|
75 | | -- Download the latest `.exe` desktop application from this repository's Releases page |
| 73 | +```bash |
| 74 | +npm run tauri:build:macos-app |
| 75 | +``` |
76 | 76 |
|
77 | | -## Local macOS packaging |
| 77 | +`.app` 写入 `dist/` 后,会删除构建过程中生成的裸 macOS 可执行中间产物。 |
78 | 78 |
|
79 | | -To generate a drag-install `.dmg` locally: |
| 79 | +最终发布阶段打包 `.dmg` 和 `.pkg`: |
80 | 80 |
|
81 | 81 | ```bash |
82 | | -npm run tauri:build:macos-dmg |
| 82 | +npm run tauri:build:macos-release |
83 | 83 | ``` |
84 | 84 |
|
85 | | -The build outputs land at: |
| 85 | +最终发布流程会把 `.app` 作为打包输入,随后从 `dist/` 中移除 `.app`,只把发布用安装包保留在 `dist/` 根目录。`dist/` 根目录里的旧版本 `.dmg` 和 `.pkg` 会移动到 `dist/history/` 下对应的版本命名文件夹中;重复构建当前版本时会替换当前根目录安装包,不再额外备份。 |
86 | 86 |
|
87 | | -- `src-tauri/target/release/bundle/macos/codex_switch.app` |
88 | | -- `src-tauri/target/release/bundle/macos/codex_switch_*.dmg` |
89 | | - |
90 | | -## macOS usage |
| 87 | +预期本地产物结构: |
91 | 88 |
|
92 | 89 | ```text |
93 | | -Open Terminal |
94 | | -codex switch list List available accounts |
95 | | -codex switch a Switch to the account under folder a |
96 | | -codex switch b Switch to the account under folder b |
| 90 | +dist/ |
| 91 | + codex_switch_<version>_<arch>.dmg |
| 92 | + codex_switch_<version>_<arch>.pkg |
| 93 | + history/ |
| 94 | + v<old-version>/ |
| 95 | + ... |
| 96 | + web/ |
| 97 | + ... |
| 98 | +``` |
| 99 | + |
| 100 | +## 版本与发布 |
| 101 | + |
| 102 | +- 项目版本保存在 `package.json`,并同步到 Tauri 和 Cargo 元数据。 |
| 103 | +- GitHub Release 标签使用完整语义版本号,例如 `1.5.3`。 |
| 104 | +- 每个补丁版本单独创建一个 Release 标签。 |
| 105 | +- 不要把补丁版本产物上传到旧的两段式标签下,例如不要继续把 `1.5.x` 上传到 `1.5`。 |
| 106 | +- macOS 安装包作为 Release 资产发布,不提交到 Git。 |
| 107 | + |
| 108 | +常用命令: |
| 109 | + |
| 110 | +```bash |
| 111 | +npm run version:sync |
| 112 | +npm run version:set -- 1.5.4 |
97 | 113 | ``` |
98 | 114 |
|
99 | | -If you want to add profiles beyond the default `a` through `d`, create the target folder manually first, put a valid `auth.json` inside it, and then run the switch command. |
| 115 | +## macOS 兼容脚本 |
100 | 116 |
|
101 | | -## macOS uninstall |
| 117 | +通过兼容入口安装: |
| 118 | + |
| 119 | +```bash |
| 120 | +bash macOS-backup/install.sh |
| 121 | +source ~/.zshrc |
| 122 | +``` |
| 123 | + |
| 124 | +支持三种模式: |
| 125 | + |
| 126 | +- `auto`:优先尝试原生桌面运行时,找不到时回退到 legacy shell 流程。 |
| 127 | +- `desktop`:强制使用原生桌面运行时。 |
| 128 | +- `legacy`:强制使用原来的 shell 版 `codex-switch.sh` 流程。 |
| 129 | + |
| 130 | +卸载: |
102 | 131 |
|
103 | 132 | ```bash |
104 | 133 | bash macOS-backup/uninstall.sh |
105 | 134 | bash macOS-backup/uninstall.sh --remove-script |
106 | 135 | source ~/.zshrc |
107 | 136 | ``` |
108 | 137 |
|
109 | | -The compatibility uninstaller also supports `--mode auto|desktop|legacy`. |
| 138 | +卸载脚本只移除受管理的命令接入层,不会删除账号备份目录;账号目录需要时手动清理。 |
| 139 | + |
| 140 | +## Windows 安装 |
| 141 | + |
| 142 | +在仓库 Releases 页面下载最新 Windows `.exe`。 |
| 143 | + |
| 144 | +## 账号数据 |
110 | 145 |
|
111 | | -- In desktop mode it removes the native shell hook first, then delegates to the native runtime uninstaller. |
112 | | -- In legacy mode it removes the original shell wrapper block. |
113 | | -- The default uninstall removes only managed command hooks. It does not delete your account folders unless you remove them manually. |
| 146 | +账号数据只保存在本机。导出的配置或账号备份可能包含 API Key 或认证数据,只应保存在可信设备上。 |
0 commit comments