Skip to content

Conversation

Wxh16144
Copy link
Contributor

@Wxh16144 Wxh16144 commented Jun 13, 2025

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

有多个显示器屏幕下,应用程序首次启动后,将应用拖到副屏后,首次打开 setting 窗口位置会重新从主屏幕显示。这个 PR 主要解决这个体验问题。

📝 补充信息 | Additional Information

Summary by Sourcery

Improve multi-display window opening experience by centering child windows (e.g., settings, devtools) on the same monitor as their parent.

Enhancements:

  • Add parentIdentifier option to BrowserWindowOpts and use it to center windows on the same display as their parent
  • Configure devtools and settings windows with parentIdentifier 'chat' to ensure they open on the correct monitor

Copy link

vercel bot commented Jun 13, 2025

@Wxh16144 is attempting to deploy a commit to the LobeHub Community Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

sourcery-ai bot commented Jun 13, 2025

Reviewer's Guide

This PR introduces a parentIdentifier property and centers newly opened windows on the same display as their parent, ensuring sub-windows (like settings or devtools) appear on the correct monitor when first shown.

Sequence diagram for opening a new window

sequenceDiagram
    participant User as actor
    participant ChatWindow as "Chat Window"
    participant SettingsBrowser as "Settings Browser"
    participant BrowserManager
    participant ScreenAPI as "Electron Screen API"

    User->>ChatWindow: Clicks 'Open Settings'
    ChatWindow->>SettingsBrowser: show()
    activate SettingsBrowser
    SettingsBrowser->>SettingsBrowser: determineWindowPosition()
    SettingsBrowser->>BrowserManager: retrieveByIdentifier("chat")
    BrowserManager-->>SettingsBrowser: returns parent window instance
    SettingsBrowser->>ScreenAPI: getDisplayNearestPoint(parent window bounds)
    ScreenAPI-->>SettingsBrowser: returns correct display
    SettingsBrowser->>SettingsBrowser: setPosition(newX, newY)
    SettingsBrowser->>SettingsBrowser: browserWindow.show()
    deactivate SettingsBrowser
Loading

Updated class diagram for Browser and BrowserWindowOpts

classDiagram
    class BrowserWindowOpts {
        +identifier: string
        +keepAlive: boolean
        +parentIdentifier: string
        +path: string
        +showOnInit: boolean
        +title: string
    }

    class Browser {
        -options: BrowserWindowOpts
        +show()
        -determineWindowPosition()
    }

    Browser "1" -- "1" BrowserWindowOpts : uses
Loading

File-Level Changes

Change Details Files
Extend window options with parentIdentifier
  • Add parentIdentifier to BrowserWindowOpts interface
  • Include parentIdentifier in appBrowsers config for devtools and settings
Browser.ts
appBrowsers.ts
Implement determineWindowPosition in Browser.show
  • Invoke determineWindowPosition before showing a window
  • Retrieve parent window via browserManager
  • Use Electron’s screen API to find nearest display and its work area
  • Calculate centered x,y within work area and call setPosition
Browser.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 13, 2025
@lobehubbot
Copy link
Member

👍 @Wxh16144

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@dosubot dosubot bot added the 💄 Design Design an style | 样式问题 label Jun 13, 2025
Copy link
Contributor

