mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-23 20:11:03 +00:00
fix: add a neutral linked desktop hook for plugins (#1580)
This commit is contained in:
1 parent
b0f2213b15
commit
e284c95891
4 files changed
+23
-1
No files matched your search
@@ -584,6 +584,7 @@ useChooseTheme (value): () => (themeId: string) => void
|
||||
useConfirm (value): () => (options: ConfirmOptions) => Promise<boolean>
|
||||
useConnectionGate (value): () => ConnectionGateController
|
||||
useConnectionLog (value): () => ConnectionLogContextType
|
||||
useDesktopLinked (value): () => boolean
|
||||
useDesktopUpdate (value): () => DesktopUpdateState
|
||||
useEditorDefaultKeys (value): () => Map<string, EditorDefaultKey>
|
||||
useHostActions (value): () => HostActionDef[]
|
||||
|
||||
@@ -605,6 +605,7 @@ const ALLOWED = [
|
||||
"useConfirm",
|
||||
"useConnectionGate",
|
||||
"useConnectionLog",
|
||||
"useDesktopLinked",
|
||||
"useDesktopUpdate",
|
||||
"useEditorDefaultKeys",
|
||||
"useHostActions",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { isElectron } from "@/lib/electron";
|
||||
import { authApi } from "@/main-axios";
|
||||
import { SYNC_CHANGED_EVENT } from "@/lib/sync-events";
|
||||
@@ -48,3 +49,22 @@ export function notifySyncChanged(): void {
|
||||
cached = null;
|
||||
window.dispatchEvent(new CustomEvent(SYNC_CHANGED_EVENT));
|
||||
}
|
||||
|
||||
/** Whether this desktop is linked to a server, kept current as it changes. */
|
||||
export function useDesktopLinked(): boolean {
|
||||
const [linked, setLinked] = useState(false);
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
const read = () =>
|
||||
void getLinkedSession().then((session) => {
|
||||
if (live) setLinked(!!session);
|
||||
});
|
||||
read();
|
||||
window.addEventListener(SYNC_CHANGED_EVENT, read);
|
||||
return () => {
|
||||
live = false;
|
||||
window.removeEventListener(SYNC_CHANGED_EVENT, read);
|
||||
};
|
||||
}, []);
|
||||
return linked;
|
||||
}
|
||||
@@ -574,7 +574,7 @@ export {
|
||||
invalidateServerStatusCache,
|
||||
} from "@/lib/hosts-request-cache";
|
||||
export { reportBetaFeedbackUrl, reportCoreIssueUrl } from "@/lib/issue-url";
|
||||
export { notifySyncChanged } from "@/lib/linked-server";
|
||||
export { notifySyncChanged, useDesktopLinked } from "@/lib/linked-server";
|
||||
export {
|
||||
clearLocalAdaptivePreferences,
|
||||
getPreferredHostAction,
|
||||
|
||||
Reference in new issue
Block a user