Fix profile menus

- Omit duplicate/delete from current profile
- Replace .infoButton with .installedProfile if current
- Drop dots from direct actions
- Disable trailing dots on iOS/tvOS
- Disable "Connect to" if ineligible (decouple to own view)
This commit is contained in:
Davide 2024-11-27 00:06:48 +01:00
parent 91f4e510c4
commit a92c2c2c64
No known key found for this signature in database
GPG Key ID: A48836171C759F5E
6 changed files with 85 additions and 14 deletions

View File

@ -43,6 +43,7 @@ struct AddProfileMenu: View {
Menu {
emptyProfileButton
importProfileButton
Divider()
providerProfileMenu
Divider()
migrateProfilesButton
@ -58,7 +59,7 @@ private extension AddProfileMenu {
let editable = EditableProfile(name: newName)
onNewProfile(editable, nil)
} label: {
ThemeImageLabel(Strings.Views.App.Toolbar.NewProfile.empty.withTrailingDots, .profileEdit)
ThemeImageLabel(Strings.Views.App.Toolbar.NewProfile.empty, .profileEdit)
}
}

View File

@ -53,13 +53,13 @@ struct ProfileContextMenu: View, Routable {
var body: some View {
tunnelToggleButton
providerConnectToButton
if style == .installedProfile {
tunnelRestartButton
}
providerConnectToButton
Divider()
profileEditButton
if [.installedProfile, .containerContext].contains(style) {
Divider()
if style == .containerContext {
profileDuplicateButton
profileRemoveButton
}
@ -95,15 +95,17 @@ private extension ProfileContextMenu {
}
var providerConnectToButton: some View {
profile?
.selectedProvider
.map { _ in
Button {
flow?.onProviderEntityRequired(profile!)
} label: {
profile.map {
ProviderConnectToButton(
profile: $0,
onTap: {
flow?.onProviderEntityRequired($0)
},
label: {
ThemeImageLabel(Strings.Views.App.ProfileContext.connectTo.withTrailingDots, .profileProvider)
}
}
)
}
}
var tunnelRestartButton: some View {
@ -124,7 +126,7 @@ private extension ProfileContextMenu {
Button {
flow?.onEditProfile(preview)
} label: {
ThemeImageLabel(Strings.Global.Actions.edit.withTrailingDots, .profileEdit)
ThemeImageLabel(Strings.Global.Actions.edit, .profileEdit)
}
}

View File

@ -178,7 +178,7 @@ private extension ProfileRowView {
var infoButton: some View {
Menu {
ProfileContextMenu(
style: .infoButton,
style: preview.id == tunnel.currentProfile?.id ? .installedProfile : .infoButton,
profileManager: profileManager,
tunnel: tunnel,
preview: preview,

View File

@ -112,7 +112,7 @@ private extension AppMenu {
}
var aboutButton: some View {
Button(Strings.Global.Nouns.about.withTrailingDots) {
Button(Strings.Global.Nouns.about) {
NSApp.activate(ignoringOtherApps: true)
NSApp.orderFrontStandardAboutPanel(self)
}

View File

@ -0,0 +1,64 @@
//
// ProviderConnectToButton.swift
// Passepartout
//
// Created by Davide De Rosa on 11/27/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
import PassepartoutKit
import SwiftUI
struct ProviderConnectToButton<Label>: View where Label: View {
@EnvironmentObject
private var iapManager: IAPManager
let profile: Profile
let onTap: (Profile) -> Void
let label: () -> Label
var body: some View {
profile
.selectedProvider
.map { _ in
Button {
onTap(profile)
} label: {
label()
}
.disabled(!isEligible)
}
}
}
private extension ProviderConnectToButton {
var isEligible: Bool {
do {
try iapManager.verify(profile)
return true
} catch {
return false
}
}
}

View File

@ -31,7 +31,11 @@ extension String {
}
public var withTrailingDots: String {
#if os(macOS)
"\(self)..."
#else
self
#endif
}
}