Skip to content

fix: desktop update banner for desktop releases#117

Merged
zouyonghe merged 2 commits intoAstrBotDevs:mainfrom
zouyonghe:codex/fix-desktop-update-banner
Apr 13, 2026
Merged

fix: desktop update banner for desktop releases#117
zouyonghe merged 2 commits intoAstrBotDevs:mainfrom
zouyonghe:codex/fix-desktop-update-banner

Conversation

@zouyonghe
Copy link
Copy Markdown
Member

@zouyonghe zouyonghe commented Apr 13, 2026

This fixes a desktop-only update UX mismatch where the top header could show AstrBot 有新版本! while the desktop updater dialog reported that the current app was already up to date.

In desktop release mode, the upstream dashboard still used /api/update/check to drive the header badge. That API reports backend update availability, not desktop shell update availability. Clicking the badge in desktop mode opens the desktop app updater dialog, so users could see a backend-originated update hint followed by a desktop updater result that correctly said there was no newer app build.

The root cause was that VerticalHeader.vue assigned hasNewVersion directly from res.data.data.has_new_version even when isDesktopReleaseMode was true. The desktop shell already routes the actual update action through window.astrbotAppUpdater, so the header badge needed to stop reflecting backend release checks in that mode.

This change patches the upstream dashboard source during prepare:webui so the backend update badge is only enabled outside desktop release mode. It also adds a regression test for the patch helper and wires the helper into the WebUI prepare pipeline.

Validation:

  • node --test "scripts/prepare-resources/desktop-bridge-checks.test.mjs"
  • node --test "scripts/prepare-resources/mode-dispatch.test.mjs" "scripts/prepare-resources/context.test.mjs" "scripts/prepare-resources/bridge-bootstrap-updater-contract.test.mjs"
  • pnpm test:prepare-resources

Summary by Sourcery

Ensure the desktop app header update banner no longer reflects backend update availability when running in desktop release mode.

Bug Fixes:

  • Prevent the desktop header update indicator from showing backend-originated update prompts that do not correspond to desktop shell updates in desktop release mode.

Enhancements:

  • Add a prepare-resources patch that rewrites the dashboard header update logic to gate the backend update banner by desktop release mode and integrate it into the WebUI preparation pipeline.

Tests:

  • Add regression tests for the desktop release update indicator patch helper, including tolerance of minor upstream formatting changes and warning behavior when the expected pattern is missing.

@zouyonghe zouyonghe changed the title [codex] fix desktop update banner for desktop releases fix: desktop update banner for desktop releases Apr 13, 2026
@zouyonghe zouyonghe marked this pull request as ready for review April 13, 2026 02:10
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a patching mechanism to suppress the backend update banner in VerticalHeader.vue when the application is running in desktop release mode. The feedback highlights that the current string-replacement logic is fragile due to its reliance on exact indentation and line endings, suggesting the use of regular expressions and better error reporting to ensure the patch applies correctly across different environments.

Comment on lines +81 to +89
const target = " hasNewVersion.value = res.data.data.has_new_version;\n\n if (res.data.data.has_new_version) {";
const replacement =
" const backendHasNewVersion = !isDesktopReleaseMode.value && res.data.data.has_new_version;\n" +
" hasNewVersion.value = backendHasNewVersion;\n\n" +
" if (backendHasNewVersion) {";

if (!source.includes(target)) {
return;
}
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.

medium

The patch logic is fragile because it relies on an exact string match with hardcoded indentation and Unix-style line endings (\n\n). If the file uses CRLF (common on Windows) or different indentation, the patch will fail. Additionally, the function returns silently when the target is not found, which can lead to the bug persisting without any build-time warning.

Consider using a regular expression to handle whitespace and line ending variations, and log a warning if the patch cannot be applied.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The patchDesktopReleaseUpdateIndicator helper relies on an exact multi-line string match for target, which is brittle against minor upstream formatting changes; consider using a more flexible pattern (e.g., a regex or AST-based approach) to make the patch more resilient.
  • In the patch helper, failing to find the target string causes a silent return; adding a warning or log when the expected pattern is not found would make it easier to detect when upstream changes have broken the patch.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `patchDesktopReleaseUpdateIndicator` helper relies on an exact multi-line string match for `target`, which is brittle against minor upstream formatting changes; consider using a more flexible pattern (e.g., a regex or AST-based approach) to make the patch more resilient.
- In the patch helper, failing to find the `target` string causes a silent return; adding a warning or log when the expected pattern is not found would make it easier to detect when upstream changes have broken the patch.

## Individual Comments

### Comment 1
<location path="scripts/prepare-resources/desktop-bridge-checks.mjs" line_range="76-91" />
<code_context>
+    return;
+  }
+
+  const target = "      hasNewVersion.value = res.data.data.has_new_version;\n\n      if (res.data.data.has_new_version) {";
+  const replacement =
+    "      const backendHasNewVersion = !isDesktopReleaseMode.value && res.data.data.has_new_version;\n" +
</code_context>
<issue_to_address>
**suggestion:** The exact string target makes this patch brittle to minor formatting or code changes in the Vue file.

This depends on an exact substring match (indentation, newlines, and precise code sequence), so even small refactors in `VerticalHeader.vue` (spacing changes, added variables, comments) will break the patch with no clear signal. Please use a more robust match (e.g., a regex for the assignment and the `if` near each other, or a shorter, essential substring) so it remains stable across minor formatting changes.

```suggestion
  const source = await readFile(file, 'utf8');
  if (source.includes('const backendHasNewVersion = !isDesktopReleaseMode.value && res.data.data.has_new_version;')) {
    return;
  }

  // Match the assignment to hasNewVersion and the immediately following if-check,
  // allowing for minor whitespace/formatting changes.
  const targetPattern =
    /hasNewVersion\.value\s*=\s*res\.data\.data\.has_new_version;\s*\n\s*if\s*\(\s*res\.data\.data\.has_new_version\s*\)\s*{/;

  const replacement =
    "      const backendHasNewVersion = !isDesktopReleaseMode.value && res.data.data.has_new_version;\n" +
    "      hasNewVersion.value = backendHasNewVersion;\n\n" +
    "      if (backendHasNewVersion) {";

  if (!targetPattern.test(source)) {
    return;
  }

  const patched = source.replace(targetPattern, replacement);
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread scripts/prepare-resources/desktop-bridge-checks.mjs Outdated
@zouyonghe
Copy link
Copy Markdown
Member Author

@sourcery-ai review

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe zouyonghe merged commit 6a0ae78 into AstrBotDevs:main Apr 13, 2026
4 checks passed
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