Skip to content

Colota - Android GPS Location tracker

fix(setup): restart tracking after applying a setup link (#935)

Max Dietrich5d033d8630d3
diff --git a/apps/docs/docs/guides/deep-link-setup.md b/apps/docs/docs/guides/deep-link-setup.md
index febf6ce3..d2fbf031 100644
--- a/apps/docs/docs/guides/deep-link-setup.md
+++ b/apps/docs/docs/guides/deep-link-setup.md
@@ -34,7 +34,7 @@ Geofences and tracking profiles can also be shared on their own from the [Geofen
2. Colota opens and shows a confirmation screen listing all settings that will be applied. The server address is shown in full with its host on a separate line. A link that replaces a configured server names the server it replaces.
3. Sensitive values (passwords, tokens) are masked in the preview
4. User taps **Apply Configuration** to save or **Cancel** to discard
-5. Settings are persisted and the app navigates to the Dashboard
+5. Settings are persisted, a running tracking session restarts with them, and the app navigates to the Dashboard
## URL Format
diff --git a/apps/mobile/src/screens/SetupImportScreen.tsx b/apps/mobile/src/screens/SetupImportScreen.tsx
index 6dd2510f..46047789 100644
--- a/apps/mobile/src/screens/SetupImportScreen.tsx
+++ b/apps/mobile/src/screens/SetupImportScreen.tsx
@@ -41,7 +41,7 @@ import { t as translate } from "../i18n/t"
export function SetupImportScreen({ route, navigation }: any) {
const { colors } = useTheme()
const { t } = useTranslation()
- const { settings: currentSettings, setSettings } = useTracking()
+ const { settings: currentSettings, setSettings, restartTracking } = useTracking()
const [applying, setApplying] = useState(false)
const [replaceByName, setReplaceByName] = useState(false)
@@ -135,6 +135,8 @@ export function SetupImportScreen({ route, navigation }: any) {
}
}
+ await restartTracking(merged)
+
showAlert(translate("setup.applied.title"), translate("setup.applied.message"), "success")
navigation.navigate("Dashboard")
} catch (e) {
diff --git a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
index a15d4a3f..ccd8cd41 100644
--- a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
@@ -5,6 +5,7 @@ import { DEFAULT_AUTH_CONFIG, TRACKING_PRESETS } from "../../types/global"
// --- Mocks ---
const mockSetSettings = jest.fn().mockResolvedValue(undefined)
+const mockRestartTracking = jest.fn().mockResolvedValue(true)
const mockSaveSetting = jest.fn().mockResolvedValue(undefined)
const mockGetAuthConfig = jest.fn().mockResolvedValue({ ...DEFAULT_AUTH_CONFIG })
const mockSaveAuthConfig = jest.fn().mockResolvedValue(true)
@@ -42,7 +43,8 @@ jest.mock("../../services/modalService", () => ({
jest.mock("../../contexts/TrackingProvider", () => ({
useTracking: () => ({
settings: { ...require("../../types/global").DEFAULT_SETTINGS, endpoint: mockCurrentEndpoint },
- setSettings: mockSetSettings
+ setSettings: mockSetSettings,
+ restartTracking: mockRestartTracking
})
}))
@@ -360,6 +362,19 @@ describe("SetupImportScreen", () => {
})
})
+ it("restarts tracking after the auth write, because a running service reads its credentials only at start", async () => {
+ const config = { endpoint: "https://test.com", auth: { type: "bearer", bearerToken: "mytoken" } }
+ const { getByText } = renderScreen(encode(config))
+
+ fireEvent.press(getByText("Apply configuration"))
+
+ await waitFor(() => expect(mockRestartTracking).toHaveBeenCalledTimes(1))
+ expect(mockRestartTracking).toHaveBeenCalledWith(expect.objectContaining({ endpoint: "https://test.com" }))
+ expect(mockRestartTracking.mock.invocationCallOrder[0]).toBeGreaterThan(
+ mockSaveAuthConfig.mock.invocationCallOrder[0]
+ )
+ })
+
it("shows error alert on failure", async () => {
mockSetSettings.mockRejectedValueOnce(new Error("fail"))
const { getByText } = renderScreen(encode({ endpoint: "https://test.com" }))
@@ -369,6 +384,7 @@ describe("SetupImportScreen", () => {
await waitFor(() => {
expect(mockShowAlert).toHaveBeenCalledWith("Error", "Failed to apply configuration. Please try again.", "error")
})
+ expect(mockRestartTracking).not.toHaveBeenCalled()
})
})
diff --git a/fastlane/metadata/android/en-US/changelogs/52.txt b/fastlane/metadata/android/en-US/changelogs/52.txt
index 77ee32ef..9ff4f10a 100644
--- a/fastlane/metadata/android/en-US/changelogs/52.txt
+++ b/fastlane/metadata/android/en-US/changelogs/52.txt
@@ -2,3 +2,4 @@
- Profiles no longer skip a pause zone's entry delay
- The Dashboard no longer cuts off the sync interval and says Offline mode when that is on
- Sync stops early on a rate limit or an unreachable server instead of trying every queued point
+- A setup link applied while tracking now takes effect at once instead of after the next start