Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/h0lly w00dz z updater #5632

Merged
merged 7 commits into from
Oct 15, 2024

Conversation

lloydzhou
Copy link
Member

@lloydzhou lloydzhou commented Oct 11, 2024

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

Summary by CodeRabbit

  • New Features

    • Enhanced version checking for updates using semantic version comparison.
    • Conditional display of an update button for users in specific client contexts.
    • New updater interface for improved update management.
  • User Interface Improvements

    • Updated error messages and feedback for update operations in both English and Chinese locales.
    • Added user feedback strings for successful and failed updates.
  • Bug Fixes

    • Improved accuracy in determining available updates.
    • Enabled dialog prompts for update notifications.

Copy link

vercel bot commented Oct 11, 2024

@lloydzhou is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 11, 2024

Walkthrough

The pull request introduces several modifications across various files to enhance version checking and user interaction for application updates. Key changes include the implementation of semantic version comparison in settings.tsx, the addition of an updater interface to the Window object in global.d.ts, and updates to locale files to improve user feedback for update operations. New utility functions for client updates and version comparison have also been added, streamlining the update process and enhancing error messaging.

Changes

File Change Summary
app/components/settings.tsx Updated version checking logic to use semverCompare. Added conditional rendering for update button.
app/global.d.ts Added updater interface to Window with methods for update management.
app/locales/cn.ts Enhanced error messages and added new properties for update feedback in cn locale.
app/locales/en.ts Added new strings for update success and failure messages in en locale.
app/store/update.ts Added clientUpdate import and invoked it in getLatestVersion method after notifying about updates.
app/utils.ts Introduced clientUpdate and semverCompare functions for handling updates and version comparison.
src-tauri/tauri.conf.json Updated dialog property in updater section from false to true to enable update prompts.

Possibly related PRs

  • feat: qwen #4942: The changes in app/components/settings.tsx related to the introduction of new providers (ByteDance and Alibaba) are directly connected to the modifications in the same file in this PR, which also involves updates to the settings component.
  • support tauri-v2 #5518: The updates in src-tauri/tauri.conf.json regarding the configuration for the application may relate to the changes in the main PR that enhance user interactions and update management.
  • i18n: improve tw Traditional Chinese locale #5602: The updates to localization files in this PR may relate to the changes in the main PR that enhance user feedback and interaction, particularly in the context of update messages.

Suggested reviewers

  • Dogtiti

Poem

🐇 In the garden of code, where updates bloom,
A rabbit hops forth, dispelling the gloom.
With versions compared, and messages clear,
The path to new features is drawing near.
So click on the button, let updates take flight,
For a brighter tomorrow, all coded just right! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (1)
app/store/update.ts (1)

Line range hint 1-168: Summary: Enhanced update process with client update functionality.

The changes in this file introduce a new client update mechanism. While the additions are minimal, they potentially enhance the update process by adding a client-side update step after notifying about a new version.

Key points:

  1. New import for clientUpdate function.
  2. Integration of clientUpdate() in the version check process.

These changes appear to improve the update workflow. However, ensure that:

  1. The clientUpdate function is well-implemented and tested.
  2. This change doesn't introduce any unexpected behavior in the existing update process.
  3. Error handling is comprehensive throughout the update process.

Consider documenting the complete update flow, including this new client update step, to maintain clarity on the entire process for future development and maintenance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c5074f0 and bd9de4d.

