Skip to content

Commit

Permalink
Merge branch 'dev' into ab
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban authored Sep 20, 2024
2 parents d81f57d + 039dd3d commit 94965b9
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 142 deletions.
58 changes: 58 additions & 0 deletions apps/main/src/lib/context-menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { BrowserWindow } from "electron"
import { Menu } from "electron"

import { t } from "./i18n"

export const registerContextMenu = (window: BrowserWindow) => {
const handler = (_event: Electron.Event, props: Electron.ContextMenuParams) => {
const { selectionText, isEditable } = props

const selectionMenu = Menu.buildFromTemplate([
{ role: "copy", label: t("menu.copy"), accelerator: "CmdOrCtrl+C" },
{ type: "separator" },
{ role: "selectAll", label: t("menu.selectAll"), accelerator: "CmdOrCtrl+A" },
])

const inputMenu = Menu.buildFromTemplate([
{ role: "undo", label: t("menu.undo"), accelerator: "CmdOrCtrl+Z" },
{
role: "redo",
label: t("menu.redo"),
accelerator: "CmdOrCtrl+Shift+Z",
},
{ type: "separator" },
{
role: "cut",
label: t("menu.cut"),
accelerator: "CmdOrCtrl+X",
},
{
role: "copy",
label: t("menu.copy"),
accelerator: "CmdOrCtrl+C",
},
{
role: "paste",
label: t("menu.paste"),
accelerator: "CmdOrCtrl+V",
},
{
type: "separator",
},
{ role: "selectAll", label: t("menu.selectAll"), accelerator: "CmdOrCtrl+A" },
])

if (isEditable) {
inputMenu.popup({
window,
})
} else if (selectionText && selectionText.trim() !== "") {
selectionMenu.popup({ window })
}
}
window.webContents.on("context-menu", handler)

return () => {
window.webContents.removeListener("context-menu", handler)
}
}
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
98 changes: 33 additions & 65 deletions apps/main/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ 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, screen, shell } from "electron"

import { isDev, isMacOS, isWindows11 } from "./env"
import { getIconPath } from "./helper"
import { t } from "./lib/i18n"
import { registerContextMenu } from "./lib/context-menu"
import { store } from "./lib/store"
import { logger } from "./logger"
import { cancelPollingUpdateUnreadCount, pollingUpdateUnreadCount } from "./tipc/dock"
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 @@ -143,57 +141,10 @@ export function createWindow(
},
})
})

window.webContents.on("context-menu", (_e, props) => {
const { selectionText, isEditable } = props

const selectionMenu = Menu.buildFromTemplate([
{ role: "copy", label: t("menu.copy"), accelerator: "CmdOrCtrl+C" },
{ type: "separator" },
{ role: "selectAll", label: t("menu.selectAll"), accelerator: "CmdOrCtrl+A" },
])

const inputMenu = Menu.buildFromTemplate([
{ role: "undo", label: t("menu.undo"), accelerator: "CmdOrCtrl+Z" },
{
role: "redo",
label: t("menu.redo"),
accelerator: "CmdOrCtrl+Shift+Z",
},
{ type: "separator" },
{
role: "cut",
label: t("menu.cut"),
accelerator: "CmdOrCtrl+X",
},
{
role: "copy",
label: t("menu.copy"),
accelerator: "CmdOrCtrl+C",
},
{
role: "paste",
label: t("menu.paste"),
accelerator: "CmdOrCtrl+V",
},
{
type: "separator",
},
{ role: "selectAll", label: t("menu.selectAll"), accelerator: "CmdOrCtrl+A" },
])

if (isEditable) {
inputMenu.popup({
window,
})
} else if (selectionText && selectionText.trim() !== "") {
selectionMenu.popup({ window })
}
})
registerContextMenu(window)

return window
}

export const createMainWindow = () => {
const storeKey = "windowState"
const windowState = store.get(storeKey) as {
Expand All @@ -202,12 +153,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
4 changes: 2 additions & 2 deletions apps/renderer/src/components/feed-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export function FollowSummary({
size={32}
/>
<div className="truncate text-base font-semibold leading-tight">
<div className="flex items-center gap-1">
<div className="flex items-center">
{feed.title}
<FeedCertification feed={feed} />
<FeedCertification className="center" feed={feed} />
</div>
<EllipsisHorizontalTextWithTooltip className="truncate text-xs font-normal text-zinc-500">
{feed.description}
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
1 change: 1 addition & 0 deletions apps/renderer/src/components/ui/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const Input = forwardRef<
"focus:!bg-accent/5",
"border border-border",
"dark:text-zinc-200 dark:placeholder:text-zinc-500",
"hover:border-accent/60",
props.type === "password" ? "font-mono placeholder:font-sans" : "font-sans",
"w-full",
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/constants/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const views: ViewDefinition[] = [
name: "feed_view_type.articles",
icon: <i className="i-mgc-paper-cute-fi" />,
className: "text-accent",
peerClassName: "peer-checked:text-accent",
peerClassName: "peer-checked:text-accent dark:peer-checked:text-accent",
translation: "title,description",
view: FeedViewType.Articles,
},
Expand Down
4 changes: 3 additions & 1 deletion apps/renderer/src/modules/discover/feed-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,10 @@ const FeedInnerForm = ({
<label
htmlFor={view.name}
className={cn(
"hover:text-theme-foreground dark:hover:text-white",
view.peerClassName,
"center flex h-10 flex-col text-xs leading-none opacity-80 duration-200 hover:opacity-90",
"center flex h-10 flex-col text-xs leading-none opacity-80 duration-200",
"text-neutral-800 dark:text-zinc-200",
"peer-checked:opacity-100",
"whitespace-nowrap",
)}
Expand Down
Loading

0 comments on commit 94965b9

Please sign in to comment.