Skip to content

Commit

Permalink
Different styles for profile menu based on context (#947)
Browse files Browse the repository at this point in the history
Hide "Duplicate" and "Delete" from the info button menu because they are
disruptive actions, misclick is likely.
  • Loading branch information
keeshux authored Nov 26, 2024
1 parent e0f16cb commit d8753f2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 26 deletions.
5 changes: 2 additions & 3 deletions Passepartout/Library/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"kind" : "remoteSourceControl",
"location" : "[email protected]:passepartoutvpn/passepartoutkit-source",
"state" : {
"revision" : "d11036e59b65601b617120471dc9a469567388f5"
"revision" : "dd4d614e9334b0a788cf8216793471074d1ec5dd"
}
},
{
Expand All @@ -58,8 +58,7 @@
"kind" : "remoteSourceControl",
"location" : "[email protected]:passepartoutvpn/passepartoutkit-source-wireguard-go",
"state" : {
"revision" : "256a4a8265b7d214bb35f4e29e18c27e2dc49137",
"version" : "0.9.2"
"revision" : "68fceaa664913988b2d9053405738682a30b87b8"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ private extension InstalledProfileView {

func menuContent() -> some View {
ProfileContextMenu(
style: .installedProfile,
profileManager: profileManager,
tunnel: tunnel,
preview: .init(profile ?? .mock),
interactiveManager: interactiveManager,
errorHandler: errorHandler,
isInstalledProfile: true,
flow: flow
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ import PassepartoutKit
import SwiftUI

struct ProfileContextMenu: View, Routable {
enum Style {
case installedProfile

case containerContext

case infoButton
}

let style: Style

let profileManager: ProfileManager

let tunnel: ExtendedTunnel
Expand All @@ -39,21 +49,20 @@ struct ProfileContextMenu: View, Routable {

let errorHandler: ErrorHandler

let isInstalledProfile: Bool

var flow: ProfileFlow?

var body: some View {
tunnelToggleButton
providerConnectToButton
if isInstalledProfile {
if style == .installedProfile {
tunnelRestartButton
}
Divider()
profileEditButton
profileDuplicateButton
Divider()
profileRemoveButton
if [.installedProfile, .containerContext].contains(style) {
Divider()
profileDuplicateButton
profileRemoveButton
}
}
}

Expand Down Expand Up @@ -89,8 +98,10 @@ private extension ProfileContextMenu {
profile?
.selectedProvider
.map { _ in
Button(Strings.Views.App.ProfileContext.connectTo) {
Button {
flow?.onProviderEntityRequired(profile!)
} label: {
ThemeImageLabel(Strings.Views.App.ProfileContext.connectTo.withTrailingDots, .profileProvider)
}
}
}
Expand Down Expand Up @@ -141,12 +152,12 @@ private extension ProfileContextMenu {
List {
Menu("Menu") {
ProfileContextMenu(
style: .installedProfile,
profileManager: .mock,
tunnel: .mock,
preview: .init(.mock),
interactiveManager: InteractiveManager(),
errorHandler: .default(),
isInstalledProfile: true
errorHandler: .default()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ private extension ProfileGridView {
.contextMenu {
currentProfile.map {
ProfileContextMenu(
style: .installedProfile,
profileManager: profileManager,
tunnel: tunnel,
preview: .init($0),
interactiveManager: interactiveManager,
errorHandler: errorHandler,
isInstalledProfile: true,
flow: flow
)
}
Expand All @@ -133,12 +133,12 @@ private extension ProfileGridView {
.themeGridCell(isSelected: preview.id == nextProfileId ?? currentProfile?.id)
.contextMenu {
ProfileContextMenu(
style: .containerContext,
profileManager: profileManager,
tunnel: tunnel,
preview: preview,
interactiveManager: interactiveManager,
errorHandler: errorHandler,
isInstalledProfile: false,
flow: flow
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ private extension ProfileListView {
.contextMenu {
currentProfile.map {
ProfileContextMenu(
style: .installedProfile,
profileManager: profileManager,
tunnel: tunnel,
preview: .init($0),
interactiveManager: interactiveManager,
errorHandler: errorHandler,
isInstalledProfile: true,
flow: flow
)
}
Expand All @@ -122,12 +122,12 @@ private extension ProfileListView {
)
.contextMenu {
ProfileContextMenu(
style: .containerContext,
profileManager: profileManager,
tunnel: tunnel,
preview: preview,
interactiveManager: interactiveManager,
errorHandler: errorHandler,
isInstalledProfile: false,
flow: flow
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ private extension ProfileRowView {
var infoButton: some View {
Menu {
ProfileContextMenu(
style: .infoButton,
profileManager: profileManager,
tunnel: tunnel,
preview: preview,
interactiveManager: interactiveManager,
errorHandler: errorHandler,
isInstalledProfile: false,
flow: flow
)
} label: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private extension OpenVPNView {
@ViewBuilder
var importView: some View {
if providerId.wrappedValue == nil {
Button(Strings.Modules.General.Rows.importFromFile) {
Button(Strings.Modules.General.Rows.importFromFile.withTrailingDots) {
isImporting = true
}
.alert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ public enum Strings {
public static func appletv(_ p1: Any) -> String {
return Strings.tr("Localizable", "modules.general.rows.appletv", String(describing: p1), fallback: "%@")
}
/// Import from file...
public static let importFromFile = Strings.tr("Localizable", "modules.general.rows.import_from_file", fallback: "Import from file...")
/// Import from file
public static let importFromFile = Strings.tr("Localizable", "modules.general.rows.import_from_file", fallback: "Import from file")
/// Enabled
public static let shared = Strings.tr("Localizable", "modules.general.rows.shared", fallback: "Enabled")
public enum Appletv {
Expand Down Expand Up @@ -599,8 +599,8 @@ public enum Strings {
}
}
public enum ProfileContext {
/// Connect to...
public static let connectTo = Strings.tr("Localizable", "views.app.profile_context.connect_to", fallback: "Connect to...")
/// Connect to
public static let connectTo = Strings.tr("Localizable", "views.app.profile_context.connect_to", fallback: "Connect to")
}
public enum Rows {
/// No active modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"views.app.errors.duplicate" = "Unable to duplicate profile '%@'.";
"views.app.errors.import" = "Unable to import profiles.";

"views.app.profile_context.connect_to" = "Connect to...";
"views.app.profile_context.connect_to" = "Connect to";

"views.app_menu.items.quit" = "Quit %@";

Expand Down Expand Up @@ -143,7 +143,7 @@
"modules.general.rows.shared.purchase" = "Share on iCloud";
"modules.general.rows.appletv" = "%@";
"modules.general.rows.appletv.purchase" = "Drop TV restriction";
"modules.general.rows.import_from_file" = "Import from file...";
"modules.general.rows.import_from_file" = "Import from file";

"modules.dns.servers.add" = "Add address";
"modules.dns.search_domains.add" = "Add domain";
Expand Down

0 comments on commit d8753f2

Please sign in to comment.