Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/desktop/src/lib/trpc/routers/device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getHostId } from "@superset/shared/host-info";
import { publicProcedure, router } from "..";

export const createDeviceRouter = () => {
return router({
getMachineId: publicProcedure.query((): { machineId: string } => {
return { machineId: getHostId() };
}),
});
};
2 changes: 2 additions & 0 deletions apps/desktop/src/lib/trpc/routers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createChangesRouter } from "./changes";
import { createChatRuntimeServiceRouter } from "./chat-runtime-service";
import { createChatServiceRouter } from "./chat-service";
import { createConfigRouter } from "./config";
import { createDeviceRouter } from "./device";
import { createExternalRouter } from "./external";
import { createFilesystemRouter } from "./filesystem";
import { createHostServiceCoordinatorRouter } from "./host-service-coordinator";
Expand Down Expand Up @@ -52,6 +53,7 @@ export const createAppRouter = (getWindow: () => BrowserWindow | null) => {
external: createExternalRouter(),
settings: createSettingsRouter(),
config: createConfigRouter(),
device: createDeviceRouter(),
uiState: createUiStateRouter(),
ringtone: createRingtoneRouter(getWindow),
hostServiceCoordinator: createHostServiceCoordinatorRouter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MOCK_ORG_ID } from "shared/constants";
import { useCollections } from "../CollectionsProvider";

interface LocalHostServiceContextValue {
machineId: string | null;
machineId: string;
activeHostUrl: string | null;
}

Expand Down Expand Up @@ -51,27 +51,34 @@ export function LocalHostServiceProvider({
}
}, [organizationIds, startHostService]);

const { data: machineIdData } = electronTrpc.device.getMachineId.useQuery(
undefined,
{ staleTime: Number.POSITIVE_INFINITY },
);

const { data: activeConnection } =
electronTrpc.hostServiceCoordinator.getConnection.useQuery(
{ organizationId: activeOrganizationId as string },
{ enabled: !!activeOrganizationId, refetchInterval: 5_000 },
);

const value = useMemo(() => {
const value = useMemo<LocalHostServiceContextValue | null>(() => {
if (!machineIdData) return null;
const machineId = machineIdData.machineId;

if (!activeConnection?.port) {
return { machineId: null, activeHostUrl: null };
return { machineId, activeHostUrl: null };
}

const activeHostUrl = `http://127.0.0.1:${activeConnection.port}`;
if (activeConnection.secret) {
setHostServiceSecret(activeHostUrl, activeConnection.secret);
}

return {
machineId: activeConnection.machineId ?? null,
activeHostUrl,
};
}, [activeConnection]);
return { machineId, activeHostUrl };
}, [machineIdData, activeConnection]);

if (!value) return null;

return (
<LocalHostServiceContext.Provider value={value}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function ProjectLocationSection({
(q) =>
q
.from({ hosts: collections.v2Hosts })
.where(({ hosts }) => eq(hosts.machineId, machineId ?? ""))
.where(({ hosts }) => eq(hosts.machineId, machineId))
.select(({ hosts }) => ({
name: hosts.name,
isOnline: hosts.isOnline,
Expand Down
Loading