mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-09 19:48:45 +01:00
checkpoint, reading session from server
This commit is contained in:
parent
7d059fe573
commit
bfaa504249
@ -318,8 +318,14 @@ class SessionView extends React.Component<{session : SessionType}, {}> {
|
|||||||
render() {
|
render() {
|
||||||
let session = this.props.session;
|
let session = this.props.session;
|
||||||
let window = session.getActiveWindow();
|
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;
|
let idx = 0;
|
||||||
|
if (session.loading.get()) {
|
||||||
|
return <div className="session-view">(loading)</div>;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="session-view">
|
<div className="session-view">
|
||||||
<div className="lines" onScroll={this.scrollHandler}>
|
<div className="lines" onScroll={this.scrollHandler}>
|
||||||
|
@ -37,27 +37,46 @@ function getLineId(line : LineType) : string {
|
|||||||
return sprintf("%s-%s-%s", line.sessionid, line.windowid, line.lineid);
|
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,
|
sessionid : string,
|
||||||
windowid : string,
|
windowid : string,
|
||||||
name : string,
|
name : string,
|
||||||
|
curremote : string,
|
||||||
|
remotes : SessionRemoteDataType[],
|
||||||
lines : LineType[],
|
lines : LineType[],
|
||||||
|
version : number,
|
||||||
};
|
};
|
||||||
|
|
||||||
type HistoryItem = {
|
type HistoryItem = {
|
||||||
cmdtext : string,
|
cmdtext : string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type SessionDataType = {
|
||||||
|
sessionid : string,
|
||||||
|
name : string,
|
||||||
|
windows : WindowDataType[],
|
||||||
|
cmds : CmdDataType[],
|
||||||
|
};
|
||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
sessionId : string;
|
sessionId : string;
|
||||||
name : string;
|
name : string;
|
||||||
windows : WindowType[];
|
windows : WindowDataType[];
|
||||||
activeWindowId : string;
|
activeWindowId : mobx.IObservableValue<string> = mobx.observable.box(null);
|
||||||
termMap : Record<string, TermWrap> = {};
|
termMap : Record<string, TermWrap> = {};
|
||||||
termMapById : Record<string, TermWrap> = {};
|
termMapById : Record<string, TermWrap> = {};
|
||||||
history : HistoryItem[] = [];
|
history : HistoryItem[] = [];
|
||||||
curRemote : string;
|
curRemote : string;
|
||||||
curDir : string;
|
curDir : string;
|
||||||
|
loading : mobx.IObservableValue<boolean> = mobx.observable.box(false);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
@ -124,12 +143,13 @@ class Session {
|
|||||||
console.log("cmddata", pk);
|
console.log("cmddata", pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
getActiveWindow() : WindowType {
|
getActiveWindow() : WindowDataType {
|
||||||
if (this.windows == null) {
|
if (this.windows == null || this.windows.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
let awid = this.activeWindowId.get();
|
||||||
for (let i=0; i<this.windows.length; i++) {
|
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];
|
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 {
|
function getDefaultSession() : Session {
|
||||||
|
return DefaultSession;
|
||||||
|
|
||||||
if (DefaultSession != null) {
|
if (DefaultSession != null) {
|
||||||
return DefaultSession;
|
return DefaultSession;
|
||||||
}
|
}
|
||||||
@ -157,5 +199,5 @@ function getDefaultSession() : Session {
|
|||||||
|
|
||||||
window.getDefaultSession = getDefaultSession;
|
window.getDefaultSession = getDefaultSession;
|
||||||
|
|
||||||
export {Session, getDefaultSession, getLineId};
|
export {Session, getDefaultSession, getLineId, loadDefaultSession};
|
||||||
export type {LineType, WindowType};
|
export type {LineType, WindowDataType};
|
||||||
|
@ -5,12 +5,14 @@ import {Terminal} from 'xterm';
|
|||||||
import {Main} from "./main";
|
import {Main} from "./main";
|
||||||
import {GlobalWS} from "./ws";
|
import {GlobalWS} from "./ws";
|
||||||
import {v4 as uuidv4} from "uuid";
|
import {v4 as uuidv4} from "uuid";
|
||||||
|
import {loadDefaultSession} from "./session";
|
||||||
|
|
||||||
let VERSION = __SHVERSION__;
|
let VERSION = __SHVERSION__;
|
||||||
|
|
||||||
window.ScriptHausClientId = uuidv4();
|
window.ScriptHausClientId = uuidv4();
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
loadDefaultSession();
|
||||||
GlobalWS.reconnect();
|
GlobalWS.reconnect();
|
||||||
let reactElem = React.createElement(Main, null, null);
|
let reactElem = React.createElement(Main, null, null);
|
||||||
let elem = document.getElementById("app");
|
let elem = document.getElementById("app");
|
||||||
|
Loading…
Reference in New Issue
Block a user