fix(location): persist pin across restarts + prevent Stop crash before simulation#349
Closed
StephenDev0 wants to merge 1 commit intomainfrom
Closed
fix(location): persist pin across restarts + prevent Stop crash before simulation#349StephenDev0 wants to merge 1 commit intomainfrom
StephenDev0 wants to merge 1 commit intomainfrom
Conversation
…late Fixes #346 - Add saveCoordinate()/loadCoordinate() with UserDefaults so the dropped pin survives app restarts. - Introduce isSimulating flag; Stop button only shown after simulate_location() succeeds, preventing crash from calling clear_simulated_location() on uninitialised C global state. - Disable Simulate Location button while simulation is already active.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #346
Summary
Two bugs are addressed in
LocationSimulationView(MapSelectionView.swift):Bug 1 – Pin disappears after restarting the app
coordinatewas a pure@Statevalue that was never written to disk. On every launch it started asnil.Fix: Added
saveCoordinate()/loadCoordinate()helpers that persist the coordinate toUserDefaults(hasPinnedLocation,pinnedLocationLat,pinnedLocationLon).saveCoordinate()is called via adidSetobserver on the state property;loadCoordinate()is called in.onAppearalongsideloadBookmarks(). When the pin is cleared successfully the stored flag is set tofalseso the map starts clean next time.Bug 2 – App crashes when tapping "Stop" immediately after dropping a pin
The "Stop" button was shown as soon as
coordinate != nil, including before "Simulate Location" had ever been tapped. Pressing it calledclear_simulated_location()on C global state that had never been initialised, causing a crash.Fix: Added an
isSimulating: Boolstate flag.isSimulatingis set totrueonly aftersimulate_location()returns0(success).if isSimulating) — it cannot be reached before a successful simulation.isSimulating == trueto prevent duplicate active sessions.isSimulatingis reset tofalseafter a successfulclear_simulated_location()call.Testing