From 7867edb8da62962d8612ce047509e5865e3222be Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 12 Jul 2022 13:20:10 -0700 Subject: [PATCH] pass process id as client id to ws --- src/emain.ts | 3 ++- src/model.ts | 46 ++++++++++------------------------------------ 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/emain.ts b/src/emain.ts index c05cb238..bd3141f7 100644 --- a/src/emain.ts +++ b/src/emain.ts @@ -75,7 +75,8 @@ app.on('window-all-closed', () => { }); electron.ipcMain.on("get-id", (event) => { - return event.processId; + event.returnValue = event.processId; + return; }); diff --git a/src/model.ts b/src/model.ts index d31f795e..459260f7 100644 --- a/src/model.ts +++ b/src/model.ts @@ -16,6 +16,15 @@ function isBlank(s : string) { return (s == null || s == ""); } +type ElectronApi = { + getId : () => string, + onCmdT : (callback : () => void) => void, +}; + +function getApi() : ElectronApi { + return (window as any).api; +} + class Cmd { sessionId : string; windowId : string; @@ -391,7 +400,7 @@ class Model { remotesLoaded : OV = mobx.observable.box(false); constructor() { - this.clientId = uuidv4(); + this.clientId = getApi().getId(); this.loadRemotes(); this.loadSessionList(); this.ws = new WSControl(this.clientId, this.onWSMessage.bind(this)) @@ -575,38 +584,3 @@ GlobalModel = (window as any).GlobalModel; export {Model, Session, Window, GlobalModel, Cmd}; -// GlobalWS.registerAndSendGetCmd(getCmdPacket, (dataPacket) => { -// let realData = atob(dataPacket.ptydata64); -// this.updatePtyData(this.ptyPos, realData, dataPacket.ptydatalen); -// }); - - -/* -reloadTerminal(startTail : boolean, delayMs : number) { - loadPtyOut(this.terminal, this.sessionId, this.cmdId, delayMs, (ptyoutLen) => { - mobx.action(() => { - this.incRenderVersion(); - this.ptyPos = ptyoutLen; - })(); - if (startTail) { - this.startPtyTail(); - } - }); -} - - setCmdStatus(status : string) { - if (this.cmdStatus == status) { - return; - } - this.cmdStatus = status; - if (!this.isRunning() && this.tailReqId) { - this.stopPtyTail(); - } - } -} - - isRunning() : boolean { - return this.cmdStatus == "running" || this.cmdStatus == "detached"; - } -*/ -