📒 Files selected for processing (6)
  • app/components/settings.tsx (3 hunks)
  • app/global.d.ts (1 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/update.ts (2 hunks)
  • app/utils.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
app/global.d.ts (1)

29-35: LGTM! Consider documenting undefined types.

The addition of the updater property to the Window interface is well-structured and provides a clear API for managing application updates. The use of Promises for asynchronous operations is appropriate for update-related tasks.

However, there are a few types that are not defined in this file:

  • UpdateResult
  • UpdateStatusResult
  • UnlistenFn

To ensure these types are defined elsewhere in the project, please run the following script:

If these types are not found, consider adding their definitions or importing them from the appropriate module.

app/store/update.ts (2)

9-9: LGTM: New import for client update functionality.

The import statement for clientUpdate from "../utils" is correctly added. This suggests the introduction of a new utility function for handling client updates.


123-123: Approve with suggestions: clientUpdate() integration.

The addition of clientUpdate() after notifying about a new version is logical. However, consider the following improvements:

  1. Add error handling for the clientUpdate() call to manage potential failures gracefully.
  2. If clientUpdate() returns any value, consider using it to provide feedback or control the flow.
  3. Ensure this change doesn't disrupt the existing update process.

Consider refactoring the code as follows:

- clientUpdate();
+ try {
+   const result = await clientUpdate();
+   // Handle the result if necessary
+ } catch (error) {
+   console.error("Failed to update client:", error);
+   // Notify the user about the update failure
+ }

To verify the impact of this change, please run the following script:

✅ Verification successful

Approve with updates: clientUpdate() integration.

The clientUpdate() function already includes error handling within its implementation. However, consider the following improvements:

  1. If clientUpdate() returns any value, consider using it to provide feedback or control the flow.
  2. Ensure this change doesn't disrupt the existing update process.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other occurrences of clientUpdate and its implementation

# Search for other occurrences of clientUpdate
echo "Searching for other occurrences of clientUpdate:"
rg "clientUpdate" --type ts

# Display the implementation of clientUpdate
echo "\nDisplaying the implementation of clientUpdate:"
ast-grep --lang typescript --pattern $'function clientUpdate() {
  $$$
}'

Length of output: 1682

app/locales/cn.ts (1)

Line range hint 1-1024: Overall, the changes look good.

The additions to the Update section are appropriate and consistent with the existing structure. Once the typo is fixed, these changes will improve the user experience by providing clear feedback on the update process.

app/locales/en.ts (1)

210-211: LGTM: Improved user feedback for update operations

The addition of these localization strings for update success and failure is a good improvement. It enhances the user experience by providing clear feedback on the outcome of update operations. Once the typo is corrected, these changes are ready to be merged.

app/components/settings.tsx (2)

52-52: Import statements are correctly updated

New utility functions clientUpdate and semverCompare are properly imported.


588-588: Improved version comparison using semantic versioning

Changing from a simple string inequality to using semverCompare enhances the accuracy of version checking.

app/utils.ts Outdated Show resolved Hide resolved
app/locales/cn.ts Outdated Show resolved Hide resolved
app/locales/en.ts Outdated Show resolved Hide resolved
app/components/settings.tsx Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bd9de4d and a0d4a04.

📒 Files selected for processing (2)
  • app/locales/en.ts (1 hunks)
  • app/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/locales/en.ts
🧰 Additional context used

