Skip to content

Feature/jsbridge#5

Open
SUGE2016 wants to merge 20 commits intoECNU:mainfrom
SUGE2016:feature/jsbridge
Open

Feature/jsbridge#5
SUGE2016 wants to merge 20 commits intoECNU:mainfrom
SUGE2016:feature/jsbridge

Conversation

@SUGE2016
Copy link
Contributor

@SUGE2016 SUGE2016 commented Feb 6, 2026

增加了web版本探测和更新提示功能

XU Gang and others added 18 commits January 12, 2026 12:01
…d macOS applications

- Created a new workflow to automate the build process for Windows and macOS using Electron.
- Configured jobs for building, artifact uploading, and release creation triggered by version tags.
- Implemented caching for Node.js dependencies to optimize build times.
ci: Add GitHub Actions workflow for building and releasing Windows an…
- Modified the icon generation script to include a new size (512px) for better resolution options.
- Updated the application icon file to reflect the changes.
- Introduced a new build job for Linux in the GitHub Actions workflow, enabling the creation of .deb packages.
- Updated the application icon to use a new PNG file for consistency across platforms.
- Adjusted package.json to include Linux-specific build configurations and artifact naming.
…izes

- Changed the author field in package.json to an object format with name and email.
- Reduced the icon generation sizes in svg-to-ico.js by removing the 512px option.
- Updated application icons to reflect recent changes.
…ld process

- Added 'fail_on_unmatched_files: false' to the build job configuration in build.yml to prevent failures due to unmatched files during the build process.
- Updated the artifact path in the GitHub Actions workflow to include architecture-specific naming for macOS builds, ensuring the correct .dmg files are uploaded.
- Updated package.json to reference a new icons directory for application icons.
- Added multiple icon sizes (16x16, 32x32, 48x48, 64x64, 128x128, 256x256, 512x512) for better resolution support.
- Introduced scripts for generating PNG icons from SVG and converting SVG to ICO format, improving the build process for Linux and macOS.
- Added a refresh button with a badge indicator for available updates in index.html.
- Enhanced main.js to check for web version updates and notify the renderer process.
- Introduced a command line argument for forcing UAT mode and updated UAT handling logic.
- Implemented a JSBridge in preload.js to facilitate communication between the web and main process.
@gemini-code-assist
Copy link

Summary of Changes

Hello @SUGE2016, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求通过集成强大的 JSBridge 显著升级了 Electron 桌面应用程序,实现了网页视图与原生 Electron 环境之间的无缝交互。这种集成支持了关键功能,例如自动检测新版网页应用程序以及用户友好的更新提示。此外,此 PR 优化了应用程序的构建过程,引入了对 Linux 包的专用支持,并简化了跨不同操作系统的图标生成,同时提供了更灵活的 UAT 环境激活方式。

Highlights

  • JSBridge 实现: 在 preload.js 中实现了新的 JSBridge (_tx 对象),以促进网页内容和 Electron 主进程之间的双向通信。
  • Web 版本更新检测: 应用程序现在可以检测到服务器上是否有可用的新版网页内容,并使用语义版本比较来判断是否需要更新。
  • 更新通知界面: 在 index.html 中引入了视觉徽章(红点)和更新的刷新按钮工具提示,以直观地通知用户有可用的网页更新。
  • 改进的构建配置: package.json 现在包含 Linux .deb 构建的配置,并使用新脚本 (svg-to-png.js, generate-linux-icons.js) 生成平台特定的图标,提升了跨平台支持。
  • 灵活的 UAT 模式激活: 增加了 --uat 命令行参数以强制启用 UAT 模式,增强了开发和测试工作流程的灵活性。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • build/chatecnu.svg
    • 更新了应用程序的主 SVG 图标,采用了新设计并调整了尺寸。
  • index.html
    • 添加了 .refresh-wrapper 的 CSS 样式,用于刷新按钮容器。
    • 将刷新按钮包裹在新的 div.refresh-wrapper 中,并添加了 div#refresh-badge(一个红点指示器)用于更新通知。
    • 实现了客户端逻辑,在点击刷新按钮时隐藏 refresh-badge,并在通过 IPC 检测到新版网页时显示它并更新刷新按钮的工具提示。
  • main.js
    • 引入了 forceUat 命令行参数,用于灵活激活 UAT 模式。
    • 实现了 compareVersions 工具函数,用于语义版本比较。
    • 添加了 checkWebVersionUpdate 函数,用于从服务器获取最新网页版本,并在有更新时通知渲染器进程。
    • 设置了 ipcMain.on('tx:status'),用于接收渲染器进程的网页版本报告并触发更新检查。
    • 添加了 emitToWeb 函数,用于从主进程向网页内容发送事件。
  • package-lock.json
    • 项目版本从 0.1.31 更新到 0.1.40
  • package.json
    • 项目版本更新到 0.1.40
    • 添加了 dev:uat 脚本,用于在 UAT 模式下运行。
    • author 字段重构为对象格式。
    • 更新了 Windows 图标路径为 build/icon.png
    • 添加了 Linux 构建配置,用于生成 .deb 包,并指定了图标路径和类别。
  • preload.js
    • 重写了文件以实现 JSBridge,向网页内容暴露了 _tx.status_tx.on
    • 建立了 IPC 通信,用于从网页向主进程报告状态以及从主进程向网页分发事件。
  • tools/generate-linux-icons.js
    • 新增脚本,用于从源 PNG 生成多尺寸的 Linux PNG 图标。
  • tools/svg-to-ico.js
    • 更改了 .ico 文件的默认输出路径为 ../build/chatecnu.ico
  • tools/svg-to-png.js
    • 新增脚本,用于将 SVG 图标转换为 PNG 格式,主要用于 Mac 和 Linux 构建。
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/build.yml
Activity
  • SUGE2016 创建了此拉取请求,旨在增加 Web 版本探测和更新提示功能。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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

