Skip to content
Closed
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
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ tauri-plugin-flags = { path = "plugins/flags" }
tauri-plugin-listener = { path = "plugins/listener" }
tauri-plugin-local-llm = { path = "plugins/local-llm" }
tauri-plugin-local-stt = { path = "plugins/local-stt" }
tauri-plugin-location-connectivity = { path = "plugins/location-connectivity" }
tauri-plugin-membership = { path = "plugins/membership" }
tauri-plugin-misc = { path = "plugins/misc" }
tauri-plugin-notification = { path = "plugins/notification" }
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@hypr/plugin-db": "workspace:^",
"@hypr/plugin-flags": "workspace:^",
"@hypr/plugin-listener": "workspace:^",
"@hypr/plugin-location-connectivity": "workspace:^",
"@hypr/plugin-local-llm": "workspace:^",
"@hypr/plugin-local-stt": "workspace:^",
"@hypr/plugin-membership": "workspace:^",
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tauri-plugin-flags = { workspace = true }
tauri-plugin-listener = { workspace = true }
tauri-plugin-local-llm = { workspace = true }
tauri-plugin-local-stt = { workspace = true }
tauri-plugin-location-connectivity = { workspace = true }
tauri-plugin-machine-uid = { workspace = true }
tauri-plugin-membership = { workspace = true }
tauri-plugin-misc = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub async fn main() {
.plugin(tauri_plugin_local_llm::init())
.plugin(tauri_plugin_local_stt::init())
.plugin(tauri_plugin_connector::init())
.plugin(tauri_plugin_location_connectivity::init())
.plugin(tauri_plugin_flags::init())
.plugin(tauri_plugin_sentry::init(&client))
.plugin(tauri_plugin_os::init())
Expand Down
179 changes: 178 additions & 1 deletion apps/desktop/src/components/settings/views/lab.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { Trans } from "@lingui/react/macro";
import { useMutation, useQuery } from "@tanstack/react-query";
import { CloudLightningIcon } from "lucide-react";
import { CloudLightningIcon, MapPinIcon, PlusIcon, XIcon } from "lucide-react";
import { useState } from "react";

import { commands as flagsCommands } from "@hypr/plugin-flags";
import { commands as locationCommands } from "@hypr/plugin-location-connectivity";
import { Button } from "@hypr/ui/components/ui/button";
import { Input } from "@hypr/ui/components/ui/input";
import { Switch } from "@hypr/ui/components/ui/switch";

export default function Lab() {
return (
<div>
<div className="space-y-4">
<CloudPreview />
<LocationBasedConnectivity />
</div>
</div>
);
Expand Down Expand Up @@ -49,6 +54,178 @@ function CloudPreview() {
);
}

function LocationBasedConnectivity() {
const [newSsid, setNewSsid] = useState("");

const enabledQuery = useQuery({
queryKey: ["location-connectivity", "enabled"],
queryFn: () => locationCommands.isLocationBasedEnabled(),
});

const trustedSsidsQuery = useQuery({
queryKey: ["location-connectivity", "trusted-ssids"],
queryFn: () => locationCommands.getTrustedSsids(),
});

const currentSsidQuery = useQuery({
queryKey: ["location-connectivity", "current-ssid"],
queryFn: () => locationCommands.getCurrentSsid(),
refetchInterval: 5000, // Check every 5 seconds
});

const toggleMutation = useMutation({
mutationFn: async (enabled: boolean) => {
await locationCommands.setLocationBasedEnabled(enabled);
},
onSuccess: () => {
enabledQuery.refetch();
trustedSsidsQuery.refetch();
},
});

const addSsidMutation = useMutation({
mutationFn: async (ssid: string) => {
await locationCommands.addTrustedSsid(ssid);
},
onSuccess: () => {
trustedSsidsQuery.refetch();
setNewSsid("");
},
});

const removeSsidMutation = useMutation({
mutationFn: async (ssid: string) => {
await locationCommands.removeTrustedSsid(ssid);
},
onSuccess: () => {
trustedSsidsQuery.refetch();
},
});

const handleAddCurrentSsid = () => {
if (currentSsidQuery.data) {
addSsidMutation.mutate(currentSsidQuery.data);
}
};

const handleAddCustomSsid = () => {
if (newSsid.trim()) {
addSsidMutation.mutate(newSsid.trim());
}
};

return (
<div className="flex flex-col rounded-lg border p-4">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-3">
<div className="flex size-6 items-center justify-center">
<MapPinIcon />
</div>
<div>
<div className="text-sm font-medium">
<Trans>Location-Based Connectivity</Trans>
</div>
<div className="text-xs text-muted-foreground">
<Trans>Automatically switch to cloud AI when in trusted locations</Trans>
</div>
</div>
</div>
<div className="flex items-center gap-2">
<Switch
checked={enabledQuery.data ?? false}
onCheckedChange={toggleMutation.mutate}
color="gray"
/>
</div>
</div>

{enabledQuery.data && (
<div className="space-y-4">
{/* Current WiFi Status */}
<div className="flex items-center justify-between p-3 bg-muted rounded-lg">
<div>
<div className="text-sm font-medium">Current Network</div>
<div className="text-xs text-muted-foreground">
{currentSsidQuery.data
? (
<>
{currentSsidQuery.data}
{trustedSsidsQuery.data?.includes(currentSsidQuery.data) && (
<span className="ml-2 text-green-600">• Trusted</span>
)}
</>
)
: (
"No WiFi connected"
)}
</div>
</div>
{currentSsidQuery.data
&& !trustedSsidsQuery.data?.includes(currentSsidQuery.data) && (
<Button
variant="outline"
size="sm"
onClick={handleAddCurrentSsid}
disabled={addSsidMutation.isPending}
>
<PlusIcon className="size-4 mr-1" />
Add Current
</Button>
)}
</div>

{/* Trusted Networks List */}
<div>
<div className="text-sm font-medium mb-2">Trusted Networks</div>
<div className="space-y-2">
{trustedSsidsQuery.data?.map((ssid: string) => (
<div
key={ssid}
className="flex items-center justify-between p-2 bg-muted rounded"
>
<span className="text-sm">{ssid}</span>
<Button
variant="ghost"
size="sm"
onClick={() => removeSsidMutation.mutate(ssid)}
disabled={removeSsidMutation.isPending}
>
<XIcon className="size-4" />
</Button>
</div>
))}

{trustedSsidsQuery.data?.length === 0 && (
<div className="text-xs text-muted-foreground p-2">
No trusted networks configured
</div>
)}
</div>
</div>

{/* Add Custom Network */}
<div className="flex gap-2">
<Input
placeholder="Enter network name (SSID)"
value={newSsid}
onChange={(e) => setNewSsid(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && handleAddCustomSsid()}
/>
<Button
variant="outline"
size="sm"
onClick={handleAddCustomSsid}
disabled={!newSsid.trim() || addSsidMutation.isPending}
>
<PlusIcon className="size-4" />
</Button>
</div>
</div>
)}
</div>
);
}

function FeatureFlag({
title,
description,
Expand Down
Loading
Loading