From d7f14aa3b44f55c9cf20fdc13e8c253c49e4d6a7 Mon Sep 17 00:00:00 2001
From: Davide De Rosa <keeshux@gmail.com>
Date: Sat, 14 Oct 2023 19:27:11 +0200
Subject: [PATCH] Read updated profiles from function argument

Coming from a "will" publisher, the value in ProfileRepository is
not up-to-date. Use the function argument instead.

Fixes #367
---
 CHANGELOG.md                                                | 6 +++++-
 .../Sources/PassepartoutVPN/Managers/ProfileManager.swift   | 3 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec62d70c6..0d6e4f47a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
-## Unreleased
+## 2.2.1 (2023-10-14)
+
+### Fixed
+
+- Persisted profile is overwritten with its former value. [#367](https://github.com/passepartoutvpn/passepartout-apple/issues/367)
 
 ## 2.2.0 (2023-10-10)
 
diff --git a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/ProfileManager.swift b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/ProfileManager.swift
index c7a7f8cbc..bcb1aedff 100644
--- a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/ProfileManager.swift
+++ b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/ProfileManager.swift
@@ -371,8 +371,7 @@ extension ProfileManager {
             currentProfile.value = .placeholder
         }
 
-        let newProfile = profileRepository.profile(withId: currentProfile.value.id)
-        if let newProfile = newProfile, newProfile != currentProfile.value {
+        if let newProfile = newProfiles[currentProfile.value.id], newProfile != currentProfile.value {
             pp_log.info("Current profile remotely updated")
             currentProfile.value = newProfile
         }