@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 @Wxh16144 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `apps/desktop/src/main/core/Browser.ts:163` </location>
<code_context>
+    const { parentIdentifier } = this.options;
+
+    if (parentIdentifier) {
+      // todo: fix ts type
+      const parentWin = this.app.browserManager.retrieveByIdentifier(parentIdentifier as any);
+      if (parentWin) {
</code_context>

<issue_to_address>
Avoid casting to any by updating retrieveByIdentifier typing

Consider updating retrieveByIdentifier or BrowserManager to accept a string and return a typed Browser instance, rather than casting parentIdentifier to any.

Suggested implementation:

```typescript
    if (parentIdentifier) {
      const parentWin = this.app.browserManager.retrieveByIdentifier(parentIdentifier);
      if (parentWin) {

```

You must also update the `retrieveByIdentifier` method in the `BrowserManager` class (likely in `apps/desktop/src/main/core/BrowserManager.ts` or similar) to have a signature like:
```ts
retrieveByIdentifier(identifier: string): Browser | undefined
```
and ensure it returns a `Browser` instance or `undefined` as appropriate. This will allow you to remove the `as any` cast and have proper type safety.
</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.

const { parentIdentifier } = this.options;

if (parentIdentifier) {
// todo: fix ts type
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Avoid casting to any by updating retrieveByIdentifier typing

Consider updating retrieveByIdentifier or BrowserManager to accept a string and return a typed Browser instance, rather than casting parentIdentifier to any.

Suggested implementation:

    if (parentIdentifier) {
      const parentWin = this.app.browserManager.retrieveByIdentifier(parentIdentifier);
      if (parentWin) {

You must also update the retrieveByIdentifier method in the BrowserManager class (likely in apps/desktop/src/main/core/BrowserManager.ts or similar) to have a signature like:

retrieveByIdentifier(identifier: string): Browser | undefined

and ensure it returns a Browser instance or undefined as appropriate. This will allow you to remove the as any cast and have proper type safety.

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.84%. Comparing base (a7d254d) to head (c689aa0).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #8176     +/-   ##
=========================================
  Coverage   87.84%   87.84%             
=========================================
  Files         836      836             
  Lines       62148    62148             
  Branches     5663     3932   -1731     
=========================================
  Hits        54596    54596             
  Misses       7552     7552             
Flag Coverage Δ
app 87.84% <ø> (ø)
server 95.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arvinxx arvinxx changed the title 💄chore: enhance the multi-display window opening experience 🐛 fix: enhance the multi-display window opening experience Jun 15, 2025
Copy link

vercel bot commented Jun 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2025 5:59pm

@arvinxx arvinxx merged commit b132e66 into lobehub:main Jun 17, 2025
26 of 29 checks passed
@lobehubbot
Copy link
Member

❤️ Great PR @Wxh16144 ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

Copy link
Contributor

gru-agent bot commented Jun 17, 2025

⏳ Processing in progress

github-actions bot pushed a commit that referenced this pull request Jun 17, 2025
### [Version&nbsp;1.94.11](v1.94.10...v1.94.11)
<sup>Released on **2025-06-17**</sup>

#### 🐛 Bug Fixes

- **misc**: Enhance the multi-display window opening experience.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Enhance the multi-display window opening experience, closes [#8176](#8176) ([b132e66](b132e66))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

🎉 This PR is included in version 1.94.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to jaworldwideorg/OneJA-Bot that referenced this pull request Jun 18, 2025
### [Version&nbsp;1.94.4](v1.94.3...v1.94.4)
<sup>Released on **2025-06-18**</sup>

#### 🐛 Bug Fixes

- **misc**: Enhance the multi-display window opening experience.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Enhance the multi-display window opening experience, closes [lobehub#8176](https://github.com/jaworldwideorg/OneJA-Bot/issues/8176) ([b132e66](b132e66))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
AirboZH pushed a commit to yuanze-dev/lobe-chat that referenced this pull request Jul 9, 2025
AirboZH pushed a commit to yuanze-dev/lobe-chat that referenced this pull request Jul 9, 2025
### [Version&nbsp;1.94.11](lobehub/lobe-chat@v1.94.10...v1.94.11)
<sup>Released on **2025-06-17**</sup>

#### 🐛 Bug Fixes

- **misc**: Enhance the multi-display window opening experience.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Enhance the multi-display window opening experience, closes [lobehub#8176](lobehub#8176) ([b132e66](lobehub@b132e66))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
bbbugg pushed a commit to bbbugg/lobe-chat that referenced this pull request Aug 14, 2025
bbbugg pushed a commit to bbbugg/lobe-chat that referenced this pull request Aug 14, 2025
### [Version&nbsp;1.94.11](lobehub/lobe-chat@v1.94.10...v1.94.11)
<sup>Released on **2025-06-17**</sup>

#### 🐛 Bug Fixes

- **misc**: Enhance the multi-display window opening experience.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Enhance the multi-display window opening experience, closes [lobehub#8176](lobehub#8176) ([7a638f7](lobehub@7a638f7))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💄 Design Design an style | 样式问题 released size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants