checkpoint, reading session from server

This commit is contained in:
sawka 2022-07-02 13:32:25 -07:00
parent 7d059fe573
commit bfaa504249
3 changed files with 60 additions and 10 deletions

View File

@ -318,8 +318,14 @@ class SessionView extends React.Component<{session : SessionType}, {}> {
render() {
let session = this.props.session;
let window = session.getActiveWindow();
let lines = window.lines;
if (window == null) {
return <div className="session-view">(no active window {session.activeWindowId.get()})</div>;
}
let lines = window.lines || [];
let idx = 0;
if (session.loading.get()) {
return <div className="session-view">(loading)</div>;
}
return (
<div className="session-view">
<div className="lines" onScroll={this.scrollHandler}>

View File

@ -37,27 +37,46 @@ function getLineId(line : LineType) : string {
return sprintf("%s-%s-%s", line.sessionid, line.windowid, line.lineid);
}
type WindowType = {
type SessionRemoteDataType = {
sessionid : string,
windowid : string,
remoteid : string,
remotename : string,
cwd : string,
}
type WindowDataType = {
sessionid : string,
windowid : string,
name : string,
curremote : string,
remotes : SessionRemoteDataType[],
lines : LineType[],
version : number,
};
type HistoryItem = {
cmdtext : string,
};
type SessionDataType = {
sessionid : string,
name : string,
windows : WindowDataType[],
cmds : CmdDataType[],
};
class Session {
sessionId : string;
name : string;
windows : WindowType[];
activeWindowId : string;
windows : WindowDataType[];
activeWindowId : mobx.IObservableValue<string> = mobx.observable.box(null);
termMap : Record<string, TermWrap> = {};
termMapById : Record<string, TermWrap> = {};
history : HistoryItem[] = [];
curRemote : string;
curDir : string;
loading : mobx.IObservableValue<boolean> = mobx.observable.box(false);
constructor() {
}
@ -124,12 +143,13 @@ class Session {
console.log("cmddata", pk);
}
getActiveWindow() : WindowType {
if (this.windows == null) {
getActiveWindow() : WindowDataType {
if (this.windows == null || this.windows.length == 0) {
return null;
}
let awid = this.activeWindowId.get();
for (let i=0; i<this.windows.length; i++) {
if (this.windows[i].windowid == this.activeWindowId) {
if (this.windows[i].windowid == awid) {
return this.windows[i];
}
}
@ -137,9 +157,31 @@ class Session {
}
}
var DefaultSession : Session = null;
var DefaultSession : Session = new Session();
function loadDefaultSession() {
if (DefaultSession.loading.get()) {
return;
}
let usp = new URLSearchParams({name: "default"});
let url = sprintf("http://localhost:8080/api/get-session?") + usp.toString();
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
mobx.action(() => {
let sdata = data.data;
DefaultSession.loading.set(false);
DefaultSession.name = sdata.name;
DefaultSession.windows = sdata.windows;
DefaultSession.activeWindowId.set(sdata.windows[0].windowid);
console.log("session", sdata);
})();
}).catch((err) => {
console.log("error calling get-session", err)
});
}
function getDefaultSession() : Session {
return DefaultSession;
if (DefaultSession != null) {
return DefaultSession;
}
@ -157,5 +199,5 @@ function getDefaultSession() : Session {
window.getDefaultSession = getDefaultSession;
export {Session, getDefaultSession, getLineId};
export type {LineType, WindowType};
export {Session, getDefaultSession, getLineId, loadDefaultSession};
export type {LineType, WindowDataType};

View File

@ -5,12 +5,14 @@ import {Terminal} from 'xterm';
import {Main} from "./main";
import {GlobalWS} from "./ws";
import {v4 as uuidv4} from "uuid";
import {loadDefaultSession} from "./session";
let VERSION = __SHVERSION__;
window.ScriptHausClientId = uuidv4();
document.addEventListener("DOMContentLoaded", () => {
loadDefaultSession();
GlobalWS.reconnect();
let reactElem = React.createElement(Main, null, null);
let elem = document.getElementById("app");