mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
fix(desktop): draw the Windows caption buttons in the contrast theme's text colour (#65324)
Some checks are pending
bot-nix-hashes / compute (push) Blocked by required conditions
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
bot-nix-hashes / hash (blacksmith-6vcpu-macos-latest, aarch64-darwin) (push) Waiting to run
bot-nix-hashes / publish (push) Blocked by required conditions
check-nix / nix-eval (push) Waiting to run
check / typecheck (push) Waiting to run
deploy-files / files-build (push) Waiting to run
deploy-files / files-deploy (push) Blocked by required conditions
deploy-site / site-build (push) Waiting to run
deploy-site / site-deploy (push) Blocked by required conditions
deploy / legacy-build (push) Waiting to run
deploy / legacy-deploy (push) Blocked by required conditions
deploy / data-build (push) Waiting to run
deploy / data-deploy (push) Blocked by required conditions
Some checks are pending
bot-nix-hashes / compute (push) Blocked by required conditions
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
bot-nix-hashes / hash (blacksmith-6vcpu-macos-latest, aarch64-darwin) (push) Waiting to run
bot-nix-hashes / publish (push) Blocked by required conditions
check-nix / nix-eval (push) Waiting to run
check / typecheck (push) Waiting to run
deploy-files / files-build (push) Waiting to run
deploy-files / files-deploy (push) Blocked by required conditions
deploy-site / site-build (push) Waiting to run
deploy-site / site-deploy (push) Blocked by required conditions
deploy / legacy-build (push) Waiting to run
deploy / legacy-deploy (push) Blocked by required conditions
deploy / data-build (push) Waiting to run
deploy / data-deploy (push) Blocked by required conditions
This commit is contained in:
parent
32ae019771
commit
ba5bbef82c
2 changed files with 19 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { resolveThemeVariant } from "@opencode/ui/theme/resolve"
|
||||
import type { DesktopTheme } from "@opencode/ui/theme/types"
|
||||
import { desktopZoomLevels } from "@opencode/app/desktop-menu"
|
||||
import { nativeTheme, type BrowserWindowConstructorOptions } from "electron"
|
||||
import { nativeTheme, systemPreferences, type BrowserWindowConstructorOptions } from "electron"
|
||||
import { Predicate } from "effect"
|
||||
import oc2ThemeJson from "../../../../ui/src/theme/themes/oc-2.json"
|
||||
import { BACKGROUND_COLOR_KEY, ZOOM_LEVEL_KEY } from "../storage/keys"
|
||||
|
|
@ -49,11 +49,20 @@ export function storedZoomLevel() {
|
|||
export function titlebarOverlay(mode: "light" | "dark" = tone(), zoom = 1) {
|
||||
return {
|
||||
color: "#00000000",
|
||||
symbolColor: mode === "dark" ? "white" : "black",
|
||||
symbolColor: captionSymbolColor(mode),
|
||||
height: Math.max(titlebarHeight, Math.round(titlebarHeight * zoom)),
|
||||
}
|
||||
}
|
||||
|
||||
// A Windows contrast theme repaints the page in system colours (`forced-colors`), whatever theme the app picked, so the
|
||||
// caption buttons draw in the theme's window text colour too instead of the app theme's black or white.
|
||||
function captionSymbolColor(mode: "light" | "dark") {
|
||||
if (process.platform === "win32" && nativeTheme.shouldUseHighContrastColors)
|
||||
return systemPreferences.getColor("window-text")
|
||||
|
||||
return mode === "dark" ? "white" : "black"
|
||||
}
|
||||
|
||||
// macOS and Windows hide the titlebar; Windows draws its window controls in an overlay sized to the zoom.
|
||||
export function platformFrame(mode: "light" | "dark", zoom: number) {
|
||||
const frame: BrowserWindowConstructorOptions = {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { randomUUID } from "node:crypto"
|
||||
import { app, BrowserWindow, screen } from "electron"
|
||||
import { app, BrowserWindow, nativeTheme, screen } from "electron"
|
||||
import { Effect, FileSystem, Path } from "effect"
|
||||
import { openExternalURL } from "../files"
|
||||
import { scoped } from "../native/logging"
|
||||
|
|
@ -123,6 +123,13 @@ export const mainWindows = Effect.fn("Window.make")(function* (input: {
|
|||
const runFork = Effect.runForkWith(yield* Effect.context())
|
||||
const wireWindowRecovery = yield* windowRecovery
|
||||
|
||||
// Turning a Windows contrast theme on or off changes the caption buttons' colour (`titlebarOverlay`).
|
||||
if (process.platform === "win32") {
|
||||
const contrastChanged = () => getMainWindows().forEach(updateTitlebar)
|
||||
nativeTheme.on("updated", contrastChanged)
|
||||
yield* Effect.addFinalizer(() => Effect.sync(() => nativeTheme.off("updated", contrastChanged)))
|
||||
}
|
||||
|
||||
// The entry module created and showed the first restored window on ready; it is adopted here,
|
||||
// before any renderer loads, so the user never waited for the layers to see a window.
|
||||
const restore = () =>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue