fix: gate syntax highlight font on windows

This commit is contained in:
purocean
2026-05-01 11:15:45 +08:00
parent a8bf579d35
commit 24b5a11545
3 changed files with 75 additions and 26 deletions
+2
View File
@@ -1,6 +1,7 @@
import buildInRenderers from '@fe/plugins/build-in-renderers'
import customStyles from '@fe/plugins/custom-styles'
import customKeybindings from '@fe/plugins/custom-keybindings'
import codeSyntaxHighlightFont from '@fe/plugins/code-syntax-highlight-font'
import electronZoom from '@fe/plugins/electron-zoom'
import historyStack from '@fe/plugins/history-stack'
import fileTreeFunctions from '@fe/plugins/file-tree-functions'
@@ -86,6 +87,7 @@ export default [
buildInRenderers,
customStyles,
customKeybindings,
codeSyntaxHighlightFont,
electronZoom,
historyStack,
fileTreeFunctions,
@@ -0,0 +1,73 @@
import lightFontUrl from '@fe/assets/FontWithASyntaxHighlighterLightOwl-Regular.woff2'
import nightFontUrl from '@fe/assets/FontWithASyntaxHighlighterNightOwl-Regular.woff2'
import type { Ctx, Plugin } from '@fe/context'
const WINDOWS_11_BUILD = 22000
function getWindowsBuildNumber (ctx: Ctx) {
if (!ctx.env.nodeRequire) {
return null
}
try {
const release = String(ctx.env.nodeRequire('os').release())
const build = Number(release.split('.')[2])
return Number.isFinite(build) ? build : null
} catch {
return null
}
}
function shouldLoadFont (ctx: Ctx) {
if (!ctx.env.isWindows) {
return true
}
const build = getWindowsBuildNumber(ctx)
return typeof build === 'number' && build >= WINDOWS_11_BUILD
}
export default {
name: 'code-syntax-highlight-font',
register: (ctx: Ctx) => {
ctx.registerHook('STARTUP', () => {
if (!shouldLoadFont(ctx)) {
return
}
const className = ctx.args.DOM_CLASS_NAME.CODE_SYNTAX_HIGHLIGHT_FONT
ctx.theme.addStyles(`
@font-face {
font-family: 'FontWithASyntaxHighlighterLightOwl-Regular';
src: url('${lightFontUrl}') format('woff2');
font-display: swap;
}
@font-face {
font-family: 'FontWithASyntaxHighlighterNightOwl-Regular';
src: url('${nightFontUrl}') format('woff2');
font-display: swap;
}
.${className} {
font-family: 'FontWithASyntaxHighlighterLightOwl-Regular', monospace;
}
@media screen {
html[app-theme=dark] .${className} {
font-family: 'FontWithASyntaxHighlighterNightOwl-Regular', monospace;
}
}
@media (prefers-color-scheme: dark) {
html[app-theme=system] .${className} {
font-family: 'FontWithASyntaxHighlighterNightOwl-Regular', monospace;
}
}
`)
})
}
} as Plugin
-26
View File
@@ -258,29 +258,3 @@ a {
border: 1px solid var(--g-color-80);
border-radius: var(--g-border-radius);
}
@font-face {
font-family: 'FontWithASyntaxHighlighterLightOwl-Regular';
src:
url('@fe/assets/FontWithASyntaxHighlighterLightOwl-Regular.woff2')
format('woff2')
;
}
@font-face {
font-family: 'FontWithASyntaxHighlighterNightOwl-Regular';
src:
url('@fe/assets/FontWithASyntaxHighlighterNightOwl-Regular.woff2')
format('woff2')
;
}
.code-syntax-highlight-font {
font-family: 'FontWithASyntaxHighlighterLightOwl-Regular', monospace;
}
@include dark-theme {
.code-syntax-highlight-font {
font-family: 'FontWithASyntaxHighlighterNightOwl-Regular', monospace;
}
}