NCGlobal.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 = 162
  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 = 524288000 // 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 = 524288000 // 500 MB
  69. // Max Cache Proxy Video
  70. let maxHTTPCache: Int64 = 10737418240 // 10 GB
  71. // NCSharePaging
  72. let indexPageActivity: Int = 0
  73. let indexPageComments: Int = 1
  74. let indexPageSharing: Int = 2
  75. // NCViewerProviderContextMenu
  76. let maxAutoDownload: UInt64 = 104857600 // 100MB
  77. let maxAutoDownloadCellular: UInt64 = 10485760 // 10MB
  78. // Nextcloud unsupported
  79. let nextcloud_unsupported_version: Int = 13
  80. // Layout
  81. let layoutList = "typeLayoutList"
  82. let layoutGrid = "typeLayoutGrid"
  83. let layoutViewMove = "LayoutMove"
  84. let layoutViewTrash = "LayoutTrash"
  85. let layoutViewOffline = "LayoutOffline"
  86. let layoutViewFavorite = "LayoutFavorite"
  87. let layoutViewFiles = "LayoutFiles"
  88. let layoutViewViewInFolder = "ViewInFolder"
  89. let layoutViewTransfers = "LayoutTransfers"
  90. let layoutViewRecent = "LayoutRecent"
  91. let layoutViewShares = "LayoutShares"
  92. // Button Type in Cell list/grid
  93. let buttonMoreMore = "more"
  94. let buttonMoreStop = "stop"
  95. // Text - OnlyOffice - Collabora
  96. let editorText = "text"
  97. let editorOnlyoffice = "onlyoffice"
  98. let editorCollabora = "collabora"
  99. let onlyofficeDocx = "onlyoffice_docx"
  100. let onlyofficeXlsx = "onlyoffice_xlsx"
  101. let onlyofficePptx = "onlyoffice_pptx"
  102. // Template
  103. let templateDocument = "document"
  104. let templateSpreadsheet = "spreadsheet"
  105. let templatePresentation = "presentation"
  106. // Rich Workspace
  107. let fileNameRichWorkspace = "Readme.md"
  108. @objc let dismissAfterSecond: TimeInterval = 4
  109. @objc let dismissAfterSecondLong: TimeInterval = 10
  110. // Error
  111. @objc let ErrorBadRequest: Int = 400
  112. @objc let ErrorResourceNotFound: Int = 404
  113. @objc let ErrorConflict: Int = 409
  114. @objc let ErrorBadServerResponse: Int = -1011
  115. @objc let ErrorInternalError: Int = -99999
  116. @objc let ErrorFileNotSaved: Int = -99998
  117. @objc let ErrorDecodeMetadata: Int = -99997
  118. @objc let ErrorE2EENotEnabled: Int = -99996
  119. @objc let ErrorOffline: Int = -99994
  120. @objc let ErrorCharactersForbidden: Int = -99993
  121. @objc let ErrorCreationFile: Int = -99992
  122. // Constants to identify the different permissions of a file
  123. @objc let permissionShared = "S"
  124. @objc let permissionCanShare = "R"
  125. @objc let permissionMounted = "M"
  126. @objc let permissionFileCanWrite = "W"
  127. @objc let permissionCanCreateFile = "C"
  128. @objc let permissionCanCreateFolder = "K"
  129. @objc let permissionCanDelete = "D"
  130. @objc let permissionCanRename = "N"
  131. @objc let permissionCanMove = "V"
  132. //Share permission
  133. //permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1)
  134. @objc let permissionReadShare: Int = 1
  135. @objc let permissionUpdateShare: Int = 2
  136. @objc let permissionCreateShare: Int = 4
  137. @objc let permissionDeleteShare: Int = 8
  138. @objc let permissionShareShare: Int = 16
  139. @objc let permissionMinFileShare: Int = 1
  140. @objc let permissionMaxFileShare: Int = 19
  141. @objc let permissionMinFolderShare: Int = 1
  142. @objc let permissionMaxFolderShare: Int = 31
  143. @objc let permissionDefaultFileRemoteShareNoSupportShareOption: Int = 3
  144. @objc let permissionDefaultFolderRemoteShareNoSupportShareOption: Int = 15
  145. // Metadata : FileType
  146. @objc let metadataTypeFileAudio = "audio"
  147. @objc let metadataTypeFileCompress = "compress"
  148. @objc let metadataTypeFileDirectory = "directory"
  149. @objc let metadataTypeFileDocument = "document"
  150. @objc let metadataTypeFileImage = "image"
  151. @objc let metadataTypeFileUnknown = "unknow"
  152. @objc let metadataTypeFileVideo = "video"
  153. @objc let metadataTypeFileImagemeter = "imagemeter"
  154. // Filename Mask and Type
  155. let keyFileNameMask = "fileNameMask"
  156. let keyFileNameType = "fileNameType"
  157. let keyFileNameAutoUploadMask = "fileNameAutoUploadMask"
  158. let keyFileNameAutoUploadType = "fileNameAutoUploadType"
  159. let keyFileNameOriginal = "fileNameOriginal"
  160. let keyFileNameOriginalAutoUpload = "fileNameOriginalAutoUpload"
  161. // Selector
  162. let selectorDownloadFile = "downloadFile"
  163. let selectorDownloadAllFile = "downloadAllFile"
  164. let selectorReadFile = "readFile"
  165. let selectorListingFavorite = "listingFavorite"
  166. let selectorLoadFileView = "loadFileView"
  167. let selectorLoadFileQuickLook = "loadFileQuickLook"
  168. let selectorLoadCopy = "loadCopy"
  169. let selectorLoadOffline = "loadOffline"
  170. let selectorOpenIn = "openIn"
  171. let selectorPrint = "print"
  172. let selectorUploadAutoUpload = "uploadAutoUpload"
  173. let selectorUploadAutoUploadAll = "uploadAutoUploadAll"
  174. let selectorUploadFile = "uploadFile"
  175. let selectorSaveAlbum = "saveAlbum"
  176. let selectorSaveAlbumLivePhotoIMG = "saveAlbumLivePhotoIMG"
  177. let selectorSaveAlbumLivePhotoMOV = "saveAlbumLivePhotoMOV"
  178. // Metadata : Status
  179. //
  180. // 1) wait download/upload
  181. // 2) in download/upload
  182. // 3) downloading/uploading
  183. // 4) done or error
  184. //
  185. let metadataStatusNormal: Int = 0
  186. let metadataStatustypeDownload: Int = 1
  187. let metadataStatusWaitDownload: Int = 2
  188. let metadataStatusInDownload: Int = 3
  189. let metadataStatusDownloading: Int = 4
  190. let metadataStatusDownloadError: Int = 5
  191. let metadataStatusTypeUpload: Int = 6
  192. let metadataStatusWaitUpload: Int = 7
  193. let metadataStatusInUpload: Int = 8
  194. let metadataStatusUploading: Int = 9
  195. let metadataStatusUploadError: Int = 10
  196. let metadataStatusUploadForcedStart: Int = 11
  197. // Notification Center
  198. @objc let notificationCenterApplicationDidEnterBackground = "applicationDidEnterBackground"
  199. let notificationCenterApplicationWillEnterForeground = "applicationWillEnterForeground"
  200. let notificationCenterApplicationDidBecomeActive = "applicationDidBecomeActive"
  201. @objc let notificationCenterInitializeMain = "initializeMain"
  202. @objc let notificationCenterChangeTheming = "changeTheming"
  203. let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus"
  204. let notificationCenterReloadDataNCShare = "reloadDataNCShare"
  205. let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView"
  206. let notificationCenterUpdateBadgeNumber = "updateBadgeNumber"
  207. @objc let notificationCenterReloadDataSource = "reloadDataSource" // userInfo: ocId?, serverUrl?
  208. let notificationCenterReloadDataSourceNetworkForced = "reloadDataSourceNetworkForced" // userInfo: serverUrl?
  209. let notificationCenterChangeStatusFolderE2EE = "changeStatusFolderE2EE" // userInfo: serverUrl
  210. let notificationCenterDownloadStartFile = "downloadStartFile" // userInfo: ocId
  211. let notificationCenterDownloadedFile = "downloadedFile" // userInfo: ocId, selector, errorCode, errorDescription
  212. let notificationCenterDownloadCancelFile = "downloadCancelFile" // userInfo: ocId
  213. let notificationCenterUploadStartFile = "uploadStartFile" // userInfo: ocId
  214. @objc let notificationCenterUploadedFile = "uploadedFile" // userInfo: ocId, ocIdTemp, errorCode, errorDescription
  215. let notificationCenterUploadCancelFile = "uploadCancelFile" // userInfo: ocId
  216. let notificationCenterProgressTask = "progressTask" // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected
  217. let notificationCenterCreateFolder = "createFolder" // userInfo: ocId
  218. let notificationCenterDeleteFile = "deleteFile" // userInfo: ocId, fileNameView, typeFile, onlyLocal
  219. let notificationCenterRenameFile = "renameFile" // userInfo: ocId, errorCode, errorDescription
  220. let notificationCenterMoveFile = "moveFile" // userInfo: ocId, serverUrlTo
  221. let notificationCenterCopyFile = "copyFile" // userInfo: ocId, serverUrlFrom
  222. let notificationCenterFavoriteFile = "favoriteFile" // userInfo: ocId
  223. let notificationCenterMenuSearchTextPDF = "menuSearchTextPDF"
  224. let notificationCenterMenuDetailClose = "menuDetailClose"
  225. let notificationCenterChangedLocation = "changedLocation"
  226. let notificationStatusAuthorizationChangedLocation = "statusAuthorizationChangedLocation"
  227. }
  228. //let rootView = UIApplication.shared.keyWindow?.rootViewController?.view
  229. //DispatchQueue.main.async
  230. //DispatchQueue.main.asyncAfter(deadline: .now() + 0.1)
  231. //DispatchQueue.global().async
  232. //DispatchQueue.global(qos: .background).async
  233. //#if targetEnvironment(simulator)
  234. //#endif
  235. //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  236. //dispatch_async(dispatch_get_main_queue(), ^{
  237. //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  238. //#if TARGET_OS_SIMULATOR
  239. //#endif