Skip to content

Commit

Permalink
feat: windows maximum button
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jul 30, 2024
1 parent ea994cb commit b9c050b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
13 changes: 13 additions & 0 deletions src/main/tipc/setting.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRequire } from "node:module"

import type { BrowserWindow } from "electron"
import { app, nativeTheme } from "electron"

import { setDockCount } from "../lib/dock"
Expand Down Expand Up @@ -46,4 +47,16 @@ export const settingRoute = {
setDockBadge: t.procedure.input<number>().action(async ({ input }) => {
setDockCount(input)
}),
getWindowIsMaximized: t.procedure
.input<void>()
.action(async ({ context }) => {
const window: BrowserWindow | null = (
context.sender as Sender
).getOwnerBrowserWindow()
return window?.isMaximized()
}),
}

interface Sender extends Electron.WebContents {
getOwnerBrowserWindow: () => Electron.BrowserWindow | null
}
18 changes: 9 additions & 9 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { env } from "../../env.js"
import { useAppIsReady } from "./atoms/app"
import { useUISettingKey } from "./atoms/settings/ui"
import { appLog } from "./lib/log"
import { getOS } from "./lib/utils"
import { cn, getOS } from "./lib/utils"
import { Titlebar } from "./modules/app/Titlebar.js"
import { RootProviders } from "./providers/root-providers"
import { handlers } from "./tipc"
Expand Down Expand Up @@ -44,15 +44,15 @@ function App() {
const windowsElectron = window.electron && getOS() === "Windows"
return (
<>
{window.electron && (
<div
className="drag-region absolute inset-x-0 top-0 h-12 shrink-0"
aria-hidden
>
{windowsElectron && <Titlebar />}
</div>
)}
<RootProviders>
{window.electron && (
<div
className={cn("drag-region absolute inset-x-0 top-0 h-12 shrink-0", windowsElectron && "pointer-events-none z-[9999]")}
aria-hidden
>
{windowsElectron && <Titlebar />}
</div>
)}
<AppLayer />
</RootProviders>
</>
Expand Down
21 changes: 19 additions & 2 deletions src/renderer/src/modules/app/Titlebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { tipcClient } from "@renderer/lib/client"
import { useQuery } from "@tanstack/react-query"
import { useForceUpdate } from "framer-motion"
import { useEffect } from "react"
import { useLocation } from "react-router-dom"
Expand All @@ -9,10 +10,15 @@ export const Titlebar = () => {
useEffect(() => {
update()
}, [location])
const { data: isMaximized, refetch } = useQuery({
queryFn: () => tipcClient?.getWindowIsMaximized(),
queryKey: ["windowIsMaximized"],
})

return (
<div className="flex h-10 w-full items-center justify-end rounded-t-[12px] pr-1">
<button
className="no-drag-region flex h-[24px] w-[32px] items-center justify-center rounded duration-200 hover:bg-theme-item-active"
className="no-drag-region pointer-events-auto flex h-[24px] w-[32px] items-center justify-center rounded duration-200 hover:bg-theme-item-active"
type="button"
onClick={() => {
tipcClient?.windowAction({ action: "minimize" })
Expand All @@ -23,7 +29,18 @@ export const Titlebar = () => {

<button
type="button"
className="no-drag-region flex h-[24px] w-[32px] items-center justify-center rounded duration-200 hover:bg-red-500 hover:!text-white"
className="no-drag-region pointer-events-auto flex h-[24px] w-[32px] items-center justify-center rounded duration-200 hover:bg-theme-item-active"
onClick={async () => {
await tipcClient?.windowAction({ action: "maximum" })
refetch()
}}
>
{isMaximized ? <i className="i-mingcute-restore-line" /> : <i className="i-mingcute-square-line" />}
</button>

<button
type="button"
className="no-drag-region pointer-events-auto flex h-[24px] w-[32px] items-center justify-center rounded duration-200 hover:bg-red-500 hover:!text-white"
onClick={() => {
tipcClient?.windowAction({ action: "close" })
}}
Expand Down

0 comments on commit b9c050b

Please sign in to comment.