NCGlobal.swift 15 KB

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