diff options
Diffstat (limited to 'gui/src/shared')
| -rw-r--r-- | gui/src/shared/bridge-settings-builder.ts | 28 | ||||
| -rw-r--r-- | gui/src/shared/daemon-rpc-types.ts | 79 | ||||
| -rw-r--r-- | gui/src/shared/localization-contexts.ts | 1 | ||||
| -rw-r--r-- | gui/src/shared/relay-location-builder.ts | 41 |
4 files changed, 19 insertions, 130 deletions
diff --git a/gui/src/shared/bridge-settings-builder.ts b/gui/src/shared/bridge-settings-builder.ts deleted file mode 100644 index 2ee5469707..0000000000 --- a/gui/src/shared/bridge-settings-builder.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { BridgeSettings, IBridgeConstraints, Ownership } from './daemon-rpc-types'; -import makeLocationBuilder, { ILocationBuilder } from './relay-location-builder'; - -export default class BridgeSettingsBuilder { - private payload: Partial<IBridgeConstraints> = {}; - - public build(): BridgeSettings { - if (this.payload.location) { - return { - type: 'normal', - normal: { - location: this.payload.location, - providers: this.payload.providers ?? [], - ownership: this.payload.ownership ?? Ownership.any, - }, - custom: undefined, - }; - } else { - throw new Error('Unsupported configuration'); - } - } - - get location(): ILocationBuilder<BridgeSettingsBuilder> { - return makeLocationBuilder(this, (location) => { - this.payload.location = location; - }); - } -} diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts index e24c124f4c..738eef5e95 100644 --- a/gui/src/shared/daemon-rpc-types.ts +++ b/gui/src/shared/daemon-rpc-types.ts @@ -128,16 +128,6 @@ export function wrapConstraint<T>( } export type ProxyType = 'shadowsocks' | 'custom'; -export function proxyTypeToString(proxy: ProxyType): string { - switch (proxy) { - case 'shadowsocks': - return 'Shadowsocks bridge'; - case 'custom': - return 'custom bridge'; - default: - return ''; - } -} export enum Ownership { any, @@ -352,35 +342,6 @@ export interface IDnsOptions { }; } -export type ProxySettings = - | { local: ILocalProxySettings } - | { remote: IRemoteProxySettings } - | { shadowsocks: IShadowsocksProxySettings }; - -export interface ILocalProxySettings { - localPort: number; - remoteIp: string; - remotePort: number; -} - -export interface IRemoteProxySettings { - ip: string; - port: number; - auth?: IRemoteProxyAuth; -} - -export interface IRemoteProxyAuth { - username: string; - password: string; -} - -export interface IShadowsocksProxySettings { - ip: string; - port: number; - password: string; - cipher: string; -} - export interface IAppVersionInfo { supported: boolean; suggestedUpgrade?: string; @@ -471,7 +432,7 @@ export type BridgeType = 'normal' | 'custom'; export interface BridgeSettings { type: BridgeType; normal: IBridgeConstraints; - custom?: ProxySettings; + custom?: CustomProxy; } export interface ISocketAddress { @@ -488,7 +449,7 @@ export interface SocksAuth { password: string; } -export type Socks5LocalAccessMethod = { +export type Socks5LocalCustomProxy = { type: 'socks5-local'; remoteIp: string; remotePort: number; @@ -496,14 +457,14 @@ export type Socks5LocalAccessMethod = { localPort: number; }; -export type Socks5RemoteAccessMethod = { +export type Socks5RemoteCustomProxy = { type: 'socks5-remote'; ip: string; port: number; authentication?: SocksAuth; }; -export type ShadowsocksAccessMethod = { +export type ShadowsocksCustomProxy = { type: 'shadowsocks'; ip: string; port: number; @@ -511,33 +472,29 @@ export type ShadowsocksAccessMethod = { cipher: string; }; -export type CustomProxy = - | Socks5LocalAccessMethod - | Socks5RemoteAccessMethod - | ShadowsocksAccessMethod; +export type CustomProxy = Socks5LocalCustomProxy | Socks5RemoteCustomProxy | ShadowsocksCustomProxy; +export type NamedCustomProxy = CustomProxy & { name: string }; -export type AccessMethod = - | { - type: 'direct'; - } - | { - type: 'bridges'; - } - | CustomProxy; +export type DirectMethod = { type: 'direct' }; +export type BridgesMethod = { type: 'bridges' }; +export type AccessMethod = DirectMethod | BridgesMethod | CustomProxy; -export type NewAccessMethodSetting = AccessMethod & { - name: string; +export type NamedAccessMethod<T extends AccessMethod> = T & { name: string }; + +export type NewAccessMethodSetting<T extends AccessMethod = AccessMethod> = NamedAccessMethod<T> & { enabled: boolean; }; -export type AccessMethodSetting = NewAccessMethodSetting & { +export type AccessMethodSetting< + T extends AccessMethod = AccessMethod +> = NewAccessMethodSetting<T> & { id: string; }; export type ApiAccessMethodSettings = { - direct: AccessMethodSetting; - mullvadBridges: AccessMethodSetting; - custom: Array<AccessMethodSetting>; + direct: AccessMethodSetting<DirectMethod>; + mullvadBridges: AccessMethodSetting<BridgesMethod>; + custom: Array<AccessMethodSetting<CustomProxy>>; }; export interface RelayOverride { diff --git a/gui/src/shared/localization-contexts.ts b/gui/src/shared/localization-contexts.ts index 71a663def0..f30212025c 100644 --- a/gui/src/shared/localization-contexts.ts +++ b/gui/src/shared/localization-contexts.ts @@ -15,6 +15,7 @@ export type LocalizationContexts = | 'account-expiry' | 'select-location-view' | 'select-location-nav' + | 'custom-bridge' | 'filter-view' | 'filter-nav' | 'settings-view' diff --git a/gui/src/shared/relay-location-builder.ts b/gui/src/shared/relay-location-builder.ts deleted file mode 100644 index 7e585f9eaf..0000000000 --- a/gui/src/shared/relay-location-builder.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Constraint, LiftedConstraint, RelayLocation } from './daemon-rpc-types'; - -export interface ILocationBuilder<Self> { - country(country: string): Self; - city(country: string, city: string): Self; - hostname(country: string, city: string, hostname: string): Self; - any(): Self; - fromRaw(location: LiftedConstraint<RelayLocation>): Self; -} - -export default function makeLocationBuilder<T>( - context: T, - receiver: (constraint: Constraint<RelayLocation>) => void, -): ILocationBuilder<T> { - return { - country: (country: string) => { - receiver({ only: { country } }); - return context; - }, - city: (country: string, city: string) => { - receiver({ only: { country, city } }); - return context; - }, - hostname: (country: string, city: string, hostname: string) => { - receiver({ only: { country, city, hostname } }); - return context; - }, - any: () => { - receiver('any'); - return context; - }, - fromRaw(location: LiftedConstraint<RelayLocation>) { - if (location === 'any') { - return this.any(); - } else { - receiver({ only: location }); - return context; - } - }, - }; -} |
