NCGlobal.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 Foundation
  24. class NCGlobal: NSObject {
  25. @objc static let shared: NCGlobal = {
  26. let instance = NCGlobal()
  27. return instance
  28. }()
  29. // Struct for Progress
  30. struct progressType {
  31. var progress: Float
  32. var totalBytes: Int64
  33. var totalBytesExpected: Int64
  34. }
  35. // Directory on Group
  36. @objc let appDatabaseNextcloud = "Library/Application Support/Nextcloud"
  37. @objc let appApplicationSupport = "Library/Application Support"
  38. @objc let appUserData = "Library/Application Support/UserData"
  39. @objc let appCertificates = "Library/Application Support/Certificates"
  40. @objc let appScan = "Library/Application Support/Scan"
  41. @objc let directoryProviderStorage = "File Provider Storage"
  42. // Service
  43. @objc let serviceShareKeyChain = "Crypto Cloud"
  44. let metadataKeyedUnarchiver = "it.twsweb.nextcloud.metadata"
  45. let refreshTask = "com.nextcloud.refreshTask"
  46. let processingTask = "com.nextcloud.processingTask"
  47. // Nextcloud version
  48. let nextcloudVersion12: Int = 12
  49. let nextcloudVersion15: Int = 15
  50. let nextcloudVersion17: Int = 17
  51. let nextcloudVersion18: Int = 18
  52. let nextcloudVersion20: Int = 20
  53. // Database Realm
  54. let databaseDefault = "nextcloud.realm"
  55. let databaseSchemaVersion: UInt64 = 167
  56. // Intro selector
  57. @objc let introLogin: Int = 0
  58. let introSignup: Int = 1
  59. // Avatar & Preview
  60. let avatarSize: CGFloat = 512
  61. let sizePreview: CGFloat = 1024
  62. let sizeIcon: CGFloat = 512
  63. // E2EE
  64. let e2eeMaxFileSize: UInt64 = 500000000 // 500 MB
  65. let e2eePassphraseTest = "more over television factory tendency independence international intellectual impress interest sentence pony"
  66. @objc let e2eeVersion = "1.1"
  67. // Max Size Upload
  68. let uploadMaxFileSize: UInt64 = 500000000 // 500 MB
  69. // Chunck size MB
  70. let chunckSize: Int64 = 10000000 // 10 MB
  71. // Max Cache Proxy Video
  72. let maxHTTPCache: Int64 = 10000000000 // 10 GB
  73. // NCSharePaging
  74. let indexPageActivity: Int = 0
  75. let indexPageComments: Int = 1
  76. let indexPageSharing: Int = 2
  77. // NCViewerProviderContextMenu
  78. let maxAutoDownload: UInt64 = 100000000 // 100MB
  79. let maxAutoDownloadCellular: UInt64 = 10000000 // 10MB
  80. // Nextcloud unsupported
  81. let nextcloud_unsupported_version: Int = 13
  82. // Layout
  83. let layoutList = "typeLayoutList"
  84. let layoutGrid = "typeLayoutGrid"
  85. let layoutViewMove = "LayoutMove"
  86. let layoutViewTrash = "LayoutTrash"
  87. let layoutViewOffline = "LayoutOffline"
  88. let layoutViewFavorite = "LayoutFavorite"
  89. let layoutViewFiles = "LayoutFiles"
  90. let layoutViewViewInFolder = "ViewInFolder"
  91. let layoutViewTransfers = "LayoutTransfers"
  92. let layoutViewRecent = "LayoutRecent"
  93. let layoutViewShares = "LayoutShares"
  94. // Button Type in Cell list/grid
  95. let buttonMoreMore = "more"
  96. let buttonMoreStop = "stop"
  97. // Text - OnlyOffice - Collabora
  98. let editorText = "text"
  99. let editorOnlyoffice = "onlyoffice"
  100. let editorCollabora = "collabora"
  101. let onlyofficeDocx = "onlyoffice_docx"
  102. let onlyofficeXlsx = "onlyoffice_xlsx"
  103. let onlyofficePptx = "onlyoffice_pptx"
  104. // Template
  105. let templateDocument = "document"
  106. let templateSpreadsheet = "spreadsheet"
  107. let templatePresentation = "presentation"
  108. // Rich Workspace
  109. let fileNameRichWorkspace = "Readme.md"
  110. @objc let dismissAfterSecond: TimeInterval = 4
  111. @objc let dismissAfterSecondLong: TimeInterval = 10
  112. // Error
  113. @objc let ErrorBadRequest: Int = 400
  114. @objc let ErrorResourceNotFound: Int = 404
  115. @objc let ErrorConflict: Int = 409
  116. @objc let ErrorBadServerResponse: Int = -1011
  117. @objc let ErrorInternalError: Int = -99999
  118. @objc let ErrorFileNotSaved: Int = -99998
  119. @objc let ErrorDecodeMetadata: Int = -99997
  120. @objc let ErrorE2EENotEnabled: Int = -99996
  121. @objc let ErrorOffline: Int = -99994
  122. @objc let ErrorCharactersForbidden: Int = -99993
  123. @objc let ErrorCreationFile: Int = -99992
  124. // Constants to identify the different permissions of a file
  125. @objc let permissionShared = "S"
  126. @objc let permissionCanShare = "R"
  127. @objc let permissionMounted = "M"
  128. @objc let permissionFileCanWrite = "W"
  129. @objc let permissionCanCreateFile = "C"
  130. @objc let permissionCanCreateFolder = "K"
  131. @objc let permissionCanDelete = "D"
  132. @objc let permissionCanRename = "N"
  133. @objc let permissionCanMove = "V"
  134. //Share permission
  135. //permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1)
  136. @objc let permissionReadShare: Int = 1
  137. @objc let permissionUpdateShare: Int = 2
  138. @objc let permissionCreateShare: Int = 4
  139. @objc let permissionDeleteShare: Int = 8
  140. @objc let permissionShareShare: Int = 16
  141. @objc let permissionMinFileShare: Int = 1
  142. @objc let permissionMaxFileShare: Int = 19
  143. @objc let permissionMinFolderShare: Int = 1
  144. @objc let permissionMaxFolderShare: Int = 31
  145. @objc let permissionDefaultFileRemoteShareNoSupportShareOption: Int = 3
  146. @objc let permissionDefaultFolderRemoteShareNoSupportShareOption: Int = 15
  147. // Metadata : FileType
  148. @objc let metadataTypeFileAudio = "audio"
  149. @objc let metadataTypeFileCompress = "compress"
  150. @objc let metadataTypeFileDirectory = "directory"
  151. @objc let metadataTypeFileDocument = "document"
  152. @objc let metadataTypeFileImage = "image"
  153. @objc let metadataTypeFileUnknown = "unknow"
  154. @objc let metadataTypeFileVideo = "video"
  155. @objc let metadataTypeFileImagemeter = "imagemeter"
  156. // Filename Mask and Type
  157. let keyFileNameMask = "fileNameMask"
  158. let keyFileNameType = "fileNameType"
  159. let keyFileNameAutoUploadMask = "fileNameAutoUploadMask"
  160. let keyFileNameAutoUploadType = "fileNameAutoUploadType"
  161. let keyFileNameOriginal = "fileNameOriginal"
  162. let keyFileNameOriginalAutoUpload = "fileNameOriginalAutoUpload"
  163. // Selector
  164. let selectorDownloadFile = "downloadFile"
  165. let selectorDownloadAllFile = "downloadAllFile"
  166. let selectorReadFile = "readFile"
  167. let selectorListingFavorite = "listingFavorite"
  168. let selectorLoadFileView = "loadFileView"
  169. let selectorLoadFileQuickLook = "loadFileQuickLook"
  170. let selectorLoadCopy = "loadCopy"
  171. let selectorLoadOffline = "loadOffline"
  172. let selectorOpenIn = "openIn"
  173. let selectorPrint = "print"
  174. let selectorUploadAutoUpload = "uploadAutoUpload"
  175. let selectorUploadAutoUploadAll = "uploadAutoUploadAll"
  176. let selectorUploadFile = "uploadFile"
  177. let selectorSaveAlbum = "saveAlbum"
  178. let selectorSaveAlbumLivePhotoIMG = "saveAlbumLivePhotoIMG"
  179. let selectorSaveAlbumLivePhotoMOV = "saveAlbumLivePhotoMOV"
  180. // Metadata : Status
  181. //
  182. // 1) wait download/upload
  183. // 2) in download/upload
  184. // 3) downloading/uploading
  185. // 4) done or error
  186. //
  187. let metadataStatusNormal: Int = 0
  188. let metadataStatustypeDownload: Int = 1
  189. let metadataStatusWaitDownload: Int = 2
  190. let metadataStatusInDownload: Int = 3
  191. let metadataStatusDownloading: Int = 4
  192. let metadataStatusDownloadError: Int = 5
  193. let metadataStatusTypeUpload: Int = 6
  194. let metadataStatusWaitUpload: Int = 7
  195. let metadataStatusInUpload: Int = 8
  196. let metadataStatusUploading: Int = 9
  197. let metadataStatusUploadError: Int = 10
  198. let metadataStatusUploadForcedStart: Int = 11
  199. // Notification Center
  200. @objc let notificationCenterApplicationDidEnterBackground = "applicationDidEnterBackground"
  201. let notificationCenterApplicationWillEnterForeground = "applicationWillEnterForeground"
  202. let notificationCenterApplicationDidBecomeActive = "applicationDidBecomeActive"
  203. @objc let notificationCenterInitializeMain = "initializeMain"
  204. @objc let notificationCenterChangeTheming = "changeTheming"
  205. let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus"
  206. let notificationCenterReloadDataNCShare = "reloadDataNCShare"
  207. let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView"
  208. let notificationCenterUpdateBadgeNumber = "updateBadgeNumber"
  209. @objc let notificationCenterReloadDataSource = "reloadDataSource" // userInfo: ocId?, serverUrl?
  210. let notificationCenterReloadDataSourceNetworkForced = "reloadDataSourceNetworkForced" // userInfo: serverUrl?
  211. let notificationCenterChangeStatusFolderE2EE = "changeStatusFolderE2EE" // userInfo: serverUrl
  212. let notificationCenterDownloadStartFile = "downloadStartFile" // userInfo: ocId
  213. let notificationCenterDownloadedFile = "downloadedFile" // userInfo: ocId, selector, errorCode, errorDescription
  214. let notificationCenterDownloadCancelFile = "downloadCancelFile" // userInfo: ocId
  215. let notificationCenterUploadStartFile = "uploadStartFile" // userInfo: ocId
  216. @objc let notificationCenterUploadedFile = "uploadedFile" // userInfo: ocId, ocIdTemp, errorCode, errorDescription
  217. let notificationCenterUploadCancelFile = "uploadCancelFile" // userInfo: ocId, serverUrl, account
  218. let notificationCenterProgressTask = "progressTask" // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected
  219. let notificationCenterCreateFolder = "createFolder" // userInfo: ocId
  220. let notificationCenterDeleteFile = "deleteFile" // userInfo: ocId, fileNameView, typeFile, onlyLocal
  221. let notificationCenterRenameFile = "renameFile" // userInfo: ocId, errorCode, errorDescription
  222. let notificationCenterMoveFile = "moveFile" // userInfo: ocId, serverUrlTo
  223. let notificationCenterCopyFile = "copyFile" // userInfo: ocId, serverUrlFrom
  224. let notificationCenterFavoriteFile = "favoriteFile" // userInfo: ocId
  225. let notificationCenterMenuSearchTextPDF = "menuSearchTextPDF"
  226. let notificationCenterMenuDetailClose = "menuDetailClose"
  227. let notificationCenterChangedLocation = "changedLocation"
  228. let notificationStatusAuthorizationChangedLocation = "statusAuthorizationChangedLocation"
  229. }
  230. //let rootView = UIApplication.shared.keyWindow?.rootViewController?.view
  231. //DispatchQueue.main.async
  232. //DispatchQueue.main.asyncAfter(deadline: .now() + 0.1)
  233. //DispatchQueue.global().async
  234. //DispatchQueue.global(qos: .background).async
  235. //#if targetEnvironment(simulator)
  236. //#endif
  237. //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  238. //dispatch_async(dispatch_get_main_queue(), ^{
  239. //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  240. //#if TARGET_OS_SIMULATOR
  241. //#endif