remoteinstance naming change

This commit is contained in:
sawka
2022-08-24 02:12:28 -07:00
parent 3aeab9d427
commit 2028a98784
2 changed files with 43 additions and 43 deletions
+34 -39
View File
@@ -4,7 +4,7 @@ import {boundMethod} from "autobind-decorator";
import {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData} from "./util"; import {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData} from "./util";
import {TermWrap} from "./term"; import {TermWrap} from "./term";
import {v4 as uuidv4} from "uuid"; import {v4 as uuidv4} from "uuid";
import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType, SessionUpdateType, WindowUpdateType, UpdateMessage, LineCmdUpdateType, InfoType, CmdLineUpdateType} from "./types"; import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, RemotePtrType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType, SessionUpdateType, WindowUpdateType, UpdateMessage, LineCmdUpdateType, InfoType, CmdLineUpdateType} from "./types";
import {WSControl} from "./ws"; import {WSControl} from "./ws";
var GlobalUser = "sawka"; var GlobalUser = "sawka";
@@ -17,6 +17,22 @@ function isBlank(s : string) {
return (s == null || s == ""); return (s == null || s == "");
} }
function remotePtrToString(rptr : RemotePtrType) : string {
if (rptr == null || isBlank(rptr.remoteid)) {
return null;
}
if (isBlank(rptr.owneruserid) && isBlank(rptr.name)) {
return rptr.remoteid;
}
if (!isBlank(rptr.owneruserid) && isBlank(rptr.name)) {
return sprintf("@%s:%s", rptr.owneruserid, rptr.remoteid)
}
if (isBlank(rptr.owneruserid) && !isBlank(rptr.name)) {
return sprintf("%s:%s", rptr.remoteid, rptr.name)
}
return sprintf("@%s:%s:%s", rptr.owneruserid, rptr.remoteid, rptr.name)
}
type KeyModsType = { type KeyModsType = {
meta? : boolean, meta? : boolean,
ctrl? : boolean, ctrl? : boolean,
@@ -275,12 +291,11 @@ class ScreenWindow {
class Window { class Window {
sessionId : string; sessionId : string;
windowId : string; windowId : string;
curRemote : OV<string> = mobx.observable.box(null); curRemote : OV<RemotePtrType> = mobx.observable.box(null);
loaded : OV<boolean> = mobx.observable.box(false); loaded : OV<boolean> = mobx.observable.box(false);
loadError : OV<string> = mobx.observable.box(null); loadError : OV<string> = mobx.observable.box(null);
lines : OArr<LineType> = mobx.observable.array([], {deep: false}); lines : OArr<LineType> = mobx.observable.array([], {deep: false});
cmds : Record<string, Cmd> = {}; cmds : Record<string, Cmd> = {};
remoteInstances : OArr<RemoteInstanceType> = mobx.observable.array([]);
constructor(sessionId : string, windowId : string) { constructor(sessionId : string, windowId : string) {
this.sessionId = sessionId; this.sessionId = sessionId;
@@ -289,7 +304,7 @@ class Window {
updateWindow(win : WindowDataType, load : boolean) { updateWindow(win : WindowDataType, load : boolean) {
mobx.action(() => { mobx.action(() => {
if (!isBlank(win.curremote)) { if (win.curremote != null && win.curremote.remoteid != "") {
this.curRemote.set(win.curremote); this.curRemote.set(win.curremote);
} }
if (load) { if (load) {
@@ -301,7 +316,6 @@ class Window {
for (let i=0; i<cmds.length; i++) { for (let i=0; i<cmds.length; i++) {
this.cmds[cmds[i].cmdid] = new Cmd(cmds[i]); this.cmds[cmds[i].cmdid] = new Cmd(cmds[i]);
} }
genMergeSimpleData(this.remoteInstances, win.remotes, (r) => r.riid, null);
})(); })();
} }
@@ -339,36 +353,12 @@ class Window {
} }
getCurRemoteInstance() : RemoteInstanceType { getCurRemoteInstance() : RemoteInstanceType {
let rname = this.curRemote.get(); let session = GlobalModel.getSessionById(this.sessionId);
if (rname == null) { let rptr = this.curRemote.get();
if (rptr == null) {
return null; return null;
} }
let sessionScope = false; return session.getRemoteInstance(this.windowId, this.curRemote.get());
if (rname.startsWith("^")) {
rname = rname.substr(1);
sessionScope = true;
}
if (sessionScope) {
let session = GlobalModel.getSessionById(this.sessionId);
let rdata = session.getRemoteInstance(rname);
return rdata;
}
return this.getRemoteInstance(rname);
}
getRemoteInstance(rname : string) : RemoteInstanceType {
for (let i=0; i<this.remoteInstances.length; i++) {
let rdata = this.remoteInstances[i];
if (rdata.name == rname) {
return rdata;
}
}
let remote = GlobalModel.getRemoteByName(rname);
if (remote != null) {
return {riid: "", sessionid: this.sessionId, windowid: this.windowId, remoteid: remote.remoteid,
name: rname, state: remote.defaultstate, sessionscope: false};
}
return null;
} }
updateCmd(cmd : CmdDataType) : void { updateCmd(cmd : CmdDataType) : void {
@@ -514,6 +504,7 @@ class Session {
this.activeScreenId.set(sdata.activescreenid); this.activeScreenId.set(sdata.activescreenid);
} }
} }
genMergeSimpleData(this.remoteInstances, sdata.remotes, (r) => r.riid, null);
})(); })();
} }
@@ -537,17 +528,21 @@ class Session {
return null; return null;
} }
getRemoteInstance(rname : string) : RemoteInstanceType { getRemoteInstance(windowId : string, rptr : RemotePtrType) : RemoteInstanceType {
if (rptr.name.startsWith("*")) {
windowId = "";
}
for (let i=0; i<this.remoteInstances.length; i++) { for (let i=0; i<this.remoteInstances.length; i++) {
let rdata = this.remoteInstances[i]; let rdata = this.remoteInstances[i];
if (rdata.name == rname) { if (rdata.windowid == windowId && rdata.remoteid == rptr.remoteid && rdata.remoteowneruserid == rptr.owneruserid && rdata.name == rptr.name) {
return rdata; return rdata;
} }
} }
let remote = GlobalModel.getRemoteByName(rname); let remote = GlobalModel.getRemote(rptr.remoteid);
if (remote != null) { if (remote != null) {
return {riid: "", sessionid: this.sessionId, windowid: null, remoteid: remote.remoteid, return {riid: "", sessionid: this.sessionId, windowid: windowId,
name: rname, state: remote.defaultstate, sessionscope: true}; remoteowneruserid: rptr.owneruserid, remoteid: rptr.remoteid, name: rptr.name,
state: remote.defaultstate};
} }
return null; return null;
} }
@@ -1126,7 +1121,7 @@ class Model {
} }
if (win != null) { if (win != null) {
rtn.window = win.windowId; rtn.window = win.windowId;
rtn.remote = win.curRemote.get(); rtn.remote = remotePtrToString(win.curRemote.get());
} }
return rtn; return rtn;
} }
+9 -4
View File
@@ -91,20 +91,25 @@ type RemoteInstanceType = {
name : string, name : string,
sessionid : string, sessionid : string,
windowid : string, windowid : string,
remoteowneruserid : string,
remoteid : string, remoteid : string,
sessionscope : boolean,
state : RemoteStateType, state : RemoteStateType,
remove? : boolean, remove? : boolean,
} }
type RemotePtrType = {
owneruserid : string,
remoteid : string,
name : string,
};
type WindowDataType = { type WindowDataType = {
sessionid : string, sessionid : string,
windowid : string, windowid : string,
curremote : string, curremote : RemotePtrType,
lines : LineType[], lines : LineType[],
cmds : CmdDataType[], cmds : CmdDataType[],
remotes : RemoteInstanceType[],
// for updates // for updates
remove? : boolean, remove? : boolean,
@@ -228,4 +233,4 @@ type InfoType = {
timeoutms? : number, timeoutms? : number,
}; };
export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType, PtyDataUpdateType, SessionUpdateType, WindowUpdateType, UpdateMessage, LineCmdUpdateType, InfoType, CmdLineUpdateType}; export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType, PtyDataUpdateType, SessionUpdateType, WindowUpdateType, UpdateMessage, LineCmdUpdateType, InfoType, CmdLineUpdateType, RemotePtrType};