本次 PR 增加了 Web 版本探测和更新提示功能,并通过 JSBridge 实现了主进程与渲染进程的通信。此外,还更新了图标资源和构建脚本,增加了对 Linux 平台的支持。整体实现思路清晰,代码质量较高。我提出了两点建议,主要关于代码可维护性和潜在的内存泄漏风险,希望能帮助改进代码。

Comment on lines +16 to +29
contextBridge.exposeInMainWorld('_tx', {
// 网页 → 客户端:告知客户端某个 key 的当前值
status: (key, value) => {
ipcRenderer.send('tx:status', key, value);
},

// 客户端 → 网页:注册事件监听
on: (event, callback) => {
if (!listeners.has(event)) {
listeners.set(event, []);
}
listeners.get(event).push(callback);
}
});

Choose a reason for hiding this comment

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

high

_tx.on 方法用于注册事件监听器,但目前缺少一个相应的方法来注销监听器。如果网页端的组件(例如 React 或 Vue 组件)在生命周期中多次注册监听器而没有清理,这可能会导致内存泄漏和重复的事件回调。建议增加一个 off 方法来移除不再需要的监听器。

contextBridge.exposeInMainWorld('_tx', {
  // 网页 → 客户端:告知客户端某个 key 的当前值
  status: (key, value) => {
    ipcRenderer.send('tx:status', key, value);
  },

  // 客户端 → 网页:注册事件监听
  on: (event, callback) => {
    if (!listeners.has(event)) {
      listeners.set(event, []);
    }
    listeners.get(event).push(callback);
  },

  // 客户端 → 网页:注销事件监听
  off: (event, callback) => {
    const callbacks = listeners.get(event);
    if (callbacks) {
      const index = callbacks.indexOf(callback);
      if (index > -1) {
        callbacks.splice(index, 1);
      }
    }
  }
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已增加off

main.js Outdated
Comment on lines +241 to +242
const isUatActive = store.get('uatActive') && store.get('uatMode');
const baseUrl = (forceUat || isUatActive) ? URL_UAT : URL_PRODUCTION;

Choose a reason for hiding this comment

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

medium

这部分用于判断是否使用 UAT 环境的逻辑是正确的,但是变量 isUatActive 在文件中的定义和使用存在不一致性,可能会引起混淆。在 createWindow 函数中(74行),isUatActive 仅代表 store.get('uatActive'),而在这里它代表 store.get('uatActive') && store.get('uatMode')。为了提高代码的可读性和可维护性,建议统一逻辑表达方式,使其更加清晰。

Suggested change
const isUatActive = store.get('uatActive') && store.get('uatMode');
const baseUrl = (forceUat || isUatActive) ? URL_UAT : URL_PRODUCTION;
const shouldUseUat = forceUat || (store.get('uatMode') && store.get('uatActive'));
const baseUrl = shouldUseUat ? URL_UAT : URL_PRODUCTION;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经修复

XU Gang added 2 commits February 6, 2026 11:01
…l in preload.js

- Updated the logic in main.js for determining the API base URL to align with createWindow logic.
- Added an 'off' method in preload.js to remove event listeners, preventing potential memory leaks.
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