mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-03-09 13:00:53 +01:00
working on separate prompt-dev version
This commit is contained in:
parent
cbf185a715
commit
4e7929ee63
28
src/base.ts
28
src/base.ts
@ -1,28 +0,0 @@
|
||||
import * as path from "path";
|
||||
import * as fs from "fs";
|
||||
|
||||
const HomeVarName = "HOME";
|
||||
const PromptHomeVarName = "PROMPT_HOME";
|
||||
const PromptLockFile = "prompt-electron.lock";
|
||||
const DBFileName = "prompt.db";
|
||||
const SessionsDirBaseName = "sessions";
|
||||
const RemotesDirBaseName = "remotes";
|
||||
const PromptDirName = "prompt";
|
||||
|
||||
function getPromptHomeDir() : string {
|
||||
if (process.env[PromptHomeVarName]) {
|
||||
return process.env[PromptHomeVarName];
|
||||
}
|
||||
let homeDir = process.env[HomeVarName];
|
||||
if (!homeDir) {
|
||||
homeDir = "/";
|
||||
}
|
||||
return path.join(homeDir, PromptDirName);
|
||||
}
|
||||
|
||||
function getDBName() : string {
|
||||
let promptHome = getPromptHomeDir();
|
||||
return path.join(promptHome, DBFileName);
|
||||
}
|
||||
|
||||
export {getPromptHomeDir, getDBName};
|
17
src/emain.ts
17
src/emain.ts
@ -51,7 +51,7 @@ if (isDev) {
|
||||
console.log("prompt-app PROMPT_DEV set");
|
||||
}
|
||||
let app = electron.app;
|
||||
app.setName("Prompt");
|
||||
app.setName((isDev ? "Prompt (Dev)" : "Prompt"));
|
||||
const DevLocalServerPath = "/Users/mike/prompt/local-server";
|
||||
let localServerProc = null;
|
||||
let localServerShouldRestart = false;
|
||||
@ -75,6 +75,10 @@ function getAppBasePath() {
|
||||
return path.dirname(__dirname);
|
||||
}
|
||||
|
||||
function getBaseHostPort() {
|
||||
return "http://localhost:8080";
|
||||
}
|
||||
|
||||
function getLocalServerPath() {
|
||||
if (isDev) {
|
||||
return DevLocalServerPath
|
||||
@ -103,7 +107,7 @@ function readAuthKey() {
|
||||
let authKeyFileName = path.join(homeDir, AuthKeyFile);
|
||||
if (!fs.existsSync(authKeyFileName)) {
|
||||
let authKeyStr = String(uuidv4());
|
||||
fs.writeFileSync(authKeyFileName, authKeyStr, 0o600);
|
||||
fs.writeFileSync(authKeyFileName, authKeyStr, {mode: 0o600});
|
||||
return authKeyStr;
|
||||
}
|
||||
let authKeyData = fs.readFileSync(authKeyFileName);
|
||||
@ -256,7 +260,7 @@ function mainResizeHandler(e) {
|
||||
let bounds = win.getBounds();
|
||||
console.log("resize/move", win.getBounds());
|
||||
let winSize = {width: bounds.width, height: bounds.height, top: bounds.y, left: bounds.x};
|
||||
let url = "http://localhost:8080/api/set-winsize";
|
||||
let url = getBaseHostPort() + "/api/set-winsize";
|
||||
let fetchHeaders = getFetchHeaders();
|
||||
fetch(url, {method: "post", body: JSON.stringify(winSize), headers: fetchHeaders}).then((resp) => handleJsonFetchResponse(url, resp)).catch((err) => {
|
||||
console.log("error setting winsize", err)
|
||||
@ -312,6 +316,11 @@ electron.ipcMain.on("get-id", (event) => {
|
||||
return;
|
||||
});
|
||||
|
||||
electron.ipcMain.on("get-isdev", (event) => {
|
||||
event.returnValue = isDev;
|
||||
return;
|
||||
});
|
||||
|
||||
electron.ipcMain.on("get-authkey", (event) => {
|
||||
event.returnValue = GlobalAuthKey;
|
||||
return;
|
||||
@ -349,7 +358,7 @@ function getFetchHeaders() {
|
||||
}
|
||||
|
||||
function getClientData() {
|
||||
let url = "http://localhost:8080/api/get-client-data";
|
||||
let url = getBaseHostPort() + "/api/get-client-data";
|
||||
let fetchHeaders = getFetchHeaders();
|
||||
return fetch(url, {headers: fetchHeaders}).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
||||
if (data == null) {
|
||||
|
@ -297,7 +297,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
|
||||
let {line} = this.props;
|
||||
this.rtnStateDiffFetched = true;
|
||||
let usp = new URLSearchParams({sessionid: line.sessionid, cmdid: line.cmdid});
|
||||
let url = "http://localhost:8080/api/rtnstate?" + usp.toString();
|
||||
let url = GlobalModel.getBaseHostPort() + "/api/rtnstate?" + usp.toString();
|
||||
let fetchHeaders = GlobalModel.getFetchHeaders();
|
||||
fetch(url, {headers: fetchHeaders}).then((resp) => {
|
||||
if (!resp.ok) {
|
||||
|
17
src/model.ts
17
src/model.ts
@ -92,6 +92,7 @@ type KeyModsType = {
|
||||
|
||||
type ElectronApi = {
|
||||
getId : () => string,
|
||||
getIsDev : () => boolean,
|
||||
getAuthKey : () => string,
|
||||
getLocalServerStatus : () => boolean,
|
||||
restartLocalServer : () => boolean,
|
||||
@ -1552,11 +1553,13 @@ class Model {
|
||||
debugSW : OV<boolean> = mobx.observable.box(false);
|
||||
localServerRunning : OV<boolean>;
|
||||
authKey : string;
|
||||
isDev : boolean;
|
||||
|
||||
constructor() {
|
||||
this.clientId = getApi().getId();
|
||||
this.isDev = getApi().getIsDev();
|
||||
this.authKey = getApi().getAuthKey();
|
||||
this.ws = new WSControl(this.clientId, this.authKey, (message : any) => this.runUpdate(message, false));
|
||||
this.ws = new WSControl(this.getBaseWsHostPort(), this.clientId, this.authKey, (message : any) => this.runUpdate(message, false));
|
||||
this.ws.reconnect();
|
||||
this.inputModel = new InputModel();
|
||||
let isLocalServerRunning = getApi().getLocalServerStatus();
|
||||
@ -1575,6 +1578,14 @@ class Model {
|
||||
document.addEventListener("keydown", this.docKeyDownHandler.bind(this));
|
||||
}
|
||||
|
||||
getBaseHostPort() : string {
|
||||
return "http://localhost:8080";
|
||||
}
|
||||
|
||||
getBaseWsHostPort() : string {
|
||||
return "ws://localhost:8081";
|
||||
}
|
||||
|
||||
getFetchHeaders() : Record<string, string> {
|
||||
return {
|
||||
"x-authkey": this.authKey,
|
||||
@ -1994,7 +2005,7 @@ class Model {
|
||||
console.trace();
|
||||
}
|
||||
}
|
||||
let url = sprintf("http://localhost:8080/api/run-command");
|
||||
let url = sprintf(GlobalModel.getBaseHostPort() + "/api/run-command");
|
||||
let fetchHeaders = this.getFetchHeaders();
|
||||
fetch(url, {method: "post", body: JSON.stringify(cmdPk), headers: fetchHeaders}).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
||||
mobx.action(() => {
|
||||
@ -2078,7 +2089,7 @@ class Model {
|
||||
_loadWindowAsync(newWin : Window) {
|
||||
this.windows.set(newWin.sessionId + "/" + newWin.windowId, newWin);
|
||||
let usp = new URLSearchParams({sessionid: newWin.sessionId, windowid: newWin.windowId});
|
||||
let url = new URL("http://localhost:8080/api/get-window?" + usp.toString());
|
||||
let url = new URL(GlobalModel.getBaseHostPort() + "/api/get-window?" + usp.toString());
|
||||
let fetchHeaders = GlobalModel.getFetchHeaders();
|
||||
fetch(url, {headers: fetchHeaders}).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
||||
if (data.data == null) {
|
||||
|
@ -2,6 +2,7 @@ let {contextBridge, ipcRenderer} = require("electron");
|
||||
|
||||
contextBridge.exposeInMainWorld("api", {
|
||||
getId: () => ipcRenderer.sendSync("get-id"),
|
||||
getIsDev: () => ipcRenderer.sendSync("get-isdev"),
|
||||
getAuthKey: () => ipcRenderer.sendSync("get-authkey"),
|
||||
getLocalServerStatus: () => ipcRenderer.sendSync("local-server-status"),
|
||||
restartLocalServer: () => ipcRenderer.sendSync("restart-server"),
|
||||
|
@ -230,10 +230,10 @@ class TermWrap {
|
||||
|
||||
_getReloadUrl() : string {
|
||||
if (this.termContext.remoteId != null) {
|
||||
return sprintf("http://localhost:8080/api/remote-pty?remoteid=%s", this.termContext.remoteId);
|
||||
return sprintf(GlobalModel.getBaseHostPort() + "/api/remote-pty?remoteid=%s", this.termContext.remoteId);
|
||||
}
|
||||
else {
|
||||
return sprintf("http://localhost:8080/api/ptyout?sessionid=%s&cmdid=%s", this.termContext.sessionId, this.termContext.cmdId);
|
||||
return sprintf(GlobalModel.getBaseHostPort() + "/api/ptyout?sessionid=%s&cmdid=%s", this.termContext.sessionId, this.termContext.cmdId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,10 @@ class WSControl {
|
||||
watchScreenId : string = null;
|
||||
wsLog : mobx.IObservableArray<string> = mobx.observable.array([], {name: "wsLog"})
|
||||
authKey : string;
|
||||
baseHostPort : string;
|
||||
|
||||
constructor(clientId : string, authKey : string, messageCallback : (any) => void) {
|
||||
constructor(baseHostPort : string, clientId : string, authKey : string, messageCallback : (any) => void) {
|
||||
this.baseHostPort = baseHostPort;
|
||||
this.messageCallback = messageCallback;
|
||||
this.clientId = clientId;
|
||||
this.authKey = authKey;
|
||||
@ -48,7 +50,7 @@ class WSControl {
|
||||
}
|
||||
this.log(sprintf("try reconnect (%s)", desc));
|
||||
this.opening = true;
|
||||
this.wsConn = new WebSocket("ws://localhost:8081/ws?clientid=" + this.clientId);
|
||||
this.wsConn = new WebSocket(this.baseHostPort + "/ws?clientid=" + this.clientId);
|
||||
this.wsConn.onopen = this.onopen;
|
||||
this.wsConn.onmessage = this.onmessage;
|
||||
this.wsConn.onclose = this.onclose;
|
||||
|
Loading…
Reference in New Issue
Block a user