Skip to content

Commit 5cf68e0

Browse files
committed
Improved UI logic
1 parent 3420e09 commit 5cf68e0

8 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎Android-APP/app/src/main/java/com/zcode/proxy/MainActivity.kt‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ private fun AppScreen(themeMode: ThemeMode, onThemeModeChange: (ThemeMode) -> Un
335335
reachable = reachable,
336336
loggedIn = loggedIn,
337337
provider = provider,
338+
proxyRunning = proxyRunning,
338339
onLogin = ::startLogin,
339340
onLogout = ::logout,
340341
)
@@ -594,6 +595,7 @@ private fun AccountCard(
594595
reachable: Boolean,
595596
loggedIn: Boolean,
596597
provider: String,
598+
proxyRunning: Boolean,
597599
onLogin: () -> Unit,
598600
onLogout: () -> Unit,
599601
) {
@@ -633,7 +635,12 @@ private fun AccountCard(
633635
)
634636
Spacer(Modifier.width(6.dp))
635637
Text(
636-
if (loggedIn) "已登录 · OAuth 授权" else "未登录",
638+
when {
639+
proxyRunning && loggedIn -> "已登录 · 代理运行中 · 登出已锁定"
640+
proxyRunning -> "未登录 · 代理运行中"
641+
loggedIn -> "已登录 · OAuth 授权"
642+
else -> "未登录"
643+
},
637644
fontSize = 13.sp,
638645
color = cs.onSurfaceVariant,
639646
)
@@ -642,13 +649,13 @@ private fun AccountCard(
642649
if (loggedIn) {
643650
OutlinedButton(
644651
onClick = onLogout,
645-
enabled = reachable,
652+
enabled = reachable && !proxyRunning,
646653
shape = RoundedCornerShape(50),
647654
colors = ButtonDefaults.outlinedButtonColors(
648655
contentColor = cs.error,
649656
disabledContentColor = cs.error.copy(alpha = 0.38f),
650657
),
651-
border = BorderStroke(1.5.dp, cs.error.copy(alpha = if (reachable) 0.55f else 0.25f)),
658+
border = BorderStroke(1.5.dp, cs.error.copy(alpha = if (reachable && !proxyRunning) 0.55f else 0.25f)),
652659
modifier = Modifier.semantics { testTag = "logoutButton" },
653660
) {
654661
Text("登出", fontSize = 14.sp, fontWeight = FontWeight.Medium)

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ file (best-effort; never affects handling). Requires a TTY with at least
249249
| `identity.refererOrigin` | `ZCODE_REFERER_ORIGIN` | `https://zcode.z.ai` | `HTTP-Referer` URL |
250250
| `endpointRouting.enabled` | `ZCODE_ENDPOINT_ROUTING` | `true` | Server-controlled upstream URL remapping via `zcode.z.ai/api/v1/agent/configs` (mirrors ZCode's `ProviderEndpointRoutingService`; fail-open) |
251251
| `clientSigning.enabled` | `ZCODE_CLIENT_SIGNING` | `true` | Client request signing V4 (Ed25519 + proof-of-work, gate-driven; only activates when the server sets `codingPlanSignature.enable=true`; fail-open) |
252-
| `claim.enabled` | `ZCODE_CLAIM_ENABLED` | `false` | Weekend-plan auto-claim: poll `zcode.z.ai/api/v1/zcode-plan/billing/preview` and claim trial packages (see below) |
252+
| `claim.enabled` | `ZCODE_CLAIM_ENABLED` | `true` | Weekend-plan auto-claim: poll `zcode.z.ai/api/v1/zcode-plan/billing/preview` and claim trial packages (see below) |
253253
| `async.enabled` / `origin` / `maxRetries` / `maxWaitMs` | `ZCODE_ASYNC_ENABLED` / `ZCODE_ASYNC_ORIGIN` / `ZCODE_ASYNC_MAX_RETRIES` / `ZCODE_ASYNC_MAX_WAIT_MS` | `false` / `https://zcode.z.ai` / `3` / `0` | Async off-peak bridge gating + tuning (see Async section) |
254254
| config file path | `ZCODE_PROXY_CONFIG` | `config.yaml` | Config file to load on `serve` |
255255

‎config.example.yaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ async:
144144
# Env overrides: ZCODE_CLAIM_ENABLED, ZCODE_CLAIM_AUTO, ZCODE_CLAIM_ORIGIN,
145145
# ZCODE_CLAIM_POLL_INTERVAL_MS.
146146
claim:
147-
enabled: false
147+
# On by default: the scheduler polls the preview endpoint every 5 min and
148+
# idles until a campaign goes live (404 preview = nothing to claim).
149+
# `false` = CLI-only (`zcode-proxy claim [list|now]` still works).
150+
enabled: true
148151
# Auto-claim in the background while serving. `false` = CLI-only
149152
# (`zcode-proxy claim` still works when `enabled: true`).
150153
auto: true

‎src/config/loader.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ logging:
138138
defaultModel: "",
139139
});
140140
expect(cfg.claim).toEqual({
141-
enabled: false,
141+
enabled: true,
142142
auto: true,
143143
origin: "https://zcode.z.ai",
144144
pollIntervalMs: 300000,

‎src/config/loader.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const DEFAULTS = {
5959
ASYNC_SETTLE_TIMEOUT_MS: 8000,
6060
ASYNC_CONTROL_TIMEOUT_MS: 15000,
6161
ASYNC_DEFAULT_MODEL: "",
62-
CLAIM_ENABLED: false,
62+
CLAIM_ENABLED: true,
6363
CLAIM_AUTO: true,
6464
CLAIM_ORIGIN: "https://zcode.z.ai",
6565
CLAIM_POLL_INTERVAL_MS: 300000,

‎src/config/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export interface AsyncConfig {
131131
* @see _reverse/NOTEPAD.md "Manual Claim Plan" section for the protocol.
132132
*/
133133
export interface ClaimConfig {
134-
/** Enable the claim subsystem (CLI `claim` command + auto scheduler). Default `false`. */
134+
/** Enable the claim subsystem (CLI `claim` command + auto scheduler). Default `true`. */
135135
enabled: boolean;
136136
/** Auto-claim in the background while the proxy is serving. Default `true` (effective when `enabled`). */
137137
auto: boolean;

‎src/tui/app.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ export async function runTui(args: ServeArgs): Promise<void> {
380380
}
381381

382382
async function logout(): Promise<void> {
383+
// Stop-first guard: the running proxy keeps serving with its in-memory
384+
// credential until restarted, so logging out mid-run would only look applied.
385+
if (state.serverStatus === "running" || state.serverStatus === "starting") {
386+
setToast("stop the proxy before logging out (press s)", "err");
387+
return;
388+
}
383389
if (activeOauth) {
384390
void activeOauth.client.close().catch(() => {});
385391
activeOauth = null;

‎src/tui/frame.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ export function buildFrame(s: FrameState): Frame {
277277
? [
278278
{ t: " Logged In ", c: DIM },
279279
{ t: " " },
280-
{ t: " Logout ", c: BTN_GRAY, action: { kind: "key", key: "o" } },
280+
// Logout is stop-first while the proxy is running — the server keeps
281+
// serving with its in-memory credential until restarted.
282+
busy
283+
? { t: " Logout ", c: DIM }
284+
: { t: " Logout ", c: BTN_GRAY, action: { kind: "key", key: "o" } },
281285
]
282286
: [
283287
{ t: " OAuth Login ", c: BTN_GREEN, action: { kind: "key", key: "l" } },

0 commit comments

Comments
 (0)