Add a Navigate app (requires a Mapbox API token)

This commit is contained in:
James Babcock committed 2026-07-25 23:32:01 -07:00
1 parent 3c2f53ed75
commit bde70ac380
16 files changed
+2096 -4

No files matched your search

+29
View File
@@ -4,10 +4,12 @@ const PERMISSION_REQUEST_CODE = 4242;
const VOICE_PERMISSION_REQUEST_CODE = 4243;
const CALENDAR_PERMISSION_REQUEST_CODE = 4244;
const LOCATION_PERMISSION_REQUEST_CODE = 4245;
const FINE_LOCATION_PERMISSION_REQUEST_CODE = 4246;
const POST_NOTIFICATIONS_PERMISSION = "android.permission.POST_NOTIFICATIONS";
const RECORD_AUDIO_PERMISSION = "android.permission.RECORD_AUDIO";
const READ_CALENDAR_PERMISSION = "android.permission.READ_CALENDAR";
const ACCESS_COARSE_LOCATION_PERMISSION = "android.permission.ACCESS_COARSE_LOCATION";
const ACCESS_FINE_LOCATION_PERMISSION = "android.permission.ACCESS_FINE_LOCATION";
function getActivity(): androidx.appcompat.app.AppCompatActivity {
const activity = Application.android.foregroundActivity ?? Application.android.startActivity;
@@ -126,6 +128,33 @@ export async function ensureCalendarPermission(): Promise<boolean> {
}
}
/** Whether precise (GPS) foreground location access has been granted. */
export function hasFineLocationPermission(): boolean {
if (!global.isAndroid) return false;
return isPermissionGranted(ACCESS_FINE_LOCATION_PERMISSION);
}
/**
* Prompt for precise foreground location access (navigation needs GPS fixes
* with bearing). Requests coarse alongside fine so Android's "approximate
* only" choice degrades gracefully rather than denying outright; resolves
* true only when precise access is actually held.
*/
export async function ensureFineLocationPermission(): Promise<boolean> {
if (!global.isAndroid) return false;
try {
await ensurePermissions(
[ACCESS_FINE_LOCATION_PERMISSION, ACCESS_COARSE_LOCATION_PERMISSION],
FINE_LOCATION_PERMISSION_REQUEST_CODE,
"Location",
);
} catch {
// Fall through: the user may have granted approximate-only, which still
// reports as a denial of fine. Re-check what is actually held.
}
return hasFineLocationPermission();
}
/** Whether approximate foreground location access has been granted. */
export function hasLocationPermission(): boolean {
if (!global.isAndroid) return false;
+21 -1
View File
@@ -8,7 +8,7 @@ import {
OsEventTypeName,
} from "./events";
import { loadDeviceAddresses } from "./device-addresses";
import { ensureBlePermissions, ensureVoicePermissions } from "./android-permissions";
import { ensureBlePermissions, ensureFineLocationPermission, ensureVoicePermissions } from "./android-permissions";
import { FaceclawCommunicatorBridge, type FrameMetrics, type RawInputEvent } from "../native/faceclaw-communicator";
import * as frameTimings from "../native/frame-timings";
import { startForegroundNotification, stopForegroundNotification, updateForegroundNotification } from "../native/foreground-service";
@@ -26,6 +26,7 @@ import { voiceControlBridge } from "../native/voice-control";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
import { rawInputEventToInputEvent, shell, type ShellInputOutcome } from "../ui/shell/shell";
import { registerSystemTools } from "../assistant/system-tools";
import { registerNavigateTools } from "../assistant/navigate-tools";
import { WorkerAppHost } from "../ui/shell/worker-window";
import { createLauncherWindow, LAUNCHER_SURFACE_ID } from "../ui/shell/launcher-app";
import {
@@ -241,6 +242,8 @@ class DashboardController {
// The always-available assistant tools (calendar, media, notifications,
// glasses state) register once at startup, independent of any connection.
registerSystemTools();
// nav.* tools launch the Navigate app on demand, so they need launchApp.
registerNavigateTools((appId) => this.launchApp(appId));
shell.configure({
actions: {
...sharedActions,
@@ -272,6 +275,7 @@ class DashboardController {
{ appId: "notifications", label: "Notifications", icon: "bell" },
{ appId: "calendar", label: "Calendar", icon: "calendar" },
{ appId: "weather", label: "Weather", icon: "cloud-sun" },
{ appId: "navigate", label: "Navigate", icon: "map" },
{ appId: "debug-tests", label: "Debug tests", icon: "flask-conical" },
{ appId: "settings", label: "Settings", icon: "settings" },
],
@@ -1192,6 +1196,8 @@ class DashboardController {
worker = new Worker("../workers/timer-app.worker");
} else if (appId === "terminal") {
worker = new Worker("../workers/terminal-app.worker");
} else if (appId === "navigate") {
worker = new Worker("../workers/navigate-app.worker");
} else {
return null;
}
@@ -1300,6 +1306,20 @@ class DashboardController {
this.appendLog("launched timer:main");
return;
}
if (appId === "navigate") {
// Navigation needs precise location; prompt on the phone while the
// window opens (the worker can't show permission dialogs).
void ensureFineLocationPermission().catch(() => {});
const existing = shell.getWindows().find((window) => window.appId === "navigate");
if (existing) {
shell.focusWindow(existing.windowId);
this.requestShellRender();
return;
}
host.openWindow({ windowId: "navigate:main", title: "Navigate", iconLetter: "N", icon: "map", focus: true });
this.appendLog("launched navigate:main");
return;
}
}
/** Create/refresh a window surface on the compositor, if connected. */