fix: add a neutral linked desktop hook for plugins (#1580)

This commit is contained in:
LukeGus committed 2026-10-19 17:07:07 -05:00
1 parent b0f2213b15
commit e284c95891
4 files changed
+23 -1

No files matched your search

+1
View File
@@ -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[]
+1
View File
@@ -605,6 +605,7 @@ const ALLOWED = [
"useConfirm",
"useConnectionGate",
"useConnectionLog",
"useDesktopLinked",
"useDesktopUpdate",
"useEditorDefaultKeys",
"useHostActions",
+20
View File
@@ -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;
}
+1 -1
View File
@@ -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,