-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'IOS-881-shadowsocks-obfuscation-settings'
- Loading branch information
Showing
10 changed files
with
492 additions
and
57 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
...MullvadVPN/View controllers/Settings/Obfuscation/ShadowsocksObfuscationSettingsView.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,72 @@ | ||
// | ||
// ShadowsocksObfuscationSettingsView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Andrew Bulhak on 2024-11-07. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import MullvadSettings | ||
import SwiftUI | ||
|
||
struct ShadowsocksObfuscationSettingsView<VM>: View where VM: ShadowsocksObfuscationSettingsViewModel { | ||
@StateObject var viewModel: VM | ||
|
||
var body: some View { | ||
let portString = NSLocalizedString( | ||
"SHADOWSOCKS_PORT_LABEL", | ||
tableName: "Shadowsocks", | ||
value: "Port", | ||
comment: "" | ||
) | ||
|
||
SingleChoiceList( | ||
title: portString, | ||
options: [WireGuardObfuscationShadowsockPort.automatic], | ||
value: $viewModel.value, | ||
itemDescription: { item in NSLocalizedString( | ||
"SHADOWSOCKS_PORT_VALUE_\(item)", | ||
tableName: "Shadowsocks", | ||
value: "\(item)", | ||
comment: "" | ||
) }, | ||
parseCustomValue: { UInt16($0).flatMap { $0 > 0 ? WireGuardObfuscationShadowsockPort.custom($0) : nil } | ||
}, | ||
formatCustomValue: { | ||
if case let .custom(port) = $0 { | ||
"\(port)" | ||
} else { | ||
nil | ||
} | ||
}, | ||
customLabel: NSLocalizedString( | ||
"SHADOWSOCKS_PORT_VALUE_CUSTOM", | ||
tableName: "Shadowsocks", | ||
value: "Custom", | ||
comment: "" | ||
), | ||
customPrompt: NSLocalizedString( | ||
"SHADOWSOCKS_PORT_VALUE_PORT_PROMPT", | ||
tableName: "Shadowsocks", | ||
value: "Port", | ||
comment: "" | ||
), | ||
customLegend: NSLocalizedString( | ||
"SHADOWSOCKS_PORT_VALUE_PORT_LEGEND", | ||
tableName: "Shadowsocks", | ||
value: "Valid range: 1 - 65535", | ||
comment: "" | ||
), | ||
customInputMinWidth: 100, | ||
customInputMaxLength: 5, | ||
customFieldMode: .numericText | ||
).onDisappear { | ||
viewModel.commit() | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
let model = MockShadowsocksObfuscationSettingsViewModel(shadowsocksPort: .automatic) | ||
return ShadowsocksObfuscationSettingsView(viewModel: model) | ||
} |
40 changes: 40 additions & 0 deletions
40
...adVPN/View controllers/Settings/Obfuscation/ShadowsocksObfuscationSettingsViewModel.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,40 @@ | ||
// | ||
// ShadowsocksObfuscationSettingsViewModel.swift | ||
// MullvadVPN | ||
// | ||
// Created by Andrew Bulhak on 2024-11-07. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MullvadSettings | ||
|
||
protocol ShadowsocksObfuscationSettingsViewModel: ObservableObject { | ||
var value: WireGuardObfuscationShadowsockPort { get set } | ||
|
||
func commit() | ||
} | ||
|
||
/** A simple mock view model for use in Previews and similar */ | ||
class MockShadowsocksObfuscationSettingsViewModel: ShadowsocksObfuscationSettingsViewModel { | ||
@Published var value: WireGuardObfuscationShadowsockPort | ||
|
||
init(shadowsocksPort: WireGuardObfuscationShadowsockPort = .automatic) { | ||
self.value = shadowsocksPort | ||
} | ||
|
||
func commit() {} | ||
} | ||
|
||
/// ** The live view model which interfaces with the TunnelManager */ | ||
class TunnelShadowsocksObfuscationSettingsViewModel: TunnelObfuscationSettingsWatchingObservableObject< | ||
WireGuardObfuscationShadowsockPort | ||
>, | ||
ShadowsocksObfuscationSettingsViewModel { | ||
init(tunnelManager: TunnelManager) { | ||
super.init( | ||
tunnelManager: tunnelManager, | ||
keyPath: \.shadowsocksPort | ||
) | ||
} | ||
} |
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.