Skip to content

Commit

Permalink
Add provider profile directly from menu
Browse files Browse the repository at this point in the history
  • Loading branch information
keeshux committed Nov 26, 2024
1 parent 0c18f1d commit 7fdd821
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct AddProfileMenu: View {
Menu {
emptyProfileButton
importProfileButton
providerProfileMenu
Divider()
migrateProfilesButton
} label: {
Expand All @@ -69,6 +70,25 @@ private extension AddProfileMenu {
}
}

var providerProfileMenu: some View {
Menu {
ForEach(supportedProviders, content: providerProfileButton(for:))
} label: {
ThemeImageLabel(Strings.Views.App.Toolbar.NewProfile.provider, .profileProvider)
}
}

func providerProfileButton(for moduleType: ModuleType) -> some View {
Button(ModuleType.openVPN.localizedDescription) {
var editable = EditableProfile(name: newName)
let newModule = moduleType.newModule(with: registry)
editable.modules.append(newModule)
editable.modules.append(OnDemandModule.Builder())
editable.activeModulesIds = Set(editable.modules.map(\.id))
onNewProfile(editable)
}
}

var migrateProfilesButton: some View {
Button(action: onMigrateProfiles) {
ThemeImageLabel(Strings.Views.App.Toolbar.migrateProfiles.withTrailingDots, .profileMigrate)
Expand All @@ -80,4 +100,8 @@ private extension AddProfileMenu {
var newName: String {
profileManager.firstUniqueName(from: Strings.Placeholders.Profile.name)
}

var supportedProviders: [ModuleType] {
[.openVPN]
}
}

0 comments on commit 7fdd821

Please sign in to comment.