From 63b0199a3952aa206723ad3f3952928e41c0df88 Mon Sep 17 00:00:00 2001 From: Davide Date: Thu, 3 Oct 2024 11:25:39 +0200 Subject: [PATCH] Merge Settings into About on iOS (#670) Closes #669 --- .../Sources/AppUI/Views/About/AboutView.swift | 1 - .../AppUI/Views/About/iOS/AboutView+iOS.swift | 2 + .../Views/About/macOS/AboutView+macOS.swift | 1 + .../Sources/AppUI/Views/App/AppToolbar.swift | 11 ++-- .../Views/Settings/SettingsSection.swift | 61 +++++++++++++++++++ .../AppUI/Views/Settings/SettingsView.swift | 26 +------- 6 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 Passepartout/Library/Sources/AppUI/Views/Settings/SettingsSection.swift diff --git a/Passepartout/Library/Sources/AppUI/Views/About/AboutView.swift b/Passepartout/Library/Sources/AppUI/Views/About/AboutView.swift index 87093491..d53504bb 100644 --- a/Passepartout/Library/Sources/AppUI/Views/About/AboutView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/About/AboutView.swift @@ -35,7 +35,6 @@ struct AboutView: View { var body: some View { listView - .navigationTitle(Strings.Views.About.title) } } diff --git a/Passepartout/Library/Sources/AppUI/Views/About/iOS/AboutView+iOS.swift b/Passepartout/Library/Sources/AppUI/Views/About/iOS/AboutView+iOS.swift index bc7b08f6..0cfdc2cf 100644 --- a/Passepartout/Library/Sources/AppUI/Views/About/iOS/AboutView+iOS.swift +++ b/Passepartout/Library/Sources/AppUI/Views/About/iOS/AboutView+iOS.swift @@ -31,6 +31,7 @@ import SwiftUI extension AboutView { var listView: some View { List { + SettingsSection() Section { // TODO: #585, donations // donateLink @@ -45,6 +46,7 @@ extension AboutView { .withTrailingText(BundleConfiguration.mainVersionString) } } + .navigationTitle(Strings.Global.settings) } } diff --git a/Passepartout/Library/Sources/AppUI/Views/About/macOS/AboutView+macOS.swift b/Passepartout/Library/Sources/AppUI/Views/About/macOS/AboutView+macOS.swift index adcc83fd..c4d78ce9 100644 --- a/Passepartout/Library/Sources/AppUI/Views/About/macOS/AboutView+macOS.swift +++ b/Passepartout/Library/Sources/AppUI/Views/About/macOS/AboutView+macOS.swift @@ -43,6 +43,7 @@ extension AboutView { Text(BundleConfiguration.mainVersionString) .padding(.bottom) } + .navigationTitle(Strings.Views.About.title) } } diff --git a/Passepartout/Library/Sources/AppUI/Views/App/AppToolbar.swift b/Passepartout/Library/Sources/AppUI/Views/App/AppToolbar.swift index 687b12b6..5c2fde1f 100644 --- a/Passepartout/Library/Sources/AppUI/Views/App/AppToolbar.swift +++ b/Passepartout/Library/Sources/AppUI/Views/App/AppToolbar.swift @@ -58,7 +58,7 @@ struct AppToolbar: ToolbarContent { } } else { ToolbarItem(placement: .navigation) { - moreMenu + moreButton } ToolbarItemGroup(placement: .primaryAction) { addProfileMenu @@ -77,12 +77,9 @@ private extension AppToolbar { ) } - var moreMenu: some View { - Menu { - settingsButton - aboutButton - } label: { - ThemeImage(.moreDetails) + var moreButton: some View { + Button(action: onAbout) { + ThemeImageLabel(Strings.Global.about, .moreDetails) } } diff --git a/Passepartout/Library/Sources/AppUI/Views/Settings/SettingsSection.swift b/Passepartout/Library/Sources/AppUI/Views/Settings/SettingsSection.swift new file mode 100644 index 00000000..0fbc0509 --- /dev/null +++ b/Passepartout/Library/Sources/AppUI/Views/Settings/SettingsSection.swift @@ -0,0 +1,61 @@ +// +// SettingsSection.swift +// 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 . +// + +import CommonLibrary +import SwiftUI + +struct SettingsSection: View { + + @AppStorage(AppPreference.confirmsQuit.key) + private var confirmsQuit = true + + @AppStorage(AppPreference.locksInBackground.key) + private var locksInBackground = false + + var header: String? + + var body: some View { + Section { +#if os(macOS) + confirmsQuitToggle +#endif +#if os(iOS) + lockInBackgroundToggle +#endif + } header: { + header.map(Text.init) + } + } +} + +private extension SettingsSection { + var confirmsQuitToggle: some View { + Toggle(Strings.Views.Settings.Rows.confirmQuit, isOn: $confirmsQuit) + } + + var lockInBackgroundToggle: some View { + Toggle(Strings.Views.Settings.Rows.lockInBackground, isOn: $locksInBackground) + } +} diff --git a/Passepartout/Library/Sources/AppUI/Views/Settings/SettingsView.swift b/Passepartout/Library/Sources/AppUI/Views/Settings/SettingsView.swift index ca9a6191..57df4157 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Settings/SettingsView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Settings/SettingsView.swift @@ -23,17 +23,10 @@ // along with Passepartout. If not, see . // -import CommonLibrary import SwiftUI public struct SettingsView: View { - @AppStorage(AppPreference.confirmsQuit.key) - private var confirmsQuit = true - - @AppStorage(AppPreference.locksInBackground.key) - private var locksInBackground = false - @State private var path = NavigationPath() @@ -42,14 +35,7 @@ public struct SettingsView: View { public var body: some View { Form { - Section { -#if os(macOS) - confirmsQuitToggle -#endif -#if os(iOS) - lockInBackgroundToggle -#endif - } + SettingsSection() } .themeForm() .navigationTitle(Strings.Global.settings) @@ -59,13 +45,3 @@ public struct SettingsView: View { #endif } } - -private extension SettingsView { - var confirmsQuitToggle: some View { - Toggle(Strings.Views.Settings.Rows.confirmQuit, isOn: $confirmsQuit) - } - - var lockInBackgroundToggle: some View { - Toggle(Strings.Views.Settings.Rows.lockInBackground, isOn: $locksInBackground) - } -}