From 2bcc8756e722be4293eb7b0f070a74f3b43617fc Mon Sep 17 00:00:00 2001 From: Red Adaya Date: Thu, 8 Feb 2024 09:06:09 +0800 Subject: [PATCH] cleanup main model --- src/model/model.ts | 84 ++++++---------------------------------------- 1 file changed, 11 insertions(+), 73 deletions(-) diff --git a/src/model/model.ts b/src/model/model.ts index 26be4286d..eb56d88b9 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -1,88 +1,46 @@ // Copyright 2023, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import type React from "react"; import * as mobx from "mobx"; import { sprintf } from "sprintf-js"; -import { v4 as uuidv4 } from "uuid"; -import { boundMethod } from "autobind-decorator"; -import { debounce } from "throttle-debounce"; -import * as mobxReact from "mobx-react"; import { handleJsonFetchResponse, base64ToString, - stringToBase64, base64ToArray, genMergeData, genMergeDataMap, genMergeSimpleData, - boundInt, isModKeyPress, isBlank, } from "../util/util"; -import { TermWrap } from "../plugins/terminal/term"; -import { PluginModel } from "../plugins/plugins"; import { SessionDataType, LineType, RemoteType, - HistoryItem, RemoteInstanceType, - RemotePtrType, CmdDataType, FeCmdPacketType, - TermOptsType, ScreenDataType, - ScreenOptsType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, + StrWithPos, UIContextType, - HistoryInfoType, - HistoryQueryOpts, - FeInputPacketType, - RemoteInputPacketType, ContextMenuOpts, RendererContext, - RendererModel, - PtyDataType, - BookmarkType, ClientDataType, - HistoryViewDataType, AlertMessageType, - HistorySearchParams, - FocusTypeStrs, ScreenLinesType, - HistoryTypeStrs, - RendererPluginType, - WindowSize, - WebShareOpts, - TermContextUnion, - RemoteEditType, RemoteViewType, CommandRtnType, - WebCmd, - WebRemote, - OpenAICmdInfoChatMessageType, - StatusIndicatorLevel, LineFocusType, + CmdInputTextPacketType, + FileInfoType, + ExtFile, } from "../types/types"; -import * as T from "../types/types"; import { WSControl } from "./ws"; -import { - getMonoFontSize, - windowWidthToCols, - windowHeightToRows, - termWidthFromCols, - termHeightFromRows, -} from "../util/textmeasure"; -import dayjs from "dayjs"; -import localizedFormat from "dayjs/plugin/localizedFormat"; -import customParseFormat from "dayjs/plugin/customParseFormat"; -import { getRendererContext, cmdStatusIsRunning } from "../app/line/lineutil"; -import { MagicLayout } from "../app/magiclayout"; -import { modalsRegistry } from "../app/common/modals/registry"; +import { cmdStatusIsRunning } from "../app/line/lineutil"; import * as appconst from "../app/appconst"; import { remotePtrToString, cmdPacketString } from "../util/modelutil"; import { checkKeyPressed, adaptFromReactOrNativeKeyEvent, setKeyUtilPlatform } from "../util/keyutil"; @@ -102,11 +60,6 @@ import { MainSidebarModel } from "./mainsidebar"; import { Screen } from "./screen"; import { Cmd } from "./cmd"; -dayjs.extend(customParseFormat); -dayjs.extend(localizedFormat); - -const RemotePtyRows = 8; // also in main.tsx -const RemotePtyCols = 80; const ProdServerEndpoint = "http://127.0.0.1:1619"; const ProdServerWsEndpoint = "ws://127.0.0.1:1623"; const DevServerEndpoint = "http://127.0.0.1:8090"; @@ -114,21 +67,6 @@ const DevServerWsEndpoint = "ws://127.0.0.1:8091"; const DefaultTermFontSize = 12; const MinFontSize = 8; const MaxFontSize = 24; -const InputChunkSize = 500; -const RemoteColors = ["red", "green", "yellow", "blue", "magenta", "cyan", "white", "orange"]; -const TabColors = ["red", "orange", "yellow", "green", "mint", "cyan", "blue", "violet", "pink", "white"]; -const TabIcons = [ - "sparkle", - "fire", - "ghost", - "cloud", - "compass", - "crown", - "droplet", - "graduation-cap", - "heart", - "file", -]; // @ts-ignore const VERSION = __WAVETERM_VERSION__; @@ -568,7 +506,7 @@ class Model { let cmd = activeScreen.getCmd(line); if (cmd != null) { if (cmd.isRunning()) { - let info: T.InfoType = { infomsg: "Cannot delete a running command" }; + let info: InfoType = { infomsg: "Cannot delete a running command" }; this.inputModel.flashInfoMsg(info, 2000); return false; } @@ -1385,8 +1323,8 @@ class Model { this.ws.pushMessage(inputPacket); } - sendCmdInputText(screenId: string, sp: T.StrWithPos) { - let pk: T.CmdInputTextPacketType = { + sendCmdInputText(screenId: string, sp: StrWithPos) { + let pk: CmdInputTextPacketType = { type: "cmdinputtext", seqnum: this.getNextPacketSeqNum(), screenid: screenId, @@ -1421,7 +1359,7 @@ class Model { return remote.remotecanonicalname; } - readRemoteFile(screenId: string, lineId: string, path: string): Promise { + readRemoteFile(screenId: string, lineId: string, path: string): Promise { let urlParams = { screenid: screenId, lineid: lineId, @@ -1430,7 +1368,7 @@ class Model { let usp = new URLSearchParams(urlParams); let url = new URL(this.getBaseHostPort() + "/api/read-file?" + usp.toString()); let fetchHeaders = this.getFetchHeaders(); - let fileInfo: T.FileInfoType = null; + let fileInfo: FileInfoType = null; let badResponseStr: string = null; let prtn = fetch(url, { method: "get", headers: fetchHeaders }) .then((resp) => { @@ -1452,7 +1390,7 @@ class Model { let isWriteable = (fileInfo.perm & 0o222) > 0; // checks for unix permission "w" bits (file as any).readOnly = !isWriteable; (file as any).notFound = !!fileInfo.notfound; - return file as T.ExtFile; + return file as ExtFile; } else { let textError: string = blobOrText; if (textError == null || textError.length == 0) {