Skip to content

Commit

Permalink
fix: can use under window blur
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Aug 22, 2024
1 parent 3735390 commit 9b2656e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
6 changes: 0 additions & 6 deletions src/main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ export function createWindow(
...configs,
})

window.webContents.executeJavaScript(
`((() => { globalThis.FEATURES = globalThis.FEATURES || []; globalThis.FEATURES['WINDOW_UNDER_BLUR'] = ${
!!baseWindowConfig.backgroundMaterial || !!baseWindowConfig.vibrancy
} })())`,
)

function refreshBound(timeout = 0) {
setTimeout(() => {
const mainWindow = getMainWindow()
Expand Down
2 changes: 1 addition & 1 deletion src/preload/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ElectronAPI } from "@electron-toolkit/preload"
declare global {
interface Window {
electron?: ElectronAPI
api: unknown
api?: { canWindowBlur: boolean }
platform: NodeJS.Platform
}
}
16 changes: 15 additions & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import os from "node:os"
import { platform } from "node:process"

import { electronAPI } from "@electron-toolkit/preload"
import { contextBridge } from "electron"

export const isMacOS = platform === "darwin"

export const isWindows = platform === "win32"

export const isLinux = platform === "linux"
export const isWindows11 = isWindows && os.version().startsWith("Windows 11")

// Custom APIs for renderer
const api = {}
const api = {
canWindowBlur:
process.platform === "darwin" ||
(process.platform === "win32" && isWindows11),
}

// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useUISettingKey } from "@renderer/atoms/settings/ui"
import { cn } from "@renderer/lib/utils"
import { SYSTEM_CAN_UNDER_BLUR_WINDOW } from "@shared/constants"

type Props = Component<
React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
Expand All @@ -21,7 +22,7 @@ const Win32Material: Props = ({ className, children, ...rest }) => (
{children}
</div>
)
export const WindowUnderBlur: Props = FEATURES.WINDOW_UNDER_BLUR ?
export const WindowUnderBlur: Props = SYSTEM_CAN_UNDER_BLUR_WINDOW ?
(props) => {
const opaqueSidebar = useUISettingKey("opaqueSidebar")
if (opaqueSidebar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ const SwitchToMasonryButton = () => {
const AppendTaildingDivider = ({ children }: { children: React.ReactNode }) => (
<>
{children}
{React.Children.count(children) > 1 && (<DividerVertical className="mx-2 w-px" />)}
{React.Children.toArray(children).filter(Boolean).length > 0 && (
<DividerVertical className="mx-2 w-px" />
)}
</>
)
4 changes: 4 additions & 0 deletions src/shared/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export const DEEPLINK_SCHEME = `${APP_PROTOCOL}://`

// export const WEB_URL = import.meta.env.VITE_VERCEL_URL ?? import.meta.env.VITE_WEB_URL
export const WEB_URL = env.VITE_WEB_URL

export const SYSTEM_CAN_UNDER_BLUR_WINDOW = globalThis?.window?.electron ?

Check failure on line 9 in src/shared/src/constants.ts

View workflow job for this annotation

GitHub Actions / release (macos-latest)

Property 'electron' does not exist on type 'Window & typeof globalThis'. Did you mean 'Electron'?

Check failure on line 9 in src/shared/src/constants.ts

View workflow job for this annotation

GitHub Actions / release (ubuntu-latest)

Property 'electron' does not exist on type 'Window & typeof globalThis'. Did you mean 'Electron'?

Check failure on line 9 in src/shared/src/constants.ts

View workflow job for this annotation

GitHub Actions / release (windows-latest)

Property 'electron' does not exist on type 'Window & typeof globalThis'. Did you mean 'Electron'?
window.api?.canWindowBlur :

Check failure on line 10 in src/shared/src/constants.ts

View workflow job for this annotation

GitHub Actions / release (macos-latest)

Property 'api' does not exist on type 'Window & typeof globalThis'.

Check failure on line 10 in src/shared/src/constants.ts

View workflow job for this annotation

GitHub Actions / release (ubuntu-latest)

Property 'api' does not exist on type 'Window & typeof globalThis'.

Check failure on line 10 in src/shared/src/constants.ts

View workflow job for this annotation

GitHub Actions / release (windows-latest)

Property 'api' does not exist on type 'Window & typeof globalThis'.
false
10 changes: 3 additions & 7 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const vite = ({ mode }) => {
process.env.ANALYZER && visualizer({ open: true }),
],
define: {

APP_VERSION: JSON.stringify(pkg.version),
APP_NAME: JSON.stringify(pkg.name),
APP_DEV_CWD: JSON.stringify(process.cwd()),
Expand All @@ -90,9 +89,6 @@ const vite = ({ mode }) => {

DEBUG: process.env.DEBUG === "true",
ELECTRON: "false",

// Proxy Electron Features
FEATURES: "{}",
},
})
}
Expand Down Expand Up @@ -131,9 +127,9 @@ const devPrint = (): PluginOption => ({
server.printUrls = () => {
_printUrls()
console.info(
` ${green(
"➜",
)} ${dim("Online debug")}: ${cyan("https://web.follow.is/__debug_proxy")}`,
` ${green("➜")} ${dim("Online debug")}: ${cyan(
"https://web.follow.is/__debug_proxy",
)}`,
)
}
},
Expand Down

0 comments on commit 9b2656e

Please sign in to comment.