NCGlobal.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. //
  2. // NCGlobal.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 22/02/21.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. class NCGlobal: NSObject {
  25. @objc static let shared: NCGlobal = {
  26. let instance = NCGlobal()
  27. return instance
  28. }()
  29. func usernameToColor(_ username: String) -> CGColor {
  30. // Normalize hash
  31. let lowerUsername = username.lowercased()
  32. var hash: String
  33. let regex = try! NSRegularExpression(pattern: "^([0-9a-f]{4}-?){8}$")
  34. let matches = regex.matches(
  35. in: username,
  36. range: NSRange(username.startIndex..., in: username))
  37. if !matches.isEmpty {
  38. // Already a md5 hash?
  39. // done, use as is.
  40. hash = lowerUsername
  41. } else {
  42. hash = lowerUsername.md5()
  43. }
  44. hash = hash.replacingOccurrences(of: "[^0-9a-f]", with: "", options: .regularExpression)
  45. // userColors has 18 colors by default
  46. let userColorIx = NCGlobal.hashToInt(hash: hash, maximum: 18)
  47. return NCBrandColor.shared.userColors[userColorIx]
  48. }
  49. // Convert a string to an integer evenly
  50. // hash is hex string
  51. static func hashToInt(hash: String, maximum: Int) -> Int {
  52. let result = hash.compactMap(\.hexDigitValue)
  53. return result.reduce(0, { $0 + $1 }) % maximum
  54. }
  55. // Directory on Group
  56. //
  57. @objc let directoryProviderStorage = "File Provider Storage"
  58. @objc let appApplicationSupport = "Library/Application Support"
  59. @objc let appCertificates = "Library/Application Support/Certificates"
  60. @objc let appDatabaseNextcloud = "Library/Application Support/Nextcloud"
  61. @objc let appScan = "Library/Application Support/Scan"
  62. @objc let appUserData = "Library/Application Support/UserData"
  63. // Service
  64. //
  65. @objc let serviceShareKeyChain = "Crypto Cloud"
  66. let metadataKeyedUnarchiver = "it.twsweb.nextcloud.metadata"
  67. let refreshTask = "com.nextcloud.refreshTask"
  68. let processingTask = "com.nextcloud.processingTask"
  69. // App
  70. //
  71. let appName = "files"
  72. let appScheme = "nextcloud"
  73. let talkName = "talk-message"
  74. let spreedName = "spreed"
  75. let twoFactorNotificatioName = "twofactor_nextcloud_notification"
  76. // Nextcloud version
  77. //
  78. let nextcloudVersion12: Int = 12
  79. let nextcloudVersion15: Int = 15
  80. let nextcloudVersion17: Int = 17
  81. let nextcloudVersion18: Int = 18
  82. let nextcloudVersion20: Int = 20
  83. let nextcloudVersion23: Int = 23
  84. let nextcloudVersion24: Int = 24
  85. let nextcloudVersion25: Int = 25
  86. let nextcloudVersion26: Int = 26
  87. let nextcloudVersion27: Int = 27
  88. // Nextcloud unsupported
  89. //
  90. let nextcloud_unsupported_version: Int = 16
  91. // Intro selector
  92. //
  93. @objc let introLogin: Int = 0
  94. let introSignup: Int = 1
  95. // Varie size GUI
  96. //
  97. @objc let heightCellSettings: CGFloat = 50
  98. // Avatar & Preview size
  99. //
  100. let avatarSize: Int = 128 * Int(UIScreen.main.scale)
  101. let avatarSizeRounded: Int = 128
  102. let sizePreview: Int = 1024
  103. let sizeIcon: Int = 512
  104. // E2EE
  105. //
  106. let e2eePassphraseTest = "more over television factory tendency independence international intellectual impress interest sentence pony"
  107. @objc let e2eeReadVersions = ["1.1", "1.2", "2.0"]
  108. // CHUNK
  109. let chunkSizeMBCellular = 10000000
  110. let chunkSizeMBEthernetOrWiFi = 100000000
  111. // Video
  112. //
  113. let maxHTTPCache: Int64 = 10000000000 // 10 GB
  114. let fileNameVideoEncoded: String = "video_encoded.mp4"
  115. // NCViewerProviderContextMenu
  116. //
  117. let maxAutoDownload: UInt64 = 50000000 // 50MB
  118. let maxAutoDownloadCellular: UInt64 = 10000000 // 10MB
  119. // Layout
  120. //
  121. let layoutList = "typeLayoutList"
  122. let layoutGrid = "typeLayoutGrid"
  123. let layoutViewTrash = "LayoutTrash"
  124. let layoutViewOffline = "LayoutOffline"
  125. let layoutViewFavorite = "LayoutFavorite"
  126. let layoutViewFiles = "LayoutFiles"
  127. let layoutViewTransfers = "LayoutTransfers"
  128. let layoutViewRecent = "LayoutRecent"
  129. let layoutViewShares = "LayoutShares"
  130. let layoutViewShareExtension = "LayoutShareExtension"
  131. let layoutViewGroupfolders = "LayoutGroupfolders"
  132. // Button Type in Cell list/grid
  133. //
  134. let buttonMoreMore = "more"
  135. let buttonMoreStop = "stop"
  136. let buttonMoreLock = "moreLock"
  137. // Standard height sections header/footer
  138. //
  139. let heightButtonsView: CGFloat = 50
  140. let heightHeaderTransfer: CGFloat = 50
  141. let heightSection: CGFloat = 30
  142. let heightFooter: CGFloat = 1
  143. let heightFooterButton: CGFloat = 30
  144. let endHeightFooter: CGFloat = 85
  145. // Text - OnlyOffice - Collabora - QuickLook
  146. //
  147. let editorText = "text"
  148. let editorOnlyoffice = "onlyoffice"
  149. let editorCollabora = "collabora"
  150. let editorQuickLook = "quicklook"
  151. let onlyofficeDocx = "onlyoffice_docx"
  152. let onlyofficeXlsx = "onlyoffice_xlsx"
  153. let onlyofficePptx = "onlyoffice_pptx"
  154. // Template
  155. //
  156. let templateDocument = "document"
  157. let templateSpreadsheet = "spreadsheet"
  158. let templatePresentation = "presentation"
  159. // Rich Workspace
  160. //
  161. let fileNameRichWorkspace = "Readme.md"
  162. // Extension
  163. //
  164. @objc let extensionPreview = "ico"
  165. // ContentPresenter
  166. //
  167. @objc let dismissAfterSecond: TimeInterval = 4
  168. @objc let dismissAfterSecondLong: TimeInterval = 10
  169. // Error
  170. //
  171. @objc let errorRequestExplicityCancelled: Int = 15
  172. @objc let errorNotModified: Int = 304
  173. @objc let errorBadRequest: Int = 400
  174. @objc let errorUnauthorized401: Int = 401
  175. @objc let errorForbidden: Int = 403
  176. @objc let errorResourceNotFound: Int = 404
  177. @objc let errordMethodNotSupported: Int = 405
  178. @objc let errorConflict: Int = 409
  179. @objc let errorPreconditionFailed: Int = 412
  180. @objc let errorUnauthorized997: Int = 997
  181. @objc let errorConnectionLost: Int = -1005
  182. @objc let errorNetworkNotAvailable: Int = -1009
  183. @objc let errorBadServerResponse: Int = -1011
  184. @objc let errorInternalError: Int = -99999
  185. @objc let errorFileNotSaved: Int = -99998
  186. @objc let errorDecodeMetadata: Int = -99997
  187. @objc let errorE2EENotEnabled: Int = -99996
  188. @objc let errorE2EE: Int = -99995
  189. @objc let errorOffline: Int = -99994
  190. @objc let errorCharactersForbidden: Int = -99993
  191. @objc let errorCreationFile: Int = -99992
  192. @objc let errorReadFile: Int = -99991
  193. @objc let errorUnauthorizedFilesPasscode: Int = -99990
  194. @objc let errorDisableFilesApp: Int = -99989
  195. @objc let errorE2EEKeyChecksums: Int = -99988
  196. // Constants to identify the different permissions of a file
  197. //
  198. @objc let permissionShared = "S"
  199. @objc let permissionCanShare = "R"
  200. @objc let permissionMounted = "M"
  201. @objc let permissionFileCanWrite = "W"
  202. @objc let permissionCanCreateFile = "C"
  203. @objc let permissionCanCreateFolder = "K"
  204. @objc let permissionCanDelete = "D"
  205. @objc let permissionCanRename = "N"
  206. @objc let permissionCanMove = "V"
  207. // Share permission
  208. // permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all
  209. //
  210. @objc let permissionReadShare: Int = 1
  211. @objc let permissionUpdateShare: Int = 2
  212. @objc let permissionCreateShare: Int = 4
  213. @objc let permissionDeleteShare: Int = 8
  214. @objc let permissionShareShare: Int = 16
  215. @objc let permissionMinFileShare: Int = 1
  216. @objc let permissionMaxFileShare: Int = 19
  217. @objc let permissionMinFolderShare: Int = 1
  218. @objc let permissionMaxFolderShare: Int = 31
  219. @objc let permissionDefaultFileRemoteShareNoSupportShareOption: Int = 3
  220. @objc let permissionDefaultFolderRemoteShareNoSupportShareOption: Int = 15
  221. // ATTRIBUTES
  222. @objc let permissionDownloadShare: Int = 0
  223. // Filename Mask and Type
  224. //
  225. let keyFileNameMask = "fileNameMask"
  226. let keyFileNameType = "fileNameType"
  227. let keyFileNameAutoUploadMask = "fileNameAutoUploadMask"
  228. let keyFileNameAutoUploadType = "fileNameAutoUploadType"
  229. let keyFileNameOriginal = "fileNameOriginal"
  230. let keyFileNameOriginalAutoUpload = "fileNameOriginalAutoUpload"
  231. // Selector
  232. //
  233. let selectorDownloadFile = "downloadFile"
  234. let selectorDownloadAllFile = "downloadAllFile"
  235. let selectorReadFile = "readFile"
  236. let selectorListingFavorite = "listingFavorite"
  237. let selectorLoadFileView = "loadFileView"
  238. let selectorLoadFileQuickLook = "loadFileQuickLook"
  239. let selectorLoadOffline = "loadOffline"
  240. let selectorOpenIn = "openIn"
  241. let selectorPrint = "print"
  242. let selectorUploadAutoUpload = "uploadAutoUpload"
  243. let selectorUploadAutoUploadAll = "uploadAutoUploadAll"
  244. let selectorUploadFile = "uploadFile"
  245. let selectorUploadFileNODelete = "UploadFileNODelete"
  246. let selectorUploadFileShareExtension = "uploadFileShareExtension"
  247. let selectorSaveAlbum = "saveAlbum"
  248. let selectorSaveAlbumLivePhotoIMG = "saveAlbumLivePhotoIMG"
  249. let selectorSaveAlbumLivePhotoMOV = "saveAlbumLivePhotoMOV"
  250. let selectorSaveAsScan = "saveAsScan"
  251. let selectorOpenDetail = "openDetail"
  252. // Metadata : Status
  253. //
  254. // 1) wait download/upload
  255. // 2) in download/upload
  256. // 3) downloading/uploading
  257. // 4) done or error
  258. //
  259. let metadataStatusNormal: Int = 0
  260. let metadataStatusWaitDownload: Int = -1
  261. let metadataStatusInDownload: Int = -2
  262. let metadataStatusDownloading: Int = -3
  263. let metadataStatusDownloadError: Int = -4
  264. let metadataStatusWaitUpload: Int = 1
  265. let metadataStatusInUpload: Int = 2
  266. let metadataStatusUploading: Int = 3
  267. let metadataStatusUploadError: Int = 4
  268. // Hidden files included in the read
  269. //
  270. let includeHiddenFiles: [String] = [".LivePhoto"]
  271. // Auto upload subfolder granularity
  272. //
  273. @objc let subfolderGranularityDaily = 2
  274. @objc let subfolderGranularityMonthly = 1
  275. @objc let subfolderGranularityYearly = 0
  276. // Notification Center
  277. //
  278. @objc let notificationCenterApplicationDidEnterBackground = "applicationDidEnterBackground"
  279. let notificationCenterApplicationDidBecomeActive = "applicationDidBecomeActive"
  280. let notificationCenterApplicationWillResignActive = "applicationWillResignActive"
  281. @objc let notificationCenterInitialize = "initialize"
  282. @objc let notificationCenterChangeTheming = "changeTheming"
  283. let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus"
  284. let notificationCenterReloadDataNCShare = "reloadDataNCShare"
  285. let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView"
  286. let notificationCenterUpdateBadgeNumber = "updateBadgeNumber" // userInfo: counter
  287. let notificationCenterReloadAvatar = "reloadAvatar"
  288. @objc let notificationCenterReloadDataSource = "reloadDataSource" // userInfo: serverUrl?
  289. let notificationCenterReloadDataSourceNetwork = "reloadDataSourceNetwork" // userInfo: serverUrl?
  290. let notificationCenterReloadDataSourceNetworkForced = "reloadDataSourceNetworkForced"
  291. let notificationCenterChangeStatusFolderE2EE = "changeStatusFolderE2EE" // userInfo: serverUrl
  292. let notificationCenterDownloadStartFile = "downloadStartFile" // userInfo: ocId, serverUrl, account
  293. let notificationCenterDownloadedFile = "downloadedFile" // userInfo: ocId, serverUrl, account, selector, error
  294. let notificationCenterDownloadCancelFile = "downloadCancelFile" // userInfo: ocId, serverUrl, account
  295. let notificationCenterUploadStartFile = "uploadStartFile" // userInfo: ocId, serverUrl, account, fileName, sessionSelector
  296. @objc let notificationCenterUploadedFile = "uploadedFile" // userInfo: ocId, serverUrl, account, fileName, ocIdTemp, error
  297. let notificationCenterUploadCancelFile = "uploadCancelFile" // userInfo: ocId, serverUrl, account
  298. let notificationCenterProgressTask = "progressTask" // userInfo: account, ocId, serverUrl, status, chunk, e2eEncrypted, progress, totalBytes, totalBytesExpected
  299. let notificationCenterCreateFolder = "createFolder" // userInfo: ocId, serverUrl, account, e2ee, withPush
  300. let notificationCenterDeleteFile = "deleteFile" // userInfo: [ocId], [indexPath], onlyLocalCache, error, hud?
  301. let notificationCenterMoveFile = "moveFile" // userInfo: [ocId], [indexPath], error, hud?
  302. let notificationCenterCopyFile = "copyFile" // userInfo: [ocId], [indexPath], error, hud?
  303. let notificationCenterRenameFile = "renameFile" // userInfo: ocId, account, indexPath
  304. let notificationCenterFavoriteFile = "favoriteFile" // userInfo: ocId, serverUrl
  305. let notificationCenterOperationReadFile = "operationReadFile" // userInfo: ocId
  306. let notificationCenterMenuSearchTextPDF = "menuSearchTextPDF"
  307. let notificationCenterMenuGotToPageInPDF = "menuGotToPageInPDF"
  308. let notificationCenterMenuDetailClose = "menuDetailClose"
  309. let notificationCenterDownloadedThumbnail = "DownloadedThumbnail" // userInfo: ocId
  310. let notificationCenterOpenMediaDetail = "openMediaDetail" // userInfo: ocId
  311. let notificationCenterDismissScanDocument = "dismissScanDocument"
  312. let notificationCenterDismissUploadAssets = "dismissUploadAssets"
  313. let notificationCenterEnableSwipeGesture = "enableSwipeGesture"
  314. let notificationCenterDisableSwipeGesture = "disableSwipeGesture"
  315. // TIP
  316. //
  317. let tipNCViewerPDFThumbnail = "tipncviewerpdfthumbnail"
  318. let tipNCCollectionViewCommonAccountRequest = "tipnccollectionviewcommonaccountrequest"
  319. let tipNCScanAddImage = "tipncscanaddimage"
  320. let tipNCViewerMediaDetailView = "tipncviewermediadetailview"
  321. // ACTION
  322. //
  323. let actionNoAction = "no-action"
  324. let actionUploadAsset = "upload-asset"
  325. let actionScanDocument = "add-scan-document"
  326. let actionTextDocument = "create-text-document"
  327. let actionVoiceMemo = "create-voice-memo"
  328. // WIDGET ACTION
  329. //
  330. let widgetActionNoAction = "nextcloud://open-action?action=no-action"
  331. let widgetActionUploadAsset = "nextcloud://open-action?action=upload-asset"
  332. let widgetActionScanDocument = "nextcloud://open-action?action=add-scan-document"
  333. let widgetActionTextDocument = "nextcloud://open-action?action=create-text-document"
  334. let widgetActionVoiceMemo = "nextcloud://open-action?action=create-voice-memo"
  335. // APPCONFIG
  336. //
  337. let configuration_brand = "brand"
  338. let configuration_serverUrl = "serverUrl"
  339. let configuration_username = "username"
  340. let configuration_password = "password"
  341. let configuration_apppassword = "apppassword"
  342. let configuration_disable_intro = "disable_intro"
  343. let configuration_disable_multiaccount = "disable_multiaccount"
  344. let configuration_disable_crash_service = "disable_crash_service"
  345. let configuration_disable_log = "disable_log"
  346. let configuration_disable_manage_account = "disable_manage_account"
  347. let configuration_disable_more_external_site = "disable_more_external_site"
  348. let configuration_disable_openin_file = "disable_openin_file"
  349. // CAPABILITIES
  350. //
  351. var capabilityServerVersionMajor: Int = 0
  352. @objc var capabilityServerVersion: String = ""
  353. var capabilityFileSharingApiEnabled: Bool = false
  354. var capabilityFileSharingPubPasswdEnforced: Bool = false
  355. var capabilityFileSharingPubExpireDateEnforced: Bool = false
  356. var capabilityFileSharingPubExpireDateDays: Int = 0
  357. var capabilityFileSharingInternalExpireDateEnforced: Bool = false
  358. var capabilityFileSharingInternalExpireDateDays: Int = 0
  359. var capabilityFileSharingRemoteExpireDateEnforced: Bool = false
  360. var capabilityFileSharingRemoteExpireDateDays: Int = 0
  361. var capabilityFileSharingDefaultPermission: Int = 0
  362. var capabilityThemingColor: String = ""
  363. var capabilityThemingColorElement: String = ""
  364. var capabilityThemingColorText: String = ""
  365. @objc var capabilityThemingName: String = ""
  366. @objc var capabilityThemingSlogan: String = ""
  367. @objc var capabilityE2EEEnabled: Bool = false
  368. @objc var capabilityE2EEApiVersion: String = ""
  369. var capabilityRichdocumentsMimetypes: [String] = []
  370. var capabilityActivity: [String] = []
  371. var capabilityNotification: [String] = []
  372. var capabilityFilesUndelete: Bool = false
  373. var capabilityFilesLockVersion: String = "" // NC 24
  374. var capabilityFilesComments: Bool = false // NC 20
  375. @objc var capabilityUserStatusEnabled: Bool = false
  376. var capabilityExternalSites: Bool = false
  377. var capabilityGroupfoldersEnabled: Bool = false // NC27
  378. // MORE NEXTCLOUD APPS
  379. let talkSchemeUrl = "nextcloudtalk://"
  380. let notesSchemeUrl = "nextcloudnotes://"
  381. let talkAppStoreUrl = "https://apps.apple.com/de/app/nextcloud-talk/id1296825574"
  382. let notesAppStoreUrl = "https://apps.apple.com/de/app/nextcloud-notes/id813973264"
  383. let moreAppsUrl = "https://www.apple.com/us/search/nextcloud?src=globalnav"
  384. // SNAPSHOT PREVIEW
  385. let defaultSnapshotConfiguration = "DefaultPreviewConfiguration"
  386. }