From 3cb47da58464c9f6ccc1e2baa5744699eb0e035b Mon Sep 17 00:00:00 2001 From: sawka Date: Sun, 26 Feb 2023 14:16:42 -0800 Subject: [PATCH] get fontsize from clientdata --- src/main.tsx | 4 ++++ src/model.ts | 20 +++++++++++++++++++- src/types.ts | 5 +++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index e2542eca..89878cd4 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2684,6 +2684,10 @@ class ScreenWindowView extends React.Component<{sw : ScreenWindow}, {}> { if (this.width.get() == 0) { return this.renderError("", false); } + let cdata = GlobalModel.clientData.get(); + if (cdata == null) { + return this.renderError("loading client data", true); + } let idx = 0; let line : LineType = null; let screen = GlobalModel.getScreenById(sw.sessionId, sw.screenId); diff --git a/src/model.ts b/src/model.ts index 011d7bd5..e877386f 100644 --- a/src/model.ts +++ b/src/model.ts @@ -72,6 +72,7 @@ function keyHasNoMods(e : any) { type OV = mobx.IObservableValue; type OArr = mobx.IObservableArray; type OMap = mobx.ObservableMap; +type CV = mobx.IComputedValue; function isBlank(s : string) { return (s == null || s == ""); @@ -1830,7 +1831,7 @@ class Model { authKey : string; isDev : boolean; activeMainView : OV<"session" | "history" | "bookmarks"> = mobx.observable.box("session", {name: "activeMainView"}); - termFontSize : OV = mobx.observable.box(DefaultTermFontSize, {name: "termFontSize"}); + termFontSize : CV; inputModel : InputModel; bookmarksModel : BookmarksModel; @@ -1846,6 +1847,20 @@ class Model { this.bookmarksModel = new BookmarksModel(); let isLocalServerRunning = getApi().getLocalServerStatus(); this.localServerRunning = mobx.observable.box(isLocalServerRunning, {name: "model-local-server-running"}); + this.termFontSize = mobx.computed(() => { + let cdata = this.clientData.get(); + if (cdata == null || cdata.feopts == null || cdata.feopts.termfontsize == null) { + return DefaultTermFontSize; + } + let fontSize = Math.ceil(cdata.feopts.termfontsize); + if (fontSize < MinFontSize) { + return MinFontSize; + } + if (fontSize > MaxFontSize) { + return MaxFontSize; + } + return fontSize; + }); getApi().onTCmd(this.onTCmd.bind(this)); getApi().onICmd(this.onICmd.bind(this)); getApi().onLCmd(this.onLCmd.bind(this)); @@ -2175,6 +2190,9 @@ class Model { else if ("bookmarks" in update) { this.bookmarksModel.mergeBookmarks(update.bookmarks); } + if ("clientdata" in update) { + this.clientData.set(update.clientdata); + } if (interactive && "info" in update) { let info : InfoType = update.info; this.inputModel.flashInfoMsg(info, info.timeoutms); diff --git a/src/types.ts b/src/types.ts index f45e8fba..6ccd7907 100644 --- a/src/types.ts +++ b/src/types.ts @@ -271,6 +271,7 @@ type PtyDataUpdateType = { }; type ModelUpdateType = { + interactive : boolean, sessions? : SessionDataType[], activesessionid? : string, windows? : WindowDataType[], @@ -281,10 +282,10 @@ type ModelUpdateType = { cmdline? : CmdLineUpdateType, remotes? : RemoteType[], history? : HistoryInfoType, - interactive : boolean, connect? : boolean, bookmarksview? : boolean, - bookmarks : BookmarkType[], + bookmarks? : BookmarkType[], + clientdata? : ClientDataType, }; type BookmarkType = {