-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(ui): enable windows mica effect #13476
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
Changes from all commits
f766e31
f01616f
a45f13f
c44d5e9
92ec3c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { afterEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const originalGetSystemVersion = process.getSystemVersion | ||
|
|
||
| async function loadWindowUtil({ isWin, systemVersion = '' }: { isWin: boolean; systemVersion?: string }) { | ||
| vi.resetModules() | ||
| vi.doMock('../../constant', () => ({ | ||
| isDev: false, | ||
| isWin | ||
| })) | ||
|
|
||
| const getSystemVersionMock = vi.fn(() => systemVersion) | ||
| Object.defineProperty(process, 'getSystemVersion', { | ||
| value: getSystemVersionMock, | ||
| configurable: true | ||
| }) | ||
|
|
||
| const windowUtil = await import('../windowUtil') | ||
| return { ...windowUtil } | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| vi.resetModules() | ||
| vi.restoreAllMocks() | ||
| vi.doUnmock('../../constant') | ||
|
|
||
| Object.defineProperty(process, 'getSystemVersion', { | ||
| value: originalGetSystemVersion, | ||
| configurable: true | ||
| }) | ||
| }) | ||
|
|
||
| describe('getWindowsBackgroundMaterial', () => { | ||
| it('returns mica on Windows 11 22H2 and newer', async () => { | ||
| const { getWindowsBackgroundMaterial } = await loadWindowUtil({ | ||
| isWin: true, | ||
| systemVersion: '10.0.22621' | ||
| }) | ||
|
|
||
| expect(getWindowsBackgroundMaterial()).toBe('mica') | ||
| }) | ||
|
|
||
| it('returns undefined below the Windows 11 22H2 build threshold', async () => { | ||
| const { getWindowsBackgroundMaterial } = await loadWindowUtil({ | ||
| isWin: true, | ||
| systemVersion: '10.0.22000' | ||
| }) | ||
|
|
||
| expect(getWindowsBackgroundMaterial()).toBeUndefined() | ||
| }) | ||
|
|
||
| it('returns undefined when the system version cannot be parsed', async () => { | ||
| const { getWindowsBackgroundMaterial } = await loadWindowUtil({ | ||
| isWin: true, | ||
| systemVersion: 'Windows 11' | ||
| }) | ||
|
|
||
| expect(getWindowsBackgroundMaterial()).toBeUndefined() | ||
| }) | ||
|
|
||
| it('returns undefined on non-Windows platforms', async () => { | ||
| const { getWindowsBackgroundMaterial } = await loadWindowUtil({ | ||
| isWin: false, | ||
| systemVersion: '10.0.22621' | ||
| }) | ||
|
|
||
| expect(getWindowsBackgroundMaterial()).toBeUndefined() | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,9 @@ import type { BrowserWindow } from 'electron' | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| import { isDev, isWin } from '../constant' | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // see: https://www.electronjs.org/zh/docs/latest/api/base-window#winsetbackgroundmaterialmaterial-windows | ||||||||||||||||||||||
| const WINDOWS_11_22H2_BUILD = 22621 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function isTilingWindowManager() { | ||||||||||||||||||||||
| if (process.platform === 'darwin') { | ||||||||||||||||||||||
| return false | ||||||||||||||||||||||
|
|
@@ -74,4 +77,19 @@ export const replaceDevtoolsFont = (browserWindow: BrowserWindow) => { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const isWindowsMicaSupported = () => { | ||||||||||||||||||||||
| if (!isWin) { | ||||||||||||||||||||||
| return false | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const systemVersion = process.getSystemVersion() | ||||||||||||||||||||||
| const buildNumber = Number.parseInt(systemVersion.split('.')[2] ?? '', 10) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return Number.isFinite(buildNumber) && buildNumber >= WINDOWS_11_22H2_BUILD | ||||||||||||||||||||||
|
Comment on lines
+85
to
+88
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Only checking the build number while ignoring A more defensive approach would be to compare the full version tuple:
Suggested change
Not blocking — totally fine to keep as-is given Microsoft's current versioning. |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export const getWindowsBackgroundMaterial = () => { | ||||||||||||||||||||||
| return isWindowsMicaSupported() ? 'mica' : undefined | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export { isTilingWindowManager } | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some test cases for
getWindowsBackgroundMaterial?isWindowsMicaSupportedis never used by external module, so it should not be exported.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed unnecessary export
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some tests, not sure if they are necessary tho. I feel the main problem with current implementation is the way we get
buildNumberis not very robust as @kangfenmao pointed out. But I didn't find a better way.With that saying, worst case scenario, you simply lose Mica effect, nothing will break. Because: