This repository has been archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/0/1206942473732463/f
- Loading branch information
1 parent
58bfb4c
commit b59493f
Showing
56 changed files
with
1,026 additions
and
107 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/Assets/vpn-dark-mode.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/Assets/vpn-light-mode.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...NetworkProtection/AppTargets/BothAppTargets/VPNLocation/DefaultVPNLocationFormatter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// DefaultVPNLocationFormatter.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import NetworkProtection | ||
|
||
struct DefaultVPNLocationFormatter: VPNLocationFormatting { | ||
func emoji(for country: String?, | ||
preferredLocation someLocation: VPNSettings.SelectedLocation) -> String? { | ||
if let country { | ||
return NetworkProtectionVPNCountryLabelsModel(country: country, useFullCountryName: true).emoji | ||
} | ||
|
||
let preferredLocation = VPNLocationModel(selectedLocation: someLocation) | ||
switch preferredLocation.icon { | ||
case .defaultIcon: | ||
return nil | ||
case .emoji(let emoji): | ||
return emoji | ||
} | ||
} | ||
|
||
func string(from location: String?, | ||
preferredLocation someLocation: VPNSettings.SelectedLocation) -> String { | ||
let preferredLocation = VPNLocationModel(selectedLocation: someLocation) | ||
|
||
if let location { | ||
return preferredLocation.isNearest ? "\(location) (Nearest)" : location | ||
} | ||
|
||
return preferredLocation.title | ||
} | ||
|
||
@available(macOS 12, *) | ||
func string(from location: String?, | ||
preferredLocation someLocation: VPNSettings.SelectedLocation, | ||
locationTextColor: Color, | ||
preferredLocationTextColor: Color) -> AttributedString { | ||
let preferredLocation = VPNLocationModel(selectedLocation: someLocation) | ||
|
||
if let location { | ||
var attributedString = AttributedString( | ||
preferredLocation.isNearest ? "\(location) \(UserText.netPVPNLocationNearest)" : location | ||
) | ||
attributedString.foregroundColor = locationTextColor | ||
if let range = attributedString.range(of: UserText.netPVPNLocationNearest) { | ||
attributedString[range].foregroundColor = preferredLocationTextColor | ||
} | ||
return attributedString | ||
} | ||
|
||
var attributedString = AttributedString(preferredLocation.title) | ||
attributedString.foregroundColor = locationTextColor | ||
return attributedString | ||
} | ||
} | ||
|
||
final class VPNLocationModel: ObservableObject { | ||
enum LocationIcon { | ||
case defaultIcon | ||
case emoji(String) | ||
} | ||
|
||
let title: String | ||
let icon: LocationIcon | ||
let isNearest: Bool | ||
|
||
init(selectedLocation: VPNSettings.SelectedLocation) { | ||
switch selectedLocation { | ||
case .nearest: | ||
title = UserText.vpnLocationNearestAvailable | ||
icon = .defaultIcon | ||
isNearest = true | ||
case .location(let location): | ||
let countryLabelsModel = NetworkProtectionVPNCountryLabelsModel(country: location.country, useFullCountryName: true) | ||
if let city = location.city { | ||
title = UserText.netPVPNSettingsLocationSubtitleFormattedCityAndCountry( | ||
city: city, | ||
country: countryLabelsModel.title | ||
) | ||
} else { | ||
title = countryLabelsModel.title | ||
} | ||
icon = .emoji(countryLabelsModel.emoji) | ||
isNearest = false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.