updates for local

This commit is contained in:
sawka 2024-09-05 18:54:12 -07:00
parent 9ef6745d66
commit 98a55b2290
5 changed files with 23 additions and 2 deletions

View File

@ -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() {

View File

@ -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),

View File

@ -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)}
/>
);

View File

@ -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,

View File

@ -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;