From 98a55b2290c2c099b67fb9269c35d25895a6240a Mon Sep 17 00:00:00 2001 From: sawka Date: Thu, 5 Sep 2024 18:54:12 -0700 Subject: [PATCH] updates for local --- emain/platform.ts | 3 +++ emain/preload.ts | 1 + frontend/app/block/blockframe.tsx | 10 ++++++++-- frontend/app/store/global.ts | 10 ++++++++++ frontend/types/custom.d.ts | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/emain/platform.ts b/emain/platform.ts index 0347b972b..b939ba9c1 100644 --- a/emain/platform.ts +++ b/emain/platform.ts @@ -31,6 +31,9 @@ ipcMain.on("get-user-name", (event) => { const userInfo = os.userInfo(); event.returnValue = userInfo.username; }); +ipcMain.on("get-host-name", (event) => { + event.returnValue = os.hostname(); +}); // must match golang function getWaveHomeDir() { diff --git a/emain/preload.ts b/emain/preload.ts index 448dd9096..b74ee7a08 100644 --- a/emain/preload.ts +++ b/emain/preload.ts @@ -9,6 +9,7 @@ contextBridge.exposeInMainWorld("api", { getPlatform: () => ipcRenderer.sendSync("get-platform"), getCursorPoint: () => ipcRenderer.sendSync("get-cursor-point"), getUserName: () => ipcRenderer.sendSync("get-user-name"), + getHostName: () => ipcRenderer.sendSync("get-host-name"), getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"), openNewWindow: () => ipcRenderer.send("open-new-window"), showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position), diff --git a/frontend/app/block/blockframe.tsx b/frontend/app/block/blockframe.tsx index 17d4f2e47..83ecd5a07 100644 --- a/frontend/app/block/blockframe.tsx +++ b/frontend/app/block/blockframe.tsx @@ -17,6 +17,8 @@ import { atoms, getBlockComponentModel, getConnStatusAtom, + getHostName, + getUserName, globalStore, useBlockAtom, useSettingsKeyAtom, @@ -489,6 +491,9 @@ const ChangeConnectionBlockModal = React.memo( } catch (e) { console.log("unable to load conn list from backend. using blank list: ", e); } + if (!connList) { + connList = []; + } let createNew: boolean = true; if (connSelected == "") { createNew = false; @@ -537,6 +542,7 @@ const ChangeConnectionBlockModal = React.memo( headerText: "", items: priorityItems, }; + const localName = getUserName() + "@" + getHostName(); const localSuggestion: SuggestionConnectionScope = { headerText: "Local", items: [ @@ -545,7 +551,7 @@ const ChangeConnectionBlockModal = React.memo( icon: "laptop", iconColor: "var(--grey-text-color)", value: "", - label: "Switch to Local Connection", + label: localName, // TODO: need to specify user name and host name onSelect: (_: string) => { changeConnection(""); @@ -619,7 +625,7 @@ const ChangeConnectionBlockModal = React.memo( onKeyDown={(e) => keyutil.keydownWrapper(handleTypeAheadKeyDown)(e)} onChange={(current: string) => setConnSelected(current)} value={connSelected} - label="username@host" + label="Connect to (username@host)..." onClickBackdrop={() => globalStore.set(changeConnModalAtom, false)} /> ); diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index 4bc1c98ef..2d6dfd564 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -507,6 +507,15 @@ function getUserName(): string { return cachedUserName; } +let cachedHostName: string = null; + +function getHostName(): string { + if (cachedHostName == null) { + cachedHostName = getApi().getHostName(); + } + return cachedHostName; +} + /** * Open a link in a new window, or in a new web widget. The user can set all links to open in a new web widget using the `web:openlinksinternally` setting. * @param uri The link to open. @@ -642,6 +651,7 @@ export { getEventORefSubject, getEventSubject, getFileSubject, + getHostName, getObjectId, getUserName, globalStore, diff --git a/frontend/types/custom.d.ts b/frontend/types/custom.d.ts index a0ceea084..18c56a759 100644 --- a/frontend/types/custom.d.ts +++ b/frontend/types/custom.d.ts @@ -54,6 +54,7 @@ declare global { getPlatform: () => NodeJS.Platform; getEnv: (varName: string) => string; getUserName: () => string; + getHostName: () => string; getAboutModalDetails: () => AboutModalDetails; showContextMenu: (menu?: ElectronContextMenuItem[]) => void; onContextMenuClick: (callback: (id: string) => void) => void;