Comment on lines +390 to +411
export function clientUpdate() {
// this a wild for updating client app
return window.__TAURI__?.updater
.checkUpdate()
.then((updateResult) => {
if (updateResult.shouldUpdate) {
window.__TAURI__?.updater
.installUpdate()
.then((result) => {
showToast(Locale.Settings.Update.Success);
})
.catch((e) => {
console.error("[Install Update Error]", e);
showToast(Locale.Settings.Update.Failed);
});
}
})
.catch((e) => {
console.error("[Check Update Error]", e);
showToast(Locale.Settings.Update.Failed);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Improve error handling, user experience, and return value in the clientUpdate function.

While the function implements the basic update flow, there are several areas for improvement:

  1. Error Handling: Check if window.__TAURI__ is defined before accessing it to prevent runtime errors in non-Tauri environments.
  2. User Confirmation: Add user confirmation before installing updates for better user experience.
  3. Return Value: Consider returning a boolean indicating whether an update was installed.
  4. Async/Await: Use async/await for better readability and error handling.

Consider refactoring the function as follows:

export async function clientUpdate(): Promise<boolean> {
  if (!window.__TAURI__?.updater) {
    console.error("Tauri updater not available");
    return false;
  }

  try {
    const updateResult = await window.__TAURI__.updater.checkUpdate();
    if (updateResult.shouldUpdate) {
      const userConfirmed = await showConfirmDialog(Locale.Settings.Update.Confirm);
      if (userConfirmed) {
        await window.__TAURI__.updater.installUpdate();
        showToast(Locale.Settings.Update.Success);
        return true;
      }
    } else {
      showToast(Locale.Settings.Update.NoUpdate);
    }
  } catch (e) {
    console.error("[Update Error]", e);
    showToast(Locale.Settings.Update.Failed);
  }
  return false;
}

This refactored version addresses the issues mentioned above and improves overall robustness and user experience.

Note: You'll need to implement the showConfirmDialog function and add the necessary locale strings.

app/utils.ts Show resolved Hide resolved
Copy link
Contributor

Your build has completed!

Preview deployment

Copy link
Contributor

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


!shsh(img_vz_02fi_e40232e-432-404a-ashbsh-0a16a8431g)

Copy link
Member Author

这里有一个别人之前的升级视频

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Here is a video of someone else’s previous upgrade

Copy link
Member

Dogtiti commented Oct 14, 2024

可以基于这个改吧?

Copy link
Member

Dogtiti commented Oct 14, 2024

我看了pr

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Can it be modified based on this?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I read PR

Copy link
Member Author

当天这个pr,我已经按之前那个人的逻辑,改过一次,让测试,没测通。。。你再看看这个pr,你本地编译了,把自己版本改低一些看看有没有对应的弹窗之类的逻辑

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I had already modified the PR that day based on the logic of the previous person, so that it could be tested, but it didn’t pass. . . Take a look at this PR again. You have compiled it locally. Change your version to a lower version and see if there is any corresponding pop-up window or other logic.

@lloydzhou lloydzhou requested review from Dogtiti and removed request for Dogtiti October 14, 2024 09:12
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src-tauri/tauri.conf.json (1)

Line range hint 1-124: Consider improvements to versioning and update configuration

While the current configuration is functional, consider the following suggestions to enhance the update process and maintainability:

  1. Version Management:
    The version "2.15.4" is hardcoded in the configuration. Consider implementing a dynamic versioning system that can be updated automatically during the build process.

  2. Update Endpoints:
    The current setup uses a single GitHub releases endpoint. For improved reliability, consider adding fallback endpoints or implementing a CDN for distributing updates.

  3. Update Frequency:
    The configuration doesn't specify how often the application should check for updates. Consider adding a pubkey field to control update check frequency, balancing between keeping users up-to-date and avoiding excessive network requests.

  4. Staged Rollouts:
    For major updates, consider implementing a staged rollout mechanism to gradually release updates to users, allowing for early detection of potential issues.

Would you like assistance in implementing any of these suggestions?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2419083 and 87d85c1.

📒 Files selected for processing (1)
  • src-tauri/tauri.conf.json (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src-tauri/tauri.conf.json (1)

102-102: Enabling update dialogs: Verify user experience impact

The change from "dialog": false to "dialog": true in the updater section enables dialog prompts for application updates. This aligns with the AI-generated summary, which mentioned this specific change.

While this change improves user awareness of available updates, consider the following:

  1. Ensure that the update dialogs are properly localized to match the user's language settings.
  2. Verify that the dialog content provides clear and concise information about the update.
  3. Test the update process thoroughly to ensure a smooth user experience.

To verify the localization of update dialogs, run the following script:

This will help ensure that appropriate translations are available for update dialogs across different languages.

@Dogtiti Dogtiti merged commit cda4494 into ChatGPTNextWeb:main Oct 15, 2024
1 check failed
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.

4 participants