-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.swift
159 lines (125 loc) · 3.53 KB
/
Settings.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// Settings.swift
// Absinthe-iOS
//
// Created by Mitchell Kahn on 7/13/16.
// Copyright © 2016 Ourglass TV. All rights reserved.
//
import Foundation
/// `NSUserDefaults` settings are wrapped here for cleanliness.
class Settings {
let userDefaults = UserDefaults.standard
static let sharedInstance = Settings()
// MARK Asahi Cloud Services
var hasValidJwt: Bool {
get {
if self.userBelliniJWTExpiry != nil && self.userBelliniJWT != nil {
if Date() < Date(timeIntervalSince1970: Settings.sharedInstance.userBelliniJWTExpiry! - 86400.0) { // JWT has expired or will expire in the next day
return true
}
}
return false
}
}
var userBelliniJWT: String? {
get {
return userDefaults.string(forKey: "userBelliniJWT")
}
set {
userDefaults.set(newValue, forKey: "userBelliniJWT")
}
}
func getJwt() -> String {
return userBelliniJWT ?? ""
}
var userBelliniJWTExpiry: Double? {
get {
return userDefaults.double(forKey: "userBelliniJWTExpiry")
}
set {
userDefaults.set(newValue, forKey: "userBelliniJWTExpiry")
}
}
// MARK: User info
var userId: String? {
get {
return userDefaults.string(forKey: "userId")
}
set {
userDefaults.set(newValue, forKey: "userId")
}
}
var userFirstName: String? {
get {
return userDefaults.string(forKey: "userFirstName")
}
set {
userDefaults.set(newValue, forKey: "userFirstName")
}
}
var userLastName: String? {
get {
return userDefaults.string(forKey: "userLastName")
}
set {
userDefaults.set(newValue, forKey: "userLastName")
}
}
var userEmail: String? {
get {
return userDefaults.string(forKey: "userEmail")
}
set {
userDefaults.set(newValue, forKey: "userEmail")
}
}
var allowAccountCreation: Bool {
get {
return userDefaults.bool(forKey: "allowAccountCreation")
}
set {
userDefaults.set(newValue, forKey: "allowAccountCreation")
}
}
var appOpened: Bool {
get {
return userDefaults.bool(forKey: "appOpened")
}
set {
userDefaults.set(newValue, forKey: "appOpened")
}
}
var alwaysShowIntro: Bool {
get {
return userDefaults.bool(forKey: "alwaysShowIntro")
}
set {
userDefaults.set(newValue, forKey: "alwaysShowIntro")
}
}
// New stuff to allow to point to dev server(s)
var useDevServer: Bool {
get {
return userDefaults.bool(forKey: "useDevServer")
}
set {
userDefaults.set(newValue, forKey: "useDevServer")
}
}
var userIsDeveloper: Bool {
get {
return userDefaults.bool(forKey: "userIsDev")
}
set {
userDefaults.set(newValue, forKey: "userIsDev")
}
}
// MARK:Defaults
func registerDefaults() {
userDefaults.register(defaults: [
"alwaysShowIntro": false,
"allowAccountCreation": true,
"appOpened": false
])
}
}