Implement font selection

This commit is contained in:
Jorik Schellekens
2020-06-15 15:33:52 +01:00
parent 94f52c4ee2
commit edb6bbc6c0
11 changed files with 239 additions and 5 deletions
+13 -1
View File
@@ -18,6 +18,8 @@ import dis from '../../dispatcher/dispatcher';
import SettingsStore, {SettingLevel} from '../SettingsStore';
import IWatcher from "./Watcher";
import { toPx } from '../../utils/units';
import { Action } from '../../dispatcher/actions';
import { UpdateSystemFontPayload } from '../../dispatcher/payloads/UpdateSystemFontPayload';
export class FontWatcher implements IWatcher {
public static readonly MIN_SIZE = 8;
@@ -33,6 +35,10 @@ export class FontWatcher implements IWatcher {
public start() {
this.setRootFontSize(SettingsStore.getValue("baseFontSize"));
this.setSystemFont({
useSystemFont: SettingsStore.getValue("useSystemFont"),
font: SettingsStore.getValue("systemFont"),
})
this.dispatcherRef = dis.register(this.onAction);
}
@@ -41,8 +47,10 @@ export class FontWatcher implements IWatcher {
}
private onAction = (payload) => {
if (payload.action === 'update-font-size') {
if (payload.action === Action.UpdateFontSize) {
this.setRootFontSize(payload.size);
} else if (payload.action === Action.UpdateSystemFont) {
this.setSystemFont(payload)
}
};
@@ -54,4 +62,8 @@ export class FontWatcher implements IWatcher {
}
(<HTMLElement>document.querySelector(":root")).style.fontSize = toPx(fontSize);
};
private setSystemFont = ({useSystemFont, font}) => {
document.body.style.fontFamily = useSystemFont ? font : "";
}
}