Skip to content

๐Ÿ’„ style: Fix win electron style #8439

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

canisminor1990
Copy link
Member

@canisminor1990 canisminor1990 commented Jul 15, 2025

๐Ÿ’ป ๅ˜ๆ›ด็ฑปๅž‹ | Change Type

  • โœจ feat
  • ๐Ÿ› fix
  • โ™ป๏ธ refactor
  • ๐Ÿ’„ style
  • ๐Ÿ‘ท build
  • โšก๏ธ perf
  • ๐Ÿ“ docs
  • ๐Ÿ”จ chore

๐Ÿ”€ ๅ˜ๆ›ด่ฏดๆ˜Ž | Description of Change

TODO

image

๐Ÿ“ ่กฅๅ……ไฟกๆฏ | Additional Information

Copy link
Contributor

sourcery-ai bot commented Jul 15, 2025

Reviewer's Guide

This PR restructures the Windows title bar component by replacing detailed styles and interactive markup with a static placeholder, enhances Electron Browser window creation by introducing a titleBarOverlay, streamlining background material configuration, and adding robust visual effects methods, and refactors tooltip integration by consolidating Tooltip props directly into ActionIcon components.

Class diagram for updated Electron Browser visual effects methods

classDiagram
    class Browser {
        +applyVisualEffects()
        +reapplyVisualEffects()
    }
    Browser : -_browserWindow
    Browser : +retrieveOrInitialize()
    Browser : +getWindowsVersion()
    Browser : +identifier
    Browser : +logger
    Browser : +applyVisualEffects() // now checks isDestroyed and uses try/catch
    Browser : +reapplyVisualEffects() // new method, calls applyVisualEffects if Windows 11
Loading

Class diagram for WinControl component simplification

classDiagram
    class WinControl {
        +render()
    }
    %% Previously: used useStyles, interactive window controls
    %% Now: returns static <div style={{ width: 132 }} />
Loading

File-Level Changes

Change Details Files
Simplify WinControl component implementation
  • Comment out custom useStyles definitions and style rules
  • Remove icon buttons for minimize, maximize, and close actions
  • Replace dynamic markup with a static div of fixed width
src/features/ElectronTitlebar/WinControl/index.tsx
Enhance Browser window creation and visual effects handling
  • Add titleBarOverlay configuration in window options
  • Remove legacy backgroundMaterial/vibrancy and backgroundColor settings
  • Refine applyVisualEffects with isDestroyed check, error handling, and detailed logs
  • Introduce reapplyVisualEffects method for manual effect reapplication
apps/desktop/src/main/core/Browser.ts
Refactor tooltip integration for ActionIcon components
  • Eliminate separate Tooltip wrappers around ActionIcon
  • Add title and tooltipProps directly to ActionIcon props
  • Standardize tooltip placement and hotkey display
src/app/[variants]/(main)/chat/(workspace)/_layout/Desktop/ChatHeader/HeaderAction.tsx
src/app/[variants]/(main)/chat/(workspace)/features/SettingButton.tsx
src/app/[variants]/(main)/chat/(workspace)/features/ShareButton/index.tsx
src/app/[variants]/(main)/chat/@session/_layout/Desktop/SessionHeader.tsx

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

Copy link

vercel bot commented Jul 15, 2025

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Comments Updated (UTC)
lobe-chat-database โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jul 18, 2025 9:27am
lobe-chat-preview โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jul 18, 2025 9:27am

@lobehubbot
Copy link
Member

๐Ÿ‘ @canisminor1990

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

gru-agent bot commented Jul 15, 2025

TestGru Assignment

Summary

Link CommitId Status Reason
Detail eccc804 ๐Ÿšซ Skipped No files need to be tested {"apps/desktop/src/main/core/Browser.ts":"File path does not match include patterns.","src/app/[variants]/(main)/chat/(workspace)/_layout/Desktop/ChatHeader/HeaderAction.tsx":"File path does not match include patterns.","src/app/[variants]/(main)/chat/(workspace)/features/SettingButton.tsx":"File path does not match include patterns.","src/app/[variants]/(main)/chat/(workspace)/features/ShareButton/index.tsx":"File path does not match include patterns.","src/app/[variants]/(main)/chat/@session/_layout/Desktop/SessionHeader.tsx":"File path does not match include patterns.","src/features/ElectronTitlebar/WinControl/index.tsx":"File path does not match include patterns."}

History Assignment

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. ๐Ÿ’„ Design Design an style | ๆ ทๅผ้—ฎ้ข˜ labels Jul 15, 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 @canisminor1990 - I've reviewed your changes - here's some feedback:

  • Remove large blocks of commented-out code in WinControl and Browser or extract them behind a feature flag to keep the implementation clear and maintainable.
  • Annotate or add a TODO explaining why WinControl now only renders a fixed-width
    so future readers understand the placeholder intent.
  • Consider syncing the hardcoded titleBarOverlay.height (30) with your existing TITLE_BAR_HEIGHT constant to avoid mismatched layouts on Windows.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Remove large blocks of commented-out code in WinControl and Browser or extract them behind a feature flag to keep the implementation clear and maintainable.
- Annotate or add a TODO explaining why WinControl now only renders a fixed-width <div> so future readers understand the placeholder intent.
- Consider syncing the hardcoded titleBarOverlay.height (30) with your existing TITLE_BAR_HEIGHT constant to avoid mismatched layouts on Windows.

## Individual Comments

### Comment 1
<location> `src/features/ElectronTitlebar/WinControl/index.tsx:56` </location>
<code_context>
-      </div>
-    </div>
-  );
+  return <div style={{ width: 132 }} />;
+
+  // const { styles } = useStyles();
</code_context>

<issue_to_address>
Returning a static width div may impact layout and accessibility.

If this is a temporary placeholder, add a clear TODO or use a more descriptive placeholder to prevent confusion for users and maintainers.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
  return <div style={{ width: 132 }} />;

  // const { styles } = useStyles();
=======
  // TODO: Replace this placeholder with the actual window control implementation.
  // This is a temporary placeholder to maintain layout.
  return (
    <div
      style={{ width: 132, height: 24, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'transparent' }}
      role="presentation"
      aria-hidden="true"
      tabIndex={-1}
      data-testid="wincontrol-placeholder"
    >
      {/* Window controls will be implemented here */}
      <span style={{ fontSize: 12, color: '#888' }}>Window Controls Placeholder</span>
    </div>
  );

  // const { styles } = useStyles();
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/features/ElectronTitlebar/WinControl/index.tsx:1` </location>
<code_context>
+// const useStyles = createStyles(({ css, cx, token }) => {
</code_context>

<issue_to_address>
Commenting out the entire styling logic may lead to inconsistent UI.

If this change is temporary, confirm that the component and application still function correctly without these styles.
</issue_to_address>

### Comment 3
<location> `apps/desktop/src/main/core/Browser.ts:249` </location>
<code_context>
-          }
-        : {}),
       autoHideMenuBar: true,
-      backgroundColor: '#00000000',
+
       frame: false,
</code_context>

<issue_to_address>
Removing the transparent background color may affect window appearance.

Please verify that removing backgroundColor does not result in an unintended opaque window or loss of transparency.
</issue_to_address>

### Comment 4
<location> `apps/desktop/src/main/core/Browser.ts:439` </location>
<code_context>
-      this._browserWindow?.setBackgroundMaterial(isDarkMode ? 'mica' : 'acrylic');
-      this._browserWindow?.setVibrancy('under-window');
+
+      try {
+        // Apply background material
+        this._browserWindow.setBackgroundMaterial('mica');
+        logger.debug(
+          `[${this.identifier}] Visual effects applied successfully (dark mode: ${isDarkMode})`,
+        );
+      } catch (error) {
+        logger.error(`[${this.identifier}] Failed to apply visual effects:`, error);
+      }
</code_context>

<issue_to_address>
Catching errors when applying visual effects increases stability.

Consider if errors should be communicated to the user or if a retry mechanism is appropriate, rather than only logging them.

Suggested implementation:

```typescript
      const applyEffects = (retry = false) => {
        try {
          // Apply background material
          this._browserWindow.setBackgroundMaterial('mica');
          logger.debug(
            `[${this.identifier}] Visual effects applied successfully (dark mode: ${isDarkMode})`,
          );
        } catch (error) {
          logger.error(`[${this.identifier}] Failed to apply visual effects${retry ? ' (retry)' : ''}:`, error);
          if (!retry) {
            // Retry once after a short delay
            setTimeout(() => applyEffects(true), 500);
          } else {
            // Notify user after retry fails
            if (typeof showErrorNotification === 'function') {
              showErrorNotification('Failed to apply visual effects to the window. Some UI features may not display as intended.');
            }
          }
        }
      };
      applyEffects();

```

- This code assumes a `showErrorNotification` function is available in scope to notify the user. If your app uses a different notification system, replace `showErrorNotification` with the appropriate function.
- If you want to customize the retry logic (e.g., more retries, different delay), adjust the `applyEffects` function accordingly.
</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 on lines +56 to +58
return <div style={{ width: 132 }} />;

// const { styles } = useStyles();
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Returning a static width div may impact layout and accessibility.

If this is a temporary placeholder, add a clear TODO or use a more descriptive placeholder to prevent confusion for users and maintainers.

Suggested change
return <div style={{ width: 132 }} />;
// const { styles } = useStyles();
// TODO: Replace this placeholder with the actual window control implementation.
// This is a temporary placeholder to maintain layout.
return (
<div
style={{ width: 132, height: 24, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'transparent' }}
role="presentation"
aria-hidden="true"
tabIndex={-1}
data-testid="wincontrol-placeholder"
>
{/* Window controls will be implemented here */}
<span style={{ fontSize: 12, color: '#888' }}>Window Controls Placeholder</span>
</div>
);
// const { styles } = useStyles();

Comment on lines +1 to +10
// const useStyles = createStyles(({ css, cx, token }) => {
// const icon = css`
// display: flex;
// align-items: center;
// justify-content: center;
//
// width: ${TITLE_BAR_HEIGHT * 1.2}px;
// min-height: ${TITLE_BAR_HEIGHT}px;
//
// color: ${token.colorTextSecondary};
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Commenting out the entire styling logic may lead to inconsistent UI.

If this change is temporary, confirm that the component and application still function correctly without these styles.

autoHideMenuBar: true,
backgroundColor: '#00000000',
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Removing the transparent background color may affect window appearance.

Please verify that removing backgroundColor does not result in an unintended opaque window or loss of transparency.

Comment on lines 439 to 445
try {
// Apply background material
this._browserWindow.setBackgroundMaterial('mica');
logger.debug(
`[${this.identifier}] Visual effects applied successfully (dark mode: ${isDarkMode})`,
);
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Catching errors when applying visual effects increases stability.

Consider if errors should be communicated to the user or if a retry mechanism is appropriate, rather than only logging them.

Suggested implementation:

      const applyEffects = (retry = false) => {
        try {
          // Apply background material
          this._browserWindow.setBackgroundMaterial('mica');
          logger.debug(
            `[${this.identifier}] Visual effects applied successfully (dark mode: ${isDarkMode})`,
          );
        } catch (error) {
          logger.error(`[${this.identifier}] Failed to apply visual effects${retry ? ' (retry)' : ''}:`, error);
          if (!retry) {
            // Retry once after a short delay
            setTimeout(() => applyEffects(true), 500);
          } else {
            // Notify user after retry fails
            if (typeof showErrorNotification === 'function') {
              showErrorNotification('Failed to apply visual effects to the window. Some UI features may not display as intended.');
            }
          }
        }
      };
      applyEffects();
  • This code assumes a showErrorNotification function is available in scope to notify the user. If your app uses a different notification system, replace showErrorNotification with the appropriate function.
  • If you want to customize the retry logic (e.g., more retries, different delay), adjust the applyEffects function accordingly.

Copy link

codecov bot commented Jul 15, 2025

Codecov Report

All modified and coverable lines are covered by tests โœ…

Project coverage is 85.31%. Comparing base (7dd65f0) to head (34f3fbe).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #8439     +/-   ##
=========================================
  Coverage   85.31%   85.31%             
=========================================
  Files         908      908             
  Lines       68519    68519             
  Branches     6514     4431   -2083     
=========================================
  Hits        58455    58455             
  Misses      10064    10064             
Flag Coverage ฮ”
app 85.31% <รธ> (รธ)
server 96.26% <รธ> (รธ)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
๐Ÿ’„ Design Design an style | ๆ ทๅผ้—ฎ้ข˜ size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
3 participants