mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
connstatus fix, update connection icons appropriately for status
This commit is contained in:
parent
ef95fd20ed
commit
74f551b212
@ -157,13 +157,14 @@ export const ConnectionButton = React.memo(
|
||||
const isLocal = util.isBlank(connection) || connection == "local";
|
||||
const connStatusAtom = getConnStatusAtom(connection);
|
||||
const connStatus = jotai.useAtomValue(connStatusAtom);
|
||||
const showDisconnectedSlash = !isLocal && !connStatus?.connected;
|
||||
let showDisconnectedSlash = false;
|
||||
let connIconElem: React.ReactNode = null;
|
||||
let color = "#53b4ea";
|
||||
const clickHandler = function () {
|
||||
setConnModalOpen(true);
|
||||
};
|
||||
let titleText = null;
|
||||
let shouldSpin = false;
|
||||
if (isLocal) {
|
||||
color = "var(--grey-text-color)";
|
||||
titleText = "Connected to Local Machine";
|
||||
@ -175,13 +176,27 @@ export const ConnectionButton = React.memo(
|
||||
);
|
||||
} else {
|
||||
titleText = "Connected to " + connection;
|
||||
if (!connStatus?.connected) {
|
||||
let iconName = "arrow-right-arrow-left";
|
||||
if (connStatus?.status == "connecting") {
|
||||
color = "var(--warning-color)";
|
||||
titleText = "Connecting to " + connection;
|
||||
iconName = "rotate";
|
||||
shouldSpin = true;
|
||||
} else if (connStatus?.status == "error") {
|
||||
color = "var(--error-color)";
|
||||
titleText = "Error connecting to " + connection;
|
||||
if (connStatus?.error != null) {
|
||||
titleText += " (" + connStatus.error + ")";
|
||||
}
|
||||
showDisconnectedSlash = true;
|
||||
} else if (!connStatus?.connected) {
|
||||
color = "var(--grey-text-color)";
|
||||
titleText = "Disconnected from " + connection;
|
||||
showDisconnectedSlash = true;
|
||||
}
|
||||
connIconElem = (
|
||||
<i
|
||||
className={clsx(util.makeIconClass("arrow-right-arrow-left", false), "fa-stack-1x")}
|
||||
className={clsx(util.makeIconClass(iconName, false), "fa-stack-1x")}
|
||||
style={{ color: color, marginRight: 2 }}
|
||||
/>
|
||||
);
|
||||
@ -189,7 +204,7 @@ export const ConnectionButton = React.memo(
|
||||
|
||||
return (
|
||||
<div ref={ref} className={clsx("connection-button")} onClick={clickHandler} title={titleText}>
|
||||
<span className="fa-stack connection-icon-box">
|
||||
<span className={clsx("fa-stack connection-icon-box", shouldSpin ? "fa-spin" : null)}>
|
||||
{connIconElem}
|
||||
<i
|
||||
className="fa-slash fa-solid fa-stack-1x"
|
||||
|
@ -568,12 +568,17 @@ async function loadConnStatus() {
|
||||
|
||||
function subscribeToConnEvents() {
|
||||
waveEventSubscribe("connchange", null, (event: WaveEvent) => {
|
||||
try {
|
||||
const connStatus = event.data as ConnStatus;
|
||||
if (connStatus == null || util.isBlank(connStatus.connection)) {
|
||||
console.log("connchange2 early return");
|
||||
return;
|
||||
}
|
||||
let curAtom = ConnStatusMap.get(connStatus.connection);
|
||||
let curAtom = getConnStatusAtom(connStatus.connection);
|
||||
globalStore.set(curAtom, connStatus);
|
||||
} catch (e) {
|
||||
console.log("connchange error", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ export class PreviewModel implements ViewModel {
|
||||
ceReadOnly: jotai.PrimitiveAtom<boolean>;
|
||||
isCeView: jotai.PrimitiveAtom<boolean>;
|
||||
previewTextRef: React.RefObject<HTMLDivElement>;
|
||||
editMode: jotai.Atom<boolean>;
|
||||
|
||||
fileName: jotai.Atom<string>;
|
||||
connection: jotai.Atom<string>;
|
||||
@ -114,6 +115,10 @@ export class PreviewModel implements ViewModel {
|
||||
const fileName = get(this.fileName);
|
||||
return iconForFile(mimeType, fileName);
|
||||
});
|
||||
this.editMode = jotai.atom((get) => {
|
||||
const blockData = get(this.blockAtom);
|
||||
return blockData?.meta?.edit ?? false;
|
||||
});
|
||||
this.viewName = jotai.atom("Preview");
|
||||
this.viewText = jotai.atom((get) => {
|
||||
if (get(this.isCeView)) {
|
||||
|
1
frontend/types/gotypes.d.ts
vendored
1
frontend/types/gotypes.d.ts
vendored
@ -237,6 +237,7 @@ declare global {
|
||||
file?: string;
|
||||
url?: string;
|
||||
connection?: string;
|
||||
edit?: boolean;
|
||||
history?: string[];
|
||||
"history:forward"?: string[];
|
||||
"display:name"?: string;
|
||||
|
@ -81,19 +81,19 @@ function jsonDeepEqual(v1: any, v2: any): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
function makeIconClass(icon: string, fw: boolean): string {
|
||||
function makeIconClass(icon: string, fw: boolean, opts?: { spin: boolean }): string {
|
||||
if (icon == null) {
|
||||
return null;
|
||||
}
|
||||
if (icon.match(/^(solid@)?[a-z0-9-]+$/)) {
|
||||
// strip off "solid@" prefix if it exists
|
||||
icon = icon.replace(/^solid@/, "");
|
||||
return clsx(`fa fa-sharp fa-solid fa-${icon}`, fw ? "fa-fw" : null);
|
||||
return clsx(`fa fa-sharp fa-solid fa-${icon}`, fw ? "fa-fw" : null, opts?.spin ? "fa-spin" : null);
|
||||
}
|
||||
if (icon.match(/^regular@[a-z0-9-]+$/)) {
|
||||
// strip off the "regular@" prefix if it exists
|
||||
icon = icon.replace(/^regular@/, "");
|
||||
return clsx(`fa fa-sharp fa-regular fa-${icon}`, fw ? "fa-fw" : null);
|
||||
return clsx(`fa fa-sharp fa-regular fa-${icon}`, fw ? "fa-fw" : null, opts?.spin ? "fa-spin" : null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ func (conn *SSHConn) FireConnChangeEvent() {
|
||||
},
|
||||
Data: status,
|
||||
}
|
||||
log.Printf("sending event: %+#v", event)
|
||||
log.Printf("connstatus change %q => %s\n", conn.GetName(), status.Status)
|
||||
wps.Broker.Publish(event)
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@ const (
|
||||
|
||||
MetaKey_Connection = "connection"
|
||||
|
||||
MetaKey_Edit = "edit"
|
||||
|
||||
MetaKey_History = "history"
|
||||
MetaKey_HistoryForward = "history:forward"
|
||||
|
||||
|
@ -18,6 +18,7 @@ type MetaTSType struct {
|
||||
File string `json:"file,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Connection string `json:"connection,omitempty"`
|
||||
Edit bool `json:"edit,omitempty"`
|
||||
History []string `json:"history,omitempty"`
|
||||
HistoryForward []string `json:"history:forward,omitempty"`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user