Commit Graph

27 Commits

Author SHA1 Message Date
Davide De Rosa b68fb21652 Fix duplicate on iOS 14
Wrong braces in 4cb18965c9.
2022-05-04 09:12:06 +02:00
Davide De Rosa 4cb18965c9 Set duplicate as current inside ProfileManager
When setting duplicate as current, batch save original profile and
duplicate in a single call via profilesToSave. This is to avoid a
double call to willUpdateProfiles() when saving Core Data context.

In order to set current profile to one that has not been persisted
yet (the duplicate), we need to resort to a pendingProfiles map
where to look the duplicate up when setting currentProfileId.

Either way, iOS 14 cannot handle updating a "hot" change in a
presented NavigationLink. Changing currentProfileId binding while
in ProfileView messes up navigation completely (multiple push and
pop events). Avoid.
2022-05-03 18:35:19 +02:00
Davide De Rosa 943bce5515 Bind navigation to ProfileManager directly
- Do the profile loading inside the model

- Allow setting current profile to a transient profile

- Check .placeholder before saving current profile

XXX: avoid loading active profile on iPad portrait.
2022-05-03 18:35:17 +02:00
Davide De Rosa 93abaf538b Simplify redundant parts of ProfileManager
- Drop overthought activeHeader

- Drop willUpdateCurrentProfile, use observable

- Drop willUpdateActiveId, observe value publisher
2022-05-03 14:36:55 +02:00
Davide De Rosa 20be153b1a Only tweak .isLoading if profile is not ready
Result is sync and immediate otherwise.
2022-05-02 11:17:51 +02:00
Davide De Rosa acbc1980f9 Ignore non-existing active profile 2022-05-01 20:40:20 +02:00
Davide De Rosa 171c1e1dd4 Omit wrapping Section on Mac 2022-05-01 19:30:56 +02:00
Davide De Rosa 8003b4a92d Observe currentProfile in ProfileView
ProfileView is not interested in changes in other profiles
notified by ProfileManager. Set isLoading inside
ObservableObject for observable to be self-contained.

Loses observation of profile deletion, but dismiss on removal is
actually handled by OrganizerView, not ProfileView.

Also drop unused presentationMode.
2022-05-01 19:14:34 +02:00
Davide De Rosa 17198e53eb Fix cannot duplicate same profile more than once 2022-04-29 00:40:56 +02:00
Davide De Rosa 1afd227f02 Do not update current profile on activation 2022-04-28 22:36:31 +02:00
Davide De Rosa 2c2e794b00 Revert async loadCurrentProfile()
Make action sync, but internally async (makeProfileReady). If not
doing so, UI on launch will not be able to show active profile
immediately. WelcomeView would appear for a moment.

Observe isReloadingCurrentProfile.

See 2b1efb8fec
2022-04-28 19:00:36 +02:00
Davide De Rosa 1ef2b8c7a7 Set activeProfileId immediately
Otherwise on app launch, active profile is rendered in 2 steps.
2022-04-28 17:56:28 +02:00
Davide De Rosa 56fa161e92 Save current profile one way
Skip updating currentProfile.value when intentionally saving
current profile.
2022-04-28 17:56:28 +02:00
Davide De Rosa 2b1efb8fec Make load*Profile() async
- Handle Task in consumers

- Drop makeReady, always make loaded profile ready

- Rename misleading loadProfile() to profileEx()
2022-04-27 17:13:03 +02:00
Davide De Rosa 02b2e3194e Add duplicate to profile menu
Contextually switch current profile to duplicate.
2022-04-27 16:59:33 +02:00
Davide De Rosa 03fdab4833 Duplicate profile from context menu 2022-04-26 22:39:47 +02:00
Davide De Rosa 10537c5a29 Fix active profile not always cleared on deletion
Was only cleared if deleted profile was current profile.
2022-04-23 10:25:31 +02:00
Davide De Rosa 8f4e4bc7c5 Skip redundant updates of current profile 2022-04-23 10:25:31 +02:00
Davide De Rosa 2432f0d97a Rewrite ProfileView as a view of currentProfile
Do not load profile in View, instead:

- Load active profile on app launch

- Load selected profile on organizer selection
2022-04-23 10:25:31 +02:00
Davide De Rosa 8838e9d130 Strip a few unnecessary publishers
- Drop unused AppManager from OrganizerView

- Do not notify ProfileManager subscribers on activeProfileId

Saved active profile is already notified by:

- Core Data
- AppManager
2022-04-23 10:25:31 +02:00
Davide De Rosa 18e9f7cbb5 Clear profile selection if current profile removed
Do it before ForEach rearranges NavigationLink elements, because
it may trigger undesired navigation to a deleted profile.

Restore related assertion.
2022-04-19 21:19:43 +02:00
Davide De Rosa 5d85699ce4 Delete profile from Organizer
Swipe to delete. Address a couple things on iPad though:

1. Also check provider availability before showing view

fatalError hit on iPad when navigating from a ready provider
profile to a non-ready one. Similar to when navigating between
different VPN protocols.

2. Suppress assertion on deleted profile

Deleting current profile via swipe seems to re-render a new
NavigationLink with the deleted profile, which results in
loading a deleted profile and hitting the assertion. Not sure if
this is a programming error or a glitch in ForEach.
2022-04-19 08:38:10 +02:00
Davide De Rosa f5c87d43c2 Better observe updates explicitly after init 2022-04-18 19:51:07 +02:00
Davide De Rosa 5cafd9794d Review a bit about duplicates handling
- Read profile(withId:) without fetcher

- Refine redundant log about duplicated profiles
2022-04-16 11:27:31 +02:00
Davide De Rosa 2273ebd8b5 Do not log duplicates renamed if there is none 2022-04-13 11:16:38 +02:00
Davide De Rosa e663dbff11 Fix inverse condition in current profile deletion 2022-04-12 18:09:30 +02:00
Davide De Rosa 4aba5f46aa Rewrite app in SwiftUI 2022-04-12 15:12:45 +02:00