2024-10-03 21:25:51 +00:00
|
|
|
//
|
2024-11-23 18:26:33 +00:00
|
|
|
// PreferencesGroup.swift
|
2024-10-03 21:25:51 +00:00
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 10/3/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CommonLibrary
|
2024-11-02 09:11:59 +00:00
|
|
|
import CommonUtils
|
2024-10-03 21:25:51 +00:00
|
|
|
import PassepartoutKit
|
|
|
|
import SwiftUI
|
|
|
|
|
2024-11-23 18:26:33 +00:00
|
|
|
public struct PreferencesGroup: View {
|
2024-10-03 21:25:51 +00:00
|
|
|
|
2024-11-13 21:35:50 +00:00
|
|
|
#if os(iOS)
|
2024-10-03 21:25:51 +00:00
|
|
|
@AppStorage(AppPreference.locksInBackground.key)
|
|
|
|
private var locksInBackground = false
|
2024-11-23 18:26:33 +00:00
|
|
|
#elseif os(macOS)
|
2024-11-13 21:35:50 +00:00
|
|
|
@EnvironmentObject
|
|
|
|
private var settings: MacSettingsModel
|
|
|
|
#endif
|
2024-11-13 21:04:34 +00:00
|
|
|
|
2024-11-23 18:26:33 +00:00
|
|
|
private let profileManager: ProfileManager
|
|
|
|
|
2024-10-03 21:25:51 +00:00
|
|
|
@State
|
|
|
|
private var isConfirmingEraseiCloud = false
|
|
|
|
|
|
|
|
@State
|
|
|
|
private var isErasingiCloud = false
|
|
|
|
|
2024-11-23 18:26:33 +00:00
|
|
|
public init(profileManager: ProfileManager) {
|
|
|
|
self.profileManager = profileManager
|
|
|
|
}
|
|
|
|
|
|
|
|
public var body: some View {
|
2024-10-03 21:25:51 +00:00
|
|
|
#if os(iOS)
|
2024-11-07 14:50:19 +00:00
|
|
|
lockInBackgroundToggle
|
2024-11-23 18:26:33 +00:00
|
|
|
#elseif os(macOS)
|
2024-11-13 21:04:34 +00:00
|
|
|
launchesOnLoginToggle
|
2024-11-07 14:50:19 +00:00
|
|
|
keepsInMenuToggle
|
|
|
|
#endif
|
|
|
|
eraseCloudKitButton
|
2024-10-03 21:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-23 18:26:33 +00:00
|
|
|
private extension PreferencesGroup {
|
2024-11-13 21:35:50 +00:00
|
|
|
#if os(iOS)
|
|
|
|
var lockInBackgroundToggle: some View {
|
2024-11-23 19:31:22 +00:00
|
|
|
Toggle(Strings.Views.Preferences.locksInBackground, isOn: $locksInBackground)
|
|
|
|
.themeSectionWithSingleRow(footer: Strings.Views.Preferences.LocksInBackground.footer)
|
2024-11-13 21:35:50 +00:00
|
|
|
}
|
2024-11-23 18:26:33 +00:00
|
|
|
#elseif os(macOS)
|
2024-11-13 21:04:34 +00:00
|
|
|
var launchesOnLoginToggle: some View {
|
2024-11-23 19:31:22 +00:00
|
|
|
Toggle(Strings.Views.Preferences.launchesOnLogin, isOn: $settings.launchesOnLogin)
|
|
|
|
.themeSectionWithSingleRow(footer: Strings.Views.Preferences.LaunchesOnLogin.footer)
|
2024-11-13 21:04:34 +00:00
|
|
|
}
|
|
|
|
|
2024-10-30 09:37:45 +00:00
|
|
|
var keepsInMenuToggle: some View {
|
2024-11-23 19:31:22 +00:00
|
|
|
Toggle(Strings.Views.Preferences.keepsInMenu, isOn: $settings.keepsInMenu)
|
|
|
|
.themeSectionWithSingleRow(footer: Strings.Views.Preferences.KeepsInMenu.footer)
|
2024-10-03 21:25:51 +00:00
|
|
|
}
|
2024-11-13 21:35:50 +00:00
|
|
|
#endif
|
2024-10-03 21:25:51 +00:00
|
|
|
var eraseCloudKitButton: some View {
|
2024-11-23 19:31:22 +00:00
|
|
|
Button(Strings.Views.Preferences.eraseIcloud, role: .destructive) {
|
2024-10-03 21:25:51 +00:00
|
|
|
isConfirmingEraseiCloud = true
|
|
|
|
}
|
|
|
|
.themeConfirmation(
|
|
|
|
isPresented: $isConfirmingEraseiCloud,
|
2024-11-23 19:31:22 +00:00
|
|
|
title: Strings.Views.Preferences.eraseIcloud,
|
2024-10-30 13:53:35 +00:00
|
|
|
isDestructive: true
|
2024-10-03 21:25:51 +00:00
|
|
|
) {
|
|
|
|
isErasingiCloud = true
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
pp_log(.app, .info, "Erase CloudKit profiles...")
|
2024-10-04 18:58:11 +00:00
|
|
|
try await profileManager.eraseRemotelySharedProfiles()
|
2024-10-03 21:25:51 +00:00
|
|
|
} catch {
|
|
|
|
pp_log(.app, .error, "Unable to erase CloudKit store: \(error)")
|
|
|
|
}
|
|
|
|
isErasingiCloud = false
|
|
|
|
}
|
|
|
|
}
|
2024-11-07 14:50:19 +00:00
|
|
|
.themeSectionWithSingleRow(
|
|
|
|
header: Strings.Unlocalized.iCloud,
|
2024-11-23 19:31:22 +00:00
|
|
|
footer: Strings.Views.Preferences.EraseIcloud.footer,
|
2024-11-07 14:50:19 +00:00
|
|
|
above: true
|
|
|
|
)
|
2024-10-03 21:25:51 +00:00
|
|
|
.disabled(isErasingiCloud)
|
|
|
|
}
|
|
|
|
}
|