forked from nextcloud/ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNCBrand.swift
executable file
·292 lines (248 loc) · 12.3 KB
/
NCBrand.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
//
// NCBrandColor.swift
// Nextcloud
//
// Created by Marino Faggiana on 24/04/17.
// Copyright (c) 2017 Marino Faggiana. All rights reserved.
//
// Author Marino Faggiana <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
let userAgent: String = {
let appVersion: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
// Original Nextcloud useragent "Mozilla/5.0 (iOS) Nextcloud-iOS/\(appVersion)"
return "Mozilla/5.0 (iOS) Nextcloud-iOS/\(appVersion)"
}()
@objc class NCBrandOptions: NSObject {
@objc static let shared: NCBrandOptions = {
let instance = NCBrandOptions()
return instance
}()
@objc public var brand: String = "Nextcloud"
@objc public var textCopyrightNextcloudiOS: String = "Nextcloud Hydrogen for iOS %@ © 2024"
@objc public var textCopyrightNextcloudServer: String = "Nextcloud Server %@"
@objc public var loginBaseUrl: String = "https://cloud.nextcloud.com"
@objc public var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com"
@objc public var linkLoginHost: String = "https://nextcloud.com/install"
@objc public var linkloginPreferredProviders: String = "https://nextcloud.com/signup-ios"
@objc public var webLoginAutenticationProtocol: String = "nc://" // example "abc://"
@objc public var privacy: String = "https://nextcloud.com/privacy"
@objc public var sourceCode: String = "https://github.com/nextcloud/ios"
@objc public var mobileconfig: String = "/remote.php/dav/provisioning/apple-provisioning.mobileconfig"
// Personalized
@objc public var webCloseViewProtocolPersonalized: String = "" // example "abc://change/plan" Don't touch me !!
@objc public var folderBrandAutoUpload: String = "" // example "_auto_upload_folder_" Don't touch me !!
// Auto Upload default folder
@objc public var folderDefaultAutoUpload: String = "Photos"
// Capabilities Group
@objc public var capabilitiesGroups: String = "group.it.twsweb.Crypto-Cloud"
@objc public var capabilitiesGroupApps: String = "group.com.nextcloud.apps"
// BRAND ONLY
@objc public var use_login_web_personalized: Bool = false // Don't touch me !!
@objc public var use_AppConfig: Bool = false // Don't touch me !!
@objc public var use_GroupApps: Bool = true // Don't touch me !!
// Options
@objc public var use_default_auto_upload: Bool = false
@objc public var use_themingColor: Bool = true
@objc public var use_themingLogo: Bool = false
@objc public var use_storeLocalAutoUploadAll: Bool = false
@objc public var use_loginflowv2: Bool = false // Don't touch me !!
@objc public var disable_intro: Bool = false
@objc public var disable_request_login_url: Bool = false
@objc public var disable_multiaccount: Bool = false
@objc public var disable_manage_account: Bool = false
@objc public var disable_more_external_site: Bool = false
@objc public var disable_openin_file: Bool = false // Don't touch me !!
@objc public var disable_crash_service: Bool = false
@objc public var disable_log: Bool = false
@objc public var disable_mobileconfig: Bool = false
@objc public var disable_show_more_nextcloud_apps_in_settings: Bool = false
@objc public var doNotAskPasscodeAtStartup: Bool = false
// Internal option behaviour
@objc public var cleanUpDay: Int = 0 // Set default "Delete, in the cache, all files older than" possible days value are: 0, 1, 7, 30, 90, 180, 365
// Max download/upload concurrent
public let maxConcurrentOperationDownload: Int = 5
public let maxConcurrentOperationUpload: Int = 5
// Number of failed attempts after reset app
@objc public let resetAppPasscodeAttempts: Int = 10
public let passcodeSecondsFail: Int = 60
// Info Paging
enum NCInfoPagingTab: Int, CaseIterable {
case activity, sharing
}
override init() {
if folderBrandAutoUpload != "" {
folderDefaultAutoUpload = folderBrandAutoUpload
}
// wrapper AppConfig
if let configurationManaged = UserDefaults.standard.dictionary(forKey: "com.apple.configuration.managed"), use_AppConfig {
if let str = configurationManaged[NCGlobal.shared.configuration_brand] as? String {
brand = str
}
if let str = configurationManaged[NCGlobal.shared.configuration_disable_intro] as? String {
disable_intro = (str as NSString).boolValue
}
if let str = configurationManaged[NCGlobal.shared.configuration_disable_multiaccount] as? String {
disable_multiaccount = (str as NSString).boolValue
}
if let str = configurationManaged[NCGlobal.shared.configuration_disable_crash_service] as? String {
disable_crash_service = (str as NSString).boolValue
}
if let str = configurationManaged[NCGlobal.shared.configuration_disable_log] as? String {
disable_log = (str as NSString).boolValue
}
if let str = configurationManaged[NCGlobal.shared.configuration_disable_manage_account] as? String {
disable_manage_account = (str as NSString).boolValue
}
if let str = configurationManaged[NCGlobal.shared.configuration_disable_more_external_site] as? String {
disable_more_external_site = (str as NSString).boolValue
}
if let str = configurationManaged[NCGlobal.shared.configuration_disable_openin_file] as? String {
disable_openin_file = (str as NSString).boolValue
}
}
}
@objc func getUserAgent() -> String {
return userAgent
}
}
class NCBrandColor: NSObject {
@objc static let shared: NCBrandColor = {
let instance = NCBrandColor()
return instance
}()
// Color
@objc public let customer: UIColor = UIColor(red: 0.0 / 255.0, green: 130.0 / 255.0, blue: 201.0 / 255.0, alpha: 1.0) // BLU NC : #0082c9
@objc public var customerText: UIColor = .white
@objc public var brand: UIColor // don't touch me
@objc public var brandElement: UIColor // don't touch me
@objc public var brandText: UIColor // don't touch me
@objc public let nextcloud: UIColor = UIColor(red: 0.0 / 255.0, green: 130.0 / 255.0, blue: 201.0 / 255.0, alpha: 1.0)
@objc public let yellowFavorite: UIColor = UIColor(red: 248.0 / 255.0, green: 205.0 / 255.0, blue: 70.0 / 255.0, alpha: 1.0)
public var userColors: [CGColor] = []
public var themingColor: String = ""
public var themingColorElement: String = ""
public var themingColorText: String = ""
@objc public var systemMint: UIColor {
get {
return UIColor(red: 0.0 / 255.0, green: 199.0 / 255.0, blue: 190.0 / 255.0, alpha: 1.0)
}
}
override init() {
brand = customer
brandElement = customer
brandText = customerText
}
func createUserColors() {
userColors = generateColors()
}
func settingThemingColor(account: String) {
let darker: CGFloat = 30 // %
let lighter: CGFloat = 30 // %
if NCBrandOptions.shared.use_themingColor {
self.themingColor = NCGlobal.shared.capabilityThemingColor
self.themingColorElement = NCGlobal.shared.capabilityThemingColorElement
self.themingColorText = NCGlobal.shared.capabilityThemingColorText
// COLOR
if themingColor.first == "#" {
if let color = UIColor(hex: themingColor) {
brand = color
} else {
brand = customer
}
} else {
brand = customer
}
// COLOR TEXT
if themingColorText.first == "#" {
if let color = UIColor(hex: themingColorText) {
brandText = color
} else {
brandText = customerText
}
} else {
brandText = customerText
}
// COLOR ELEMENT
if themingColorElement.first == "#" {
if let color = UIColor(hex: themingColorElement) {
brandElement = color
} else {
brandElement = brand
}
} else {
brandElement = brand
}
if brandElement.isTooLight() {
if let color = brandElement.darker(by: darker) {
brandElement = color
}
} else if brandElement.isTooDark() {
if let color = brandElement.lighter(by: lighter) {
brandElement = color
}
}
} else {
if self.customer.isTooLight() {
if let color = customer.darker(by: darker) {
brandElement = color
}
} else if customer.isTooDark() {
if let color = customer.lighter(by: lighter) {
brandElement = color
}
} else {
brandElement = customer
}
brand = customer
brandText = customerText
}
}
private func stepCalc(steps: Int, color1: CGColor, color2: CGColor) -> [CGFloat] {
var step = [CGFloat](repeating: 0, count: 3)
step[0] = (color2.components![0] - color1.components![0]) / CGFloat(steps)
step[1] = (color2.components![1] - color1.components![1]) / CGFloat(steps)
step[2] = (color2.components![2] - color1.components![2]) / CGFloat(steps)
return step
}
private func mixPalette(steps: Int, color1: CGColor, color2: CGColor) -> [CGColor] {
var palette = [color1]
let step = stepCalc(steps: steps, color1: color1, color2: color2)
let c1Components = color1.components!
for i in 1 ..< steps {
let r = c1Components[0] + step[0] * CGFloat(i)
let g = c1Components[1] + step[1] * CGFloat(i)
let b = c1Components[2] + step[2] * CGFloat(i)
palette.append(UIColor(red: r, green: g, blue: b, alpha: 1).cgColor)
}
return palette
}
/**
Generate colors from the official nextcloud color.
You can provide how many colors you want (multiplied by 3).
if `step` = 6,
3 colors \* 6 will result in 18 generated colors
*/
func generateColors(steps: Int = 6) -> [CGColor] {
let red = UIColor(red: 182 / 255, green: 70 / 255, blue: 157 / 255, alpha: 1).cgColor
let yellow = UIColor(red: 221 / 255, green: 203 / 255, blue: 85 / 255, alpha: 1).cgColor
let blue = UIColor(red: 0 / 255, green: 130 / 255, blue: 201 / 255, alpha: 1).cgColor
let palette1 = mixPalette(steps: steps, color1: red, color2: yellow)
let palette2 = mixPalette(steps: steps, color1: yellow, color2: blue)
let palette3 = mixPalette(steps: steps, color1: blue, color2: red)
return palette1 + palette2 + palette3
}
}