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 { Menu {
emptyProfileButton emptyProfileButton
importProfileButton importProfileButton
Divider()
providerProfileMenu providerProfileMenu
Divider() Divider()
migrateProfilesButton migrateProfilesButton
@ -58,7 +59,7 @@ private extension AddProfileMenu {
let editable = EditableProfile(name: newName) let editable = EditableProfile(name: newName)
onNewProfile(editable, nil) onNewProfile(editable, nil)
} label: { } 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 { var body: some View {
tunnelToggleButton tunnelToggleButton
providerConnectToButton
if style == .installedProfile { if style == .installedProfile {
tunnelRestartButton tunnelRestartButton
} }
providerConnectToButton
Divider()
profileEditButton profileEditButton
if [.installedProfile, .containerContext].contains(style) { if style == .containerContext {
Divider()
profileDuplicateButton profileDuplicateButton
profileRemoveButton profileRemoveButton
} }
@ -95,15 +95,17 @@ private extension ProfileContextMenu {
} }
var providerConnectToButton: some View { var providerConnectToButton: some View {
profile? profile.map {
.selectedProvider ProviderConnectToButton(
.map { _ in profile: $0,
Button { onTap: {
flow?.onProviderEntityRequired(profile!) flow?.onProviderEntityRequired($0)
} label: { },
label: {
ThemeImageLabel(Strings.Views.App.ProfileContext.connectTo.withTrailingDots, .profileProvider) ThemeImageLabel(Strings.Views.App.ProfileContext.connectTo.withTrailingDots, .profileProvider)
} }
} )
}
} }
var tunnelRestartButton: some View { var tunnelRestartButton: some View {
@ -124,7 +126,7 @@ private extension ProfileContextMenu {
Button { Button {
flow?.onEditProfile(preview) flow?.onEditProfile(preview)
} label: { } 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 { var infoButton: some View {
Menu { Menu {
ProfileContextMenu( ProfileContextMenu(
style: .infoButton, style: preview.id == tunnel.currentProfile?.id ? .installedProfile : .infoButton,
profileManager: profileManager, profileManager: profileManager,
tunnel: tunnel, tunnel: tunnel,
preview: preview, preview: preview,

View File

@ -112,7 +112,7 @@ private extension AppMenu {
} }
var aboutButton: some View { var aboutButton: some View {
Button(Strings.Global.Nouns.about.withTrailingDots) { Button(Strings.Global.Nouns.about) {
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
NSApp.orderFrontStandardAboutPanel(self) 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 { public var withTrailingDots: String {
#if os(macOS)
"\(self)..." "\(self)..."
#else
self
#endif
} }
} }