-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.swift
105 lines (90 loc) · 3.2 KB
/
Config.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// Config.swift
// Switchcraft
//
// Created by Brendan Lensink on 2018-03-29.
// Copyright (c) 2018 Steamclock Software. All rights reserved.
//
import Foundation
/**
* Handles config options for a Switchcraft instance.
*/
public struct Config {
/**
* The location in UserDefaults.standard where the endpoint is stored.
* Default is "switchcraftEndpoint".
*/
public var defaultsKey: String
/**
* The alert view title.
* Default is "Select an Endpoint".
*/
public var alertTitle = "Select an Endpoint"
/**
* The alert view message.
* Default is the current build name and version number.
*/
public var alertMessage: String? {
guard let bundle = Bundle.main.infoDictionary,
let displayName = (bundle["CFBundleDisplayName"] as? String) ?? (bundle["CFBundleName"] as? String),
let versionString = bundle["CFBundleShortVersionString"] as? String,
let buildNumber = bundle["CFBundleVersion"] as? String else {
return nil
}
return displayName + " " + versionString + "-" + buildNumber
}
/**
* The alert view text field placeholder.
* Default is "Enter Value".
*/
public var textFieldPlaceholder = "Enter Value"
/**
* The alert view text field submit button.
* Default is "Use Custom".
*/
public var textFieldDoneTitle = "Use Custom"
/**
* The alert view cancel button title.
* Default is "Cancel".
*/
public var cancelTitle = "Cancel"
/**
* Whether the alert view will show a text field allowing custom entry.
* Default is `false`.
*/
public var allowCustom = false
/**
* The set of endpoints to be shown in the switcher.
*/
public var endpoints: [Endpoint] = []
/**
* The set of custom actions to be shown in the switcher.
*/
public var actions: [Action] = []
/**
* The endpoint index to use in cases of new installations or irrecoverable changes.
* Default is `0`.
*/
public var defaultEndpointIndex: Int = 0
/**
* Show an alert if the app requires a restart before the endpoint change will take effect.
* If set to true, after changing endpoints there will be an alert presented with an option to force quit the app to restart.
* Default is `false`.
*/
public var changeRequiresRestart: Bool = false
/**
* Create a new config with a set of endpoints and key.
*
* - parameter defaultsKey: The key to store the endpoint under in `UserDefaults`.
* - parameter endpoints: The set of endpoints to show in the picker.
* - parameter defaultEndpointIndex: Which endpoint index to use in cases of new installations or irrecoverable changes. 0 if unspecified.
* - parameter allowCustom: Whether the switcher allows entering custom endpoints.
*/
public init(defaultsKey: String, endpoints: [Endpoint], defaultEndpointIndex: Int = 0, actions: [Action] = [], allowCustom: Bool = false) {
self.defaultsKey = defaultsKey
self.endpoints = endpoints
self.defaultEndpointIndex = defaultEndpointIndex
self.allowCustom = allowCustom
self.actions = actions
}
}