mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-06 19:18:22 +01:00
cleanup main model
This commit is contained in:
parent
5ad26b10cd
commit
2bcc8756e7
@ -1,88 +1,46 @@
|
|||||||
// Copyright 2023, Command Line Inc.
|
// Copyright 2023, Command Line Inc.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import type React from "react";
|
|
||||||
import * as mobx from "mobx";
|
import * as mobx from "mobx";
|
||||||
import { sprintf } from "sprintf-js";
|
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 {
|
import {
|
||||||
handleJsonFetchResponse,
|
handleJsonFetchResponse,
|
||||||
base64ToString,
|
base64ToString,
|
||||||
stringToBase64,
|
|
||||||
base64ToArray,
|
base64ToArray,
|
||||||
genMergeData,
|
genMergeData,
|
||||||
genMergeDataMap,
|
genMergeDataMap,
|
||||||
genMergeSimpleData,
|
genMergeSimpleData,
|
||||||
boundInt,
|
|
||||||
isModKeyPress,
|
isModKeyPress,
|
||||||
isBlank,
|
isBlank,
|
||||||
} from "../util/util";
|
} from "../util/util";
|
||||||
import { TermWrap } from "../plugins/terminal/term";
|
|
||||||
import { PluginModel } from "../plugins/plugins";
|
|
||||||
import {
|
import {
|
||||||
SessionDataType,
|
SessionDataType,
|
||||||
LineType,
|
LineType,
|
||||||
RemoteType,
|
RemoteType,
|
||||||
HistoryItem,
|
|
||||||
RemoteInstanceType,
|
RemoteInstanceType,
|
||||||
RemotePtrType,
|
|
||||||
CmdDataType,
|
CmdDataType,
|
||||||
FeCmdPacketType,
|
FeCmdPacketType,
|
||||||
TermOptsType,
|
|
||||||
ScreenDataType,
|
ScreenDataType,
|
||||||
ScreenOptsType,
|
|
||||||
PtyDataUpdateType,
|
PtyDataUpdateType,
|
||||||
ModelUpdateType,
|
ModelUpdateType,
|
||||||
UpdateMessage,
|
UpdateMessage,
|
||||||
InfoType,
|
InfoType,
|
||||||
|
StrWithPos,
|
||||||
UIContextType,
|
UIContextType,
|
||||||
HistoryInfoType,
|
|
||||||
HistoryQueryOpts,
|
|
||||||
FeInputPacketType,
|
|
||||||
RemoteInputPacketType,
|
|
||||||
ContextMenuOpts,
|
ContextMenuOpts,
|
||||||
RendererContext,
|
RendererContext,
|
||||||
RendererModel,
|
|
||||||
PtyDataType,
|
|
||||||
BookmarkType,
|
|
||||||
ClientDataType,
|
ClientDataType,
|
||||||
HistoryViewDataType,
|
|
||||||
AlertMessageType,
|
AlertMessageType,
|
||||||
HistorySearchParams,
|
|
||||||
FocusTypeStrs,
|
|
||||||
ScreenLinesType,
|
ScreenLinesType,
|
||||||
HistoryTypeStrs,
|
|
||||||
RendererPluginType,
|
|
||||||
WindowSize,
|
|
||||||
WebShareOpts,
|
|
||||||
TermContextUnion,
|
|
||||||
RemoteEditType,
|
|
||||||
RemoteViewType,
|
RemoteViewType,
|
||||||
CommandRtnType,
|
CommandRtnType,
|
||||||
WebCmd,
|
|
||||||
WebRemote,
|
|
||||||
OpenAICmdInfoChatMessageType,
|
|
||||||
StatusIndicatorLevel,
|
|
||||||
LineFocusType,
|
LineFocusType,
|
||||||
|
CmdInputTextPacketType,
|
||||||
|
FileInfoType,
|
||||||
|
ExtFile,
|
||||||
} from "../types/types";
|
} from "../types/types";
|
||||||
import * as T from "../types/types";
|
|
||||||
import { WSControl } from "./ws";
|
import { WSControl } from "./ws";
|
||||||
import {
|
import { cmdStatusIsRunning } from "../app/line/lineutil";
|
||||||
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 * as appconst from "../app/appconst";
|
import * as appconst from "../app/appconst";
|
||||||
import { remotePtrToString, cmdPacketString } from "../util/modelutil";
|
import { remotePtrToString, cmdPacketString } from "../util/modelutil";
|
||||||
import { checkKeyPressed, adaptFromReactOrNativeKeyEvent, setKeyUtilPlatform } from "../util/keyutil";
|
import { checkKeyPressed, adaptFromReactOrNativeKeyEvent, setKeyUtilPlatform } from "../util/keyutil";
|
||||||
@ -102,11 +60,6 @@ import { MainSidebarModel } from "./mainsidebar";
|
|||||||
import { Screen } from "./screen";
|
import { Screen } from "./screen";
|
||||||
import { Cmd } from "./cmd";
|
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 ProdServerEndpoint = "http://127.0.0.1:1619";
|
||||||
const ProdServerWsEndpoint = "ws://127.0.0.1:1623";
|
const ProdServerWsEndpoint = "ws://127.0.0.1:1623";
|
||||||
const DevServerEndpoint = "http://127.0.0.1:8090";
|
const DevServerEndpoint = "http://127.0.0.1:8090";
|
||||||
@ -114,21 +67,6 @@ const DevServerWsEndpoint = "ws://127.0.0.1:8091";
|
|||||||
const DefaultTermFontSize = 12;
|
const DefaultTermFontSize = 12;
|
||||||
const MinFontSize = 8;
|
const MinFontSize = 8;
|
||||||
const MaxFontSize = 24;
|
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
|
// @ts-ignore
|
||||||
const VERSION = __WAVETERM_VERSION__;
|
const VERSION = __WAVETERM_VERSION__;
|
||||||
@ -568,7 +506,7 @@ class Model {
|
|||||||
let cmd = activeScreen.getCmd(line);
|
let cmd = activeScreen.getCmd(line);
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
if (cmd.isRunning()) {
|
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);
|
this.inputModel.flashInfoMsg(info, 2000);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1385,8 +1323,8 @@ class Model {
|
|||||||
this.ws.pushMessage(inputPacket);
|
this.ws.pushMessage(inputPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCmdInputText(screenId: string, sp: T.StrWithPos) {
|
sendCmdInputText(screenId: string, sp: StrWithPos) {
|
||||||
let pk: T.CmdInputTextPacketType = {
|
let pk: CmdInputTextPacketType = {
|
||||||
type: "cmdinputtext",
|
type: "cmdinputtext",
|
||||||
seqnum: this.getNextPacketSeqNum(),
|
seqnum: this.getNextPacketSeqNum(),
|
||||||
screenid: screenId,
|
screenid: screenId,
|
||||||
@ -1421,7 +1359,7 @@ class Model {
|
|||||||
return remote.remotecanonicalname;
|
return remote.remotecanonicalname;
|
||||||
}
|
}
|
||||||
|
|
||||||
readRemoteFile(screenId: string, lineId: string, path: string): Promise<T.ExtFile> {
|
readRemoteFile(screenId: string, lineId: string, path: string): Promise<ExtFile> {
|
||||||
let urlParams = {
|
let urlParams = {
|
||||||
screenid: screenId,
|
screenid: screenId,
|
||||||
lineid: lineId,
|
lineid: lineId,
|
||||||
@ -1430,7 +1368,7 @@ class Model {
|
|||||||
let usp = new URLSearchParams(urlParams);
|
let usp = new URLSearchParams(urlParams);
|
||||||
let url = new URL(this.getBaseHostPort() + "/api/read-file?" + usp.toString());
|
let url = new URL(this.getBaseHostPort() + "/api/read-file?" + usp.toString());
|
||||||
let fetchHeaders = this.getFetchHeaders();
|
let fetchHeaders = this.getFetchHeaders();
|
||||||
let fileInfo: T.FileInfoType = null;
|
let fileInfo: FileInfoType = null;
|
||||||
let badResponseStr: string = null;
|
let badResponseStr: string = null;
|
||||||
let prtn = fetch(url, { method: "get", headers: fetchHeaders })
|
let prtn = fetch(url, { method: "get", headers: fetchHeaders })
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
@ -1452,7 +1390,7 @@ class Model {
|
|||||||
let isWriteable = (fileInfo.perm & 0o222) > 0; // checks for unix permission "w" bits
|
let isWriteable = (fileInfo.perm & 0o222) > 0; // checks for unix permission "w" bits
|
||||||
(file as any).readOnly = !isWriteable;
|
(file as any).readOnly = !isWriteable;
|
||||||
(file as any).notFound = !!fileInfo.notfound;
|
(file as any).notFound = !!fileInfo.notfound;
|
||||||
return file as T.ExtFile;
|
return file as ExtFile;
|
||||||
} else {
|
} else {
|
||||||
let textError: string = blobOrText;
|
let textError: string = blobOrText;
|
||||||
if (textError == null || textError.length == 0) {
|
if (textError == null || textError.length == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user