diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 99674cb..0743455 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -97,7 +97,12 @@ export function registerIpc({ settings, secrets, bookmarks, disable3dTiles, isTr handle(IPC.profilesUpdate, (id: unknown, patch: unknown) => bookmarks.updateProfile(str(id, 100), patch)) handle(IPC.profilesRemove, (id: unknown) => bookmarks.removeProfile(str(id, 100))) + // Turned off in Settings: answer without a request so nothing counts toward the quota. + const placesOff = () => !settings.get().placesApi + const PLACES_OFF = { ok: false, error: { status: 'error', message: 'Places API is turned off in Settings.' } } as const + handle(IPC.placesAutocomplete, (req: unknown) => { + if (placesOff()) return PLACES_OFF const r = (req ?? {}) as Partial const bias = r.bias && Number.isFinite(r.bias.latitude) && Number.isFinite(r.bias.longitude) @@ -110,9 +115,10 @@ export function registerIpc({ settings, secrets, bookmarks, disable3dTiles, isTr }) }) handle(IPC.placesDetails, (placeId: unknown, token: unknown) => - placeDetails(secrets.get().googleApiKey, str(placeId, 300), str(token, 100)) + placesOff() ? PLACES_OFF : placeDetails(secrets.get().googleApiKey, str(placeId, 300), str(token, 100)) ) handle(IPC.placesNearby, (req: unknown) => { + if (placesOff()) return PLACES_OFF const r = (req ?? {}) as Partial const { latitude, longitude } = r.center ?? {} if ( @@ -130,6 +136,7 @@ export function registerIpc({ settings, secrets, bookmarks, disable3dTiles, isTr }) }) handle(IPC.placesCities, (req: unknown) => { + if (placesOff()) return PLACES_OFF const r = (req ?? {}) as Partial const { south, west, north, east } = r if ( diff --git a/src/renderer/src/components/CommandPalette.tsx b/src/renderer/src/components/CommandPalette.tsx index 10eb1db..86d3e2a 100644 --- a/src/renderer/src/components/CommandPalette.tsx +++ b/src/renderer/src/components/CommandPalette.tsx @@ -57,7 +57,8 @@ function PaletteDialog() { const set = useAppStore((s) => s.set) const bookmarks = useAppStore((s) => s.bookmarks) const profiles = useAppStore((s) => s.profiles) - const hasGoogleKey = useAppStore((s) => !!s.keys.googleApiKey) + // Place search needs a Google key and the Places API setting on. + const hasGoogleKey = useAppStore((s) => !!s.keys.googleApiKey && s.settings.placesApi) const target = useAppStore((s) => s.target) const [query, setQuery] = useState('') const [selected, setSelected] = useState(0) diff --git a/src/renderer/src/components/HorizonPanel.tsx b/src/renderer/src/components/HorizonPanel.tsx index adbe194..9aec685 100644 --- a/src/renderer/src/components/HorizonPanel.tsx +++ b/src/renderer/src/components/HorizonPanel.tsx @@ -555,7 +555,7 @@ function HorizonPanelBody() { onPick={(utc) => engine?.sun.setInstant(utc)} /> )} - {state.peakStatus === 'unavailable' && prefs.peakNames && Peak names need a Google Maps Platform key with Places API (New).} + {state.peakStatus === 'unavailable' && prefs.peakNames && Peak names need a Google Maps Platform key with Places API (New), turned on in Settings.} {hover && ( diff --git a/src/renderer/src/components/RightRail.tsx b/src/renderer/src/components/RightRail.tsx index 87cf0d3..716389e 100644 --- a/src/renderer/src/components/RightRail.tsx +++ b/src/renderer/src/components/RightRail.tsx @@ -167,6 +167,7 @@ export function RightRail() { const camera = useAppStore((s) => s.camera) const pinElsewhere = !!pin && (!camera || haversine(pin, camera) > 5) const placeLabels = useAppStore((s) => s.settings.placeLabels) + const placesApi = useAppStore((s) => s.settings.placesApi) const lightPollution = useAppStore((s) => s.settings.lightPollution.enabled) const viewfinder = useAppStore((s) => s.viewfinder) const patchSettings = useAppStore((s) => s.patchSettings) @@ -230,9 +231,9 @@ export function RightRail() { /> patchSettings((d) => void (d.placeLabels = !d.placeLabels))} /> diff --git a/src/renderer/src/components/SettingsDialog.tsx b/src/renderer/src/components/SettingsDialog.tsx index f0ba408..0bde32c 100644 --- a/src/renderer/src/components/SettingsDialog.tsx +++ b/src/renderer/src/components/SettingsDialog.tsx @@ -33,6 +33,8 @@ function KeysSection() { const secrets = useAppStore((s) => s.secrets) const showToast = useAppStore((s) => s.showToast) const info = useAppInfo() + const placesApi = useAppStore((s) => s.settings.placesApi) + const patch = useAppStore((s) => s.patchSettings) const { keys, setKeys, result, validating, validate, setResult } = useKeyFields(initial) return (
@@ -44,6 +46,9 @@ function KeysSection() {
)} + + patch((d) => void (d.placesApi = e.target.checked))} /> +