diff --git a/src/main.tsx b/src/main.tsx
index 281b3e973..75c36bec7 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -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
diff --git a/src/session.ts b/src/session.ts
index 5dd499e55..7510412ad 100644
--- a/src/session.ts
+++ b/src/session.ts
@@ -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 = mobx.observable.box(null);
termMap : Record = {};
termMapById : Record = {};
history : HistoryItem[] = [];
curRemote : string;
curDir : string;
+ loading : mobx.IObservableValue = 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 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};
diff --git a/src/sh2.ts b/src/sh2.ts
index d5c99bc63..2258c3686 100644
--- a/src/sh2.ts
+++ b/src/sh2.ts
@@ -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");