Skip to content

Persist server location #412

Open
jigar-f wants to merge 6 commits intomainfrom
jigar/persist-server-location-
Open

Persist server location #412
jigar-f wants to merge 6 commits intomainfrom
jigar/persist-server-location-

Conversation

@jigar-f
Copy link
Copy Markdown
Contributor

@jigar-f jigar-f commented Apr 13, 2026

This pull request adds persistent storage for the selected VPN server, ensuring that the server choice survives Android VPN service restarts and OS-driven tunnel lifecycle events. It also introduces helper functions to manage this persisted state, updates the SelectServer logic to save selections, and refactors tunnel restart logic for clarity.

Persistent server selection:

  • Added a persistSelection function and supporting helpers (ClearLastSelectedServer, LastSelectedServer) to save and retrieve the selected server to a JSON file in the app's data directory, ensuring the selection can be restored after service restarts.

Server selection logic:

  • Updated SelectServer and AutoConnect to call persistSelection whenever the server selection changes, so the persisted state always matches the current selection. [1] [2]
  • Improved documentation for SelectServer to clarify the persistence mechanism and its purpose in the Android VPN lifecycle.

Tunnel restart logic:

  • Refactored restartTunnel to use the new Restart function, which now stops and starts the service, improving clarity and reliability.
  • Updated the comment for Restart to accurately reflect its behavior.

Other:

  • Minor cleanup in unrelated function (preTest), removing an unnecessary blank line.

Comment thread vpn/vpn.go Outdated
@jigar-f jigar-f requested a review from garmr-ulfr April 15, 2026 10:31
@jigar-f jigar-f marked this pull request as ready for review April 15, 2026 10:31
Copilot AI review requested due to automatic review settings April 15, 2026 10:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds persistence for the currently selected VPN server so selection can survive VPN lifecycle restarts (notably on Android), and refactors tunnel restart flow for clarity.

Changes:

  • Persist selected server (group/tag) to a JSON file under the app data directory; add helpers to clear/read the persisted selection.
  • Update AutoConnect / SelectServer to update the persisted selection whenever the selection changes.
  • Refactor restartTunnel() to delegate to Restart(), and adjust related comments/formatting.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 4 comments.

File Description
vpn/vpn.go Adds selection persistence helpers and calls them from selection flows; refactors tunnel restart implementation.
common/settings/settings.go Minor formatting/alignment cleanup of settings key constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vpn/vpn.go Outdated
Comment thread vpn/vpn.go
Comment thread vpn/vpn.go
Comment thread vpn/vpn.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants