diff --git a/src/main.tsx b/src/main.tsx
index 8b8a8233..5129b4c6 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -7,7 +7,7 @@ import dayjs from 'dayjs'
import {If, For, When, Otherwise, Choose} from "tsx-control-statements/components";
import cn from "classnames"
import {TermWrap} from "./term";
-import {getDefaultSession, getLineId, Session} from "./session";
+import {getCurrentSession, getLineId, Session, initSession, newSession} from "./session";
import type {LineType, CmdDataType, RemoteType} from "./session";
import localizedFormat from 'dayjs/plugin/localizedFormat';
@@ -414,21 +414,20 @@ class MainSideBar extends React.Component<{}, {}> {
-
- Shared Sessions
-
-
Private Sessions
+
+ Shared Sessions
+
+
@@ -481,7 +480,7 @@ class Main extends React.Component<{}, {}> {
}
render() {
- let session = getDefaultSession();
+ let session = getCurrentSession();
return (
diff --git a/src/session.ts b/src/session.ts
index ff5e31a8..4260a368 100644
--- a/src/session.ts
+++ b/src/session.ts
@@ -50,7 +50,7 @@ type RemoteInstanceType = {
state : RemoteStateType,
}
-type WindowDataType = {
+type WindowType = {
sessionid : string,
windowid : string,
name : string,
@@ -60,6 +60,15 @@ type WindowDataType = {
version : number,
};
+type WindowDataType = {
+ sessionid : string,
+ windowid : string,
+ name : string,
+ curremote : string,
+ lines : LineType[],
+ version : number,
+};
+
type HistoryItem = {
cmdtext : string,
};
@@ -125,7 +134,7 @@ type CmdDataType = {
class Session {
sessionId : string;
name : string;
- windows : WindowDataType[];
+ windows : WindowType[];
activeWindowId : mobx.IObservableValue = mobx.observable.box(null);
termMap : Record = {};
termMapById : Record = {};
@@ -168,7 +177,7 @@ class Session {
return null;
}
- getWindowById(windowid : string) : WindowDataType {
+ getWindowById(windowid : string) : WindowType {
for (let i=0; i {
+ for (let i=0; i handleJsonFetchResponse(url, resp)).then((data) => {
- mobx.action(() => {
- window.lines.replace(data.data || []);
- window.linesLoading.set(false);
- })();
+ if (data.data == null) {
+ console.log("null window returned from get-window");
+ return;
+ }
+ this.setWindowInSession(data.data);
return;
}).catch((err) => {
console.log(sprintf("error getting window=%s lines", windowid), err)
@@ -346,7 +373,7 @@ class Session {
console.log("cmddata", pk);
}
- getActiveWindow() : WindowDataType {
+ getActiveWindow() : WindowType {
if (this.windows == null || this.windows.length == 0) {
return null;
}
@@ -360,45 +387,44 @@ class Session {
}
}
-var DefaultSession : Session = new Session();
+var CurrentSession : Session = new Session();
-function initSession() {
- if (DefaultSession.loading.get()) {
+function initSession(name : string) {
+ if (CurrentSession.loading.get()) {
return;
}
let remotesLoaded = false;
let sessionLoaded = false;
- DefaultSession.loading.set(true);
+ CurrentSession.loading.set(true);
fetch("http://localhost:8080/api/get-remotes").then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
mobx.action(() => {
- DefaultSession.globalRemotes = data.data
+ CurrentSession.globalRemotes = data.data
remotesLoaded = true;
if (remotesLoaded && sessionLoaded) {
- DefaultSession.loading.set(false);
+ CurrentSession.loading.set(false);
}
})();
}).catch((err) => {
console.log("error calling get-remotes", err)
});
- let usp = new URLSearchParams({name: "default"});
+ let usp = new URLSearchParams({name: name});
let url = new 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.sessionId = sdata.sessionid;
- DefaultSession.name = sdata.name;
- DefaultSession.windows = sdata.windows || [];
- for (let i=0; i {
@@ -406,11 +432,28 @@ function initSession() {
});
}
-function getDefaultSession() : Session {
- return DefaultSession;
+function winDataToWindow(win : WindowDataType) : WindowType {
+ let w = {
+ sessionid: win.sessionid,
+ windowid: win.windowid,
+ name: win.name,
+ curremote: win.curremote,
+ lines: mobx.observable.array(win.lines || []),
+ linesLoading: mobx.observable.box(false),
+ version: win.version,
+ };
+ return w;
}
-(window as any).getDefaultSession = getDefaultSession;
+function getCurrentSession() : Session {
+ return CurrentSession;
+}
-export {Session, getDefaultSession, getLineId, initSession};
-export type {LineType, WindowDataType, CmdDataType, RemoteType};
+function newSession() {
+
+}
+
+(window as any).getCurrentSession = getCurrentSession;
+
+export {Session, getCurrentSession, getLineId, initSession, newSession};
+export type {LineType, WindowType, CmdDataType, RemoteType};
diff --git a/src/sh2.ts b/src/sh2.ts
index fdb4319c..e4296660 100644
--- a/src/sh2.ts
+++ b/src/sh2.ts
@@ -13,7 +13,7 @@ let VERSION = __SHVERSION__;
(window as any).ScriptHausClientId = uuidv4();
document.addEventListener("DOMContentLoaded", () => {
- initSession();
+ initSession("default");
GlobalWS.reconnect();
let reactElem = React.createElement(Main, null, null);
let elem = document.getElementById("app");