[feature]: Support using system fonts (#304)

* [feature]: Support using system fonts

Uses the **experimental** queryLocalFonts API, when prompted, to get the fonts and do CSS.
Resolves #270 and #288 (by proxy)

Caveats/notes:
- This is experimental, and is only supported by Chrome/Chromium/Edgeium (see https://caniuse.com/?search=querylocalfonts)
- As far as I can tell, the only way to dynamically change the font (shown in https://wicg.github.io/local-font-access/#example-style-with-local-fonts) was by DOM manipulation; css variables did not seem to work
- This shows **all** fonts, including their variants (bold/italic/etc); given that the style names could be localized, not sure of a way to parse this (on my system, for instance, I had 859 different combinations)
- I made fonts a separate top-level setting because it was easier to manipulate without causing as many rerenders; feel free to put that back

* add permission chec

* add electron magic to support custom font

* restrict content types
This commit is contained in:
Kendall Garner 2023-10-22 22:25:17 +00:00 committed by GitHub
parent e6ed9229c2
commit 74cab01013
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 282 additions and 20 deletions

View file

@ -19,6 +19,7 @@ import {
PlaybackType,
TableType,
Platform,
FontType,
} from '/@/renderer/types';
import { randomString } from '/@/renderer/utils';
@ -111,10 +112,16 @@ export enum BindingActions {
}
export interface SettingsState {
font: {
builtIn: string;
custom: string | null;
system: string | null;
type: FontType;
};
general: {
defaultFullPlaylist: boolean;
followSystemTheme: boolean;
fontContent: string;
playButtonBehavior: Play;
resume: boolean;
showQueueDrawerButton: boolean;
@ -208,10 +215,15 @@ const getPlatformDefaultWindowBarStyle = (): Platform => {
const platformDefaultWindowBarStyle: Platform = getPlatformDefaultWindowBarStyle();
const initialState: SettingsState = {
font: {
builtIn: 'Inter',
custom: null,
system: null,
type: FontType.BUILT_IN,
},
general: {
defaultFullPlaylist: true,
followSystemTheme: false,
fontContent: 'Inter',
playButtonBehavior: Play.NOW,
resume: false,
showQueueDrawerButton: false,
@ -542,3 +554,5 @@ export const useMpvSettings = () =>
export const useLyricsSettings = () => useSettingsStore((state) => state.lyrics, shallow);
export const useRemoteSettings = () => useSettingsStore((state) => state.remote, shallow);
export const useFontSettings = () => useSettingsStore((state) => state.font, shallow);