Skip to content

Refactor GitHub unlock resume flow#38

Merged
qiin2333 merged 1 commit into
masterfrom
codex/refactor-github-unlock-flow
Jun 14, 2026
Merged

Refactor GitHub unlock resume flow#38
qiin2333 merged 1 commit into
masterfrom
codex/refactor-github-unlock-flow

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Move GitHub developer unlock persistence, polling, and Star verification into DeveloperUnlockService
  • Keep SettingsPageV2 focused on UI orchestration and developer-mode activation state
  • Restore pending GitHub device-flow verification after returning from the browser so users do not need to restart authorization

Validation

  • git diff --check
  • DEVECO_SDK_HOME=/Applications/DevEco-Studio.app/Contents/sdk sh ./hvigorw --mode module -p module=entry assembleHap --no-daemon (CompileArkTS passed; PackageHap still fails locally because this machine has no Java Runtime)

Summary by CodeRabbit

发布说明

  • New Features
    • 新增开发者模式解锁服务,集中封装设备码请求、轮询状态与结果处理,并提供统一的状态机返回(已验证/未 Star/过期/失败等)。
    • 支持恢复挂起的设备码流程:在页面展示与设置加载完成后自动续处理,减少中断。
    • 改进并发与弹窗控制,优化失败/未 Star 场景的展示与引导(项目链接生成随服务调整)。

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 581defc3-69cf-4983-a1f9-a00b47bd453d

📥 Commits

Reviewing files that changed from the base of the PR and between 72ecc07 and fde7e95.

📒 Files selected for processing (2)
  • entry/src/main/ets/pages/SettingsPageV2.ets
  • entry/src/main/ets/service/DeveloperUnlockService.ets
🚧 Files skipped from review as they are similar to previous changes (2)
  • entry/src/main/ets/service/DeveloperUnlockService.ets
  • entry/src/main/ets/pages/SettingsPageV2.ets

📝 Walkthrough

Walkthrough

新增 DeveloperUnlockService,将 GitHub 设备码请求、带节流轮询、pending 状态持久化与 token 轮询结果映射封装为独立服务层。SettingsPageV2 将原基于 GitHubStarVerifier 的解锁逻辑迁移至该服务,新增并发控制状态字段、onPageShow() 生命周期及 resumeDeveloperPendingUnlock() 等辅助方法,由 DeveloperUnlockStatus 状态机驱动整个解锁流程。

Changes

开发者解锁服务层封装与页面层迁移

Layer / File(s) Summary
DeveloperUnlockService 服务层实现
entry/src/main/ets/service/DeveloperUnlockService.ets
新增 DeveloperUnlockStatus 枚举(REQUESTED/PENDING/VERIFIED/NOT_STARRED/EXPIRED/FAILED)、DeveloperUnlockResult 结果模型及 DeveloperUnlockService 静态方法集;封装设备码请求、带最小间隔节流的轮询、pending 设备码持久化读写与恢复,以及授权成功后的 star 校验与登录/验证时间更新逻辑。
SettingsPageV2 导入、状态字段与生命周期
entry/src/main/ets/pages/SettingsPageV2.ets
将导入从 GitHubStarVerifier 替换为 DeveloperUnlockService/DeveloperUnlockStatus/DeveloperUnlockResult;新增 developerPendingDialogVisibledeveloperPendingResumeBusy 并发控制字段;新增 onPageShow() 生命周期及 loadSettings() finally 块中的延迟触发,均指向 resumeDeveloperPendingUnlock()
SettingsPageV2 UI 查询与对话框触发
entry/src/main/ets/pages/SettingsPageV2.ets
getDeveloperModeSubtitle()toggleDeveloperMode() 改为基于 DeveloperUnlockService.isGitHubConfigured() 与服务提供的项目信息进行分支;showDeveloperUnlockDialog() 改为优先调用 restorePendingDeviceCode() 恢复 pending 设备码,再按状态决定是否直接展示授权对话;项目链接改为使用服务提供的 URL。
SettingsPageV2 核心状态机与辅助方法
entry/src/main/ets/pages/SettingsPageV2.ets
新增 resumeDeveloperPendingUnlock()(并发控制与防重入)、requestDeveloperDeviceCode()showDeveloperDeviceCodeDialog()pollDeveloperPendingDeviceCode()applyDeveloperUnlockResult() 状态机(REQUESTED/PENDING/VERIFIED/NOT_STARRED/EXPIRED/FAILED)、activateDeveloperMode()showDeveloperNotStarredDialog()failDeveloperUnlockVerification() 等辅助方法,替代原 GitHubStarVerifier 的持久化、节流与轮询逻辑。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次变更的核心内容——将 GitHub 解锁恢复流程重构至服务层,逻辑清晰。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/refactor-github-unlock-flow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
entry/src/main/ets/pages/SettingsPageV2.ets (1)

609-609: 💤 Low value

restorePendingDeviceCode 重复调用

Line 609 在 loadSettings() 中已调用 restorePendingDeviceCode(),但 finally 块中的 resumeDeveloperPendingUnlock() 会再次调用(line 3804)。建议移除 line 609 的调用,让 resume 方法统一处理恢复逻辑。

♻️ 可选优化
       this.developerMode = await this.loadBoolean(SettingsKeys.DEVELOPER_MODE, false);
       this.devKeyActivated = await this.loadBoolean(SettingsKeys.DEV_KEY_ACTIVATED, false);
-      await DeveloperUnlockService.restorePendingDeviceCode();
       
       // 备份
       this.autoBackupEnabled = await SettingsBackupService.isAutoBackupEnabled();

Also applies to: 617-619

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@entry/src/main/ets/pages/SettingsPageV2.ets` at line 609, The
`restorePendingDeviceCode()` method is being called twice - once at line 609 in
the `loadSettings()` method and again through `resumeDeveloperPendingUnlock()`
in the finally block at line 3804, causing duplicate invocation. Remove the
`DeveloperUnlockService.restorePendingDeviceCode()` call at line 609 and also
examine lines 617-619 for any similar duplicate calls to the same method,
removing those as well. This will consolidate the restore logic into a single
unified invocation through `resumeDeveloperPendingUnlock()` in the finally
block.
entry/src/main/ets/service/DeveloperUnlockService.ets (1)

134-142: 💤 Low value

可考虑并行清理提升性能

6 次顺序写入可以用 Promise.all 并行执行,减少 I/O 等待时间。

♻️ 可选优化
 static async clearPendingDeviceCode(): Promise<void> {
   DeveloperUnlockService.pendingDeviceCode = null;
-  await PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_DEVICE_CODE, '');
-  await PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_USER_CODE, '');
-  await PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_VERIFICATION_URI, '');
-  await PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_VERIFICATION_URI_COMPLETE, '');
-  await PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_EXPIRES_AT, 0);
-  await PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_INTERVAL, 0);
+  await Promise.all([
+    PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_DEVICE_CODE, ''),
+    PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_USER_CODE, ''),
+    PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_VERIFICATION_URI, ''),
+    PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_VERIFICATION_URI_COMPLETE, ''),
+    PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_EXPIRES_AT, 0),
+    PreferencesUtil.put(SettingsKeys.DEV_GITHUB_PENDING_INTERVAL, 0),
+  ]);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@entry/src/main/ets/service/DeveloperUnlockService.ets` around lines 134 -
142, The clearPendingDeviceCode method in DeveloperUnlockService currently
executes six sequential await calls to PreferencesUtil.put, which blocks on each
I/O operation. Instead of awaiting each PreferencesUtil.put call individually,
collect all six calls into an array and execute them in parallel using
Promise.all. This will significantly reduce total I/O wait time by allowing all
preference writes to occur concurrently rather than sequentially.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@entry/src/main/ets/pages/SettingsPageV2.ets`:
- Line 609: The `restorePendingDeviceCode()` method is being called twice - once
at line 609 in the `loadSettings()` method and again through
`resumeDeveloperPendingUnlock()` in the finally block at line 3804, causing
duplicate invocation. Remove the
`DeveloperUnlockService.restorePendingDeviceCode()` call at line 609 and also
examine lines 617-619 for any similar duplicate calls to the same method,
removing those as well. This will consolidate the restore logic into a single
unified invocation through `resumeDeveloperPendingUnlock()` in the finally
block.

In `@entry/src/main/ets/service/DeveloperUnlockService.ets`:
- Around line 134-142: The clearPendingDeviceCode method in
DeveloperUnlockService currently executes six sequential await calls to
PreferencesUtil.put, which blocks on each I/O operation. Instead of awaiting
each PreferencesUtil.put call individually, collect all six calls into an array
and execute them in parallel using Promise.all. This will significantly reduce
total I/O wait time by allowing all preference writes to occur concurrently
rather than sequentially.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1dc3bb64-bd14-4889-a185-ed5b2d9cef75

📥 Commits

Reviewing files that changed from the base of the PR and between d99033a and 72ecc07.

📒 Files selected for processing (2)
  • entry/src/main/ets/pages/SettingsPageV2.ets
  • entry/src/main/ets/service/DeveloperUnlockService.ets

@qiin2333 qiin2333 force-pushed the codex/refactor-github-unlock-flow branch from 72ecc07 to fde7e95 Compare June 14, 2026 06:56
@qiin2333 qiin2333 merged commit b8f51c6 into master Jun 14, 2026
2 checks passed
@qiin2333 qiin2333 deleted the codex/refactor-github-unlock-flow branch June 14, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant