Skip to content

Commit

Permalink
fix: remove windows under blur and ensure main window in the screen b…
Browse files Browse the repository at this point in the history
…ounds

Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 20, 2024
1 parent be3b2e7 commit d772343
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 75 deletions.
105 changes: 53 additions & 52 deletions apps/main/src/tipc/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,58 +71,59 @@ export const appRoute = {
case "maximum": {
// FIXME: this is a electron bug, see https://github.com/RSSNext/Follow/issues/231
// So in this way we use a workaround to fix it, that is manually resize the window
if (isWindows11) {
const display = screen.getDisplayMatching(window.getBounds())
const size = display.workAreaSize

const isMaximized = size.height === window.getSize()[1]

const storeKey = Symbol.for("maximized")
if (isMaximized) {
const stored = window[storeKey]
if (!stored) return

window.setResizable(true)
window.setMovable(true)

window.setBounds(
{
width: stored.size[0],
height: stored.size[1],
x: stored.position[0],
y: stored.position[1],
},
true,
)

delete window[storeKey]
} else {
const currentWindowSize = window.getSize()
const currentWindowPosition = window.getPosition()
window[storeKey] = {
size: currentWindowSize,
position: currentWindowPosition,
}

// Maually Resize
const { workArea } = display

window.setBounds(
{
x: workArea.x,
y: workArea.y,
width: workArea.width,
height: workArea.height,
},
true,
)

window.setResizable(false)
window.setMovable(false)
}

return
}
// Comemnt the manually handle logic and disable backgroundMaterial for now
// if (isWindows11) {
// const display = screen.getDisplayMatching(window.getBounds())
// const size = display.workAreaSize

// const isMaximized = size.height === window.getSize()[1]

// const storeKey = Symbol.for("maximized")
// if (isMaximized) {
// const stored = window[storeKey]
// if (!stored) return

// window.setResizable(true)
// window.setMovable(true)

// window.setBounds(
// {
// width: stored.size[0],
// height: stored.size[1],
// x: stored.position[0],
// y: stored.position[1],
// },
// true,
// )

// delete window[storeKey]
// } else {
// const currentWindowSize = window.getSize()
// const currentWindowPosition = window.getPosition()
// window[storeKey] = {
// size: currentWindowSize,
// position: currentWindowPosition,
// }

// // Maually Resize
// const { workArea } = display

// window.setBounds(
// {
// x: workArea.x,
// y: workArea.y,
// width: workArea.width,
// height: workArea.height,
// },
// true,
// )

// window.setResizable(false)
// window.setMovable(false)
// }

// return
// }

if (window.isMaximized()) {
window.unmaximize()
Expand Down
48 changes: 31 additions & 17 deletions apps/main/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { is } from "@electron-toolkit/utils"
import { callGlobalContextMethod } from "@follow/shared/bridge"
import { imageRefererMatches } from "@follow/shared/image"
import type { BrowserWindowConstructorOptions } from "electron"
import { BrowserWindow, Menu, shell } from "electron"
import { BrowserWindow, Menu, screen,shell } from "electron"

import { isDev, isMacOS, isWindows11 } from "./env"
import { getIconPath } from "./helper"
Expand Down Expand Up @@ -64,9 +64,10 @@ export function createWindow(
icon: getIconPath(),

titleBarStyle: "hidden",
backgroundMaterial: isWindows11 ? "mica" : undefined,
// Electron material bug, comment this for now
// backgroundMaterial: isWindows11 ? "mica" : undefined,

frame: true,
maximizable: !isWindows11,
} as Electron.BrowserWindowConstructorOptions)
break
}
Expand All @@ -82,18 +83,15 @@ export function createWindow(
...configs,
})

function refreshBound(timeout = 0) {
setTimeout(() => {
const mainWindow = getMainWindow()
if (!mainWindow) return
// FIXME: workaround for theme bug in full screen mode
const size = mainWindow.getSize()
mainWindow.setSize(size[0] + 1, size[1] + 1)
mainWindow.setSize(size[0], size[1])
}, timeout)
}

window.on("leave-html-full-screen", () => {
function refreshBound(timeout = 0) {
setTimeout(() => {
// FIXME: workaround for theme bug in full screen mode
const size = window?.getSize()
window?.setSize(size[0] + 1, size[1] + 1)
window?.setSize(size[0], size[1])
}, timeout)
}
// To solve the vibrancy losing issue when leaving full screen mode
// @see https://github.com/toeverything/AFFiNE/blob/280e24934a27557529479a70ab38c4f5fc65cb00/packages/frontend/electron/src/main/windows-manager/main-window.ts:L157
refreshBound()
Expand Down Expand Up @@ -193,7 +191,6 @@ export function createWindow(

return window
}

export const createMainWindow = () => {
const storeKey = "windowState"
const windowState = store.get(storeKey) as {
Expand All @@ -202,12 +199,29 @@ export const createMainWindow = () => {
x: number
y: number
} | null
const primaryDisplay = screen.getPrimaryDisplay()
const { width: screenWidth, height: screenHeight } = primaryDisplay.workAreaSize

// Ensure the window is within screen bounds
const ensureInBounds = (value: number, size: number, max: number) => {
if (value + size > max) {
return Math.max(0, max - size)
}
return Math.max(0, value)
}

const width = windowState?.width || 1200
const height = windowState?.height || 900
const x =
windowState?.x !== undefined ? ensureInBounds(windowState.x, width, screenWidth) : undefined
const y =
windowState?.y !== undefined ? ensureInBounds(windowState.y, height, screenHeight) : undefined

const window = createWindow({
width: windowState?.width || 1200,
height: windowState?.height || 900,
x: windowState?.x,
y: windowState?.y,
x,
y,
minWidth: 1024,
minHeight: 500,
})
Expand Down
13 changes: 7 additions & 6 deletions apps/renderer/src/components/ui/background/WindowUnderBlur.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const Noop: Props = ({ children, className, ...rest }) => (
</div>
)

const Win32Material: Props = ({ className, children, ...rest }) => (
<div className={cn("bg-transparent", className)} {...rest}>
{children}
</div>
)
// Disable blur effect on Windows, because electron backgroundMaterial has some issues
// const Win32Material: Props = ({ className, children, ...rest }) => (
// <div className={cn("bg-transparent", className)} {...rest}>
// {children}
// </div>
// )
export const WindowUnderBlur: Props = SYSTEM_CAN_UNDER_BLUR_WINDOW
? (props) => {
const opaqueSidebar = useUISettingKey("opaqueSidebar")
Expand All @@ -38,7 +39,7 @@ export const WindowUnderBlur: Props = SYSTEM_CAN_UNDER_BLUR_WINDOW
return <MacOSVibrancy {...props} />
}
case "win32": {
return <Win32Material {...props} />
return <Noop {...props} />
}
default: {
return <Noop {...props} />
Expand Down

0 comments on commit d772343

Please sign in to comment.