KMPreferenceManager.swift 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554
  1. //
  2. // KMPreferenceManager.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/2/3.
  6. //
  7. import Cocoa
  8. enum KMPreferenceGroup: String {
  9. case general, display, markup, infomation, other
  10. }
  11. private let KMPreferenceInfoKey: String = "KMPreferenceInfoKey"
  12. typealias KMPreferenceKey = String
  13. /// general
  14. /// files
  15. private let KMOpenLastUnclosedDocumentWhenAppStartKey: KMPreferenceKey = "KMOpenLastUnclosedDocumentWhenAppStartKey"
  16. private let KMOpenLastUnlockedDocumentWhenAppStartKey: KMPreferenceKey = "KMOpenLastUnlockedDocumentWhenAppStartKey"
  17. private let KMDocumentMaximunDisplayNumberKey: KMPreferenceKey = "KMDocumentMaximunDisplayNumberKey"
  18. private let KMAutoSaveKey: KMPreferenceKey = "KMAutoSaveKey"
  19. private let KMAutoSavePerNumberMinuteKey: KMPreferenceKey = "KMAutoSavePerNumberMinuteKey"
  20. private let KMCloseFilePromptTypeKey: KMPreferenceKey = "KMCloseFilePromptTypeKey"
  21. /// open image file
  22. private let KMOpenImageFileTypeKey: KMPreferenceKey = "KMOpenImageFileTypeKey"
  23. private let KMSetDefaultPDFReaderKey: KMPreferenceKey = "KMSetDefaultPDFReaderKey"
  24. /// save password
  25. private let KMSavePasswordTypeKey: KMPreferenceKey = "KMSavePasswordTypeKey"
  26. private let KMGeneralAuthorNameKey: KMPreferenceKey = "KMGeneralAuthorNameKey"
  27. // Tip: 新补充
  28. private let KMOpenDocumentTypeKey: KMPreferenceKey = "KMOpenDocumentTypeKey"
  29. private let KMGeneralShowInMenuBarKey: KMPreferenceKey = "KMGeneralShowInMenuBarKey"
  30. private let KMOpenFileTypeKey: KMPreferenceKey = "KMOpenFileTypeKey"
  31. private let KMShowLeftSideBarKey: KMPreferenceKey = "KMShowLeftSideBarKey"
  32. private let KMRememberSnapshotKey: KMPreferenceKey = "KMRememberSnapshotKey"
  33. private let KMRevertInitPDFViewSettingTypeKey: KMPreferenceKey = "KMRevertInitPDFViewSettingTypeKey"
  34. private let KMAutoSaveNoteBackupKey: KMPreferenceKey = "KMAutoSaveNoteBackupKey"
  35. private let KMKeepSnapshotWindowToTopKey: KMPreferenceKey = "KMKeepSnapshotWindowToTopKey"
  36. /// display
  37. private let KMViewPageDisplayTypeKey: KMPreferenceKey = "KMViewPageDisplayTypeKey"
  38. private let KMViewZoomScaleTypeKey: KMPreferenceKey = "KMViewZoomScaleTypeKey"
  39. private let KMLeftSideDisplayTypeKey: KMPreferenceKey = "KMLeftSideDisplayTypeKey"
  40. private let KMShowOutlineListKey: KMPreferenceKey = "KMShowOutlineListKey"
  41. private let KMLeftSideExpandTypeKey: KMPreferenceKey = "KMLeftSideExpandTypeKey"
  42. private let KMPropertyPanelExpandTypeKey: KMPreferenceKey = "KMPropertyPanelExpandTypeKey"
  43. private let KMDisplayBackgroundNormalColorKey: KMPreferenceKey = "KMDisplayBackgroundNormalColorKey"
  44. private let KMDisplayBackgroundFullScreenColorKey: KMPreferenceKey = "KMDisplayBackgroundFullScreenColorKey"
  45. private let KMHighlightFormsKey: KMPreferenceKey = "KMHighlightFormsKey"
  46. private let KMDisplayFieldHighlightingColorKey: KMPreferenceKey = "KMDisplayFieldHighlightingColorKey"
  47. private let KMDisplayRequiredFieldHighlightingColorKey: KMPreferenceKey = "KMDisplayRequiredFieldHighlightingColorKey"
  48. private let KMPageIndicatorTypeKey: KMPreferenceKey = "KMPageIndicatorTypeKey"
  49. private let KMHighlightLinksKey: KMPreferenceKey = "KMHighlightLinksKey"
  50. // Tip: 新补充
  51. private let KMThumbPageSizeKey: KMPreferenceKey = "KMThumbPageSizeKey"
  52. private let KMThumbSnapshotSizeKey: KMPreferenceKey = "KMThumbSnapshotSizeKey"
  53. private let KMDiscreteSizeKey: KMPreferenceKey = "KMDiscreteSizeKey"
  54. private let KMOutlineFontSizeKey: KMPreferenceKey = "KMOutlineFontSizeKey"
  55. private let KMGreekThresholdKey: KMPreferenceKey = "KMGreekThresholdKey"
  56. private let KMAntiAliasTextKey: KMPreferenceKey = "KMAntiAliasTextKey"
  57. private let KMReadBarColorKey: KMPreferenceKey = "KMReadBarColorKey"
  58. private let KMInvertBarKey: KMPreferenceKey = "KMInvertBarKey"
  59. /// markup
  60. private let KMMarkupColorHighlightKey: KMPreferenceKey = "KMMarkupColorHighlightKey"
  61. private let KMMarkupColorStrikthroughKey: KMPreferenceKey = "KMMarkupColorStrikthroughKey"
  62. private let KMMarkupColorUnderlineKey: KMPreferenceKey = "KMMarkupColorUnderlineKey"
  63. private let KMMarkupColorPenKey: KMPreferenceKey = "KMMarkupColorPenKey"
  64. private let KMMarkupColorTextKey: KMPreferenceKey = "KMMarkupColorTextKey"
  65. private let KMMarkupColorNoteKey: KMPreferenceKey = "KMMarkupColorNoteKey"
  66. private let KMMarkupColorRectangleFillKey: KMPreferenceKey = "KMMarkupColorRectangleFillKey"
  67. private let KMMarkupColorRectangleBorderKey: KMPreferenceKey = "KMMarkupColorRectangleBorderKey"
  68. private let KMMarkupColorCircleFillKey: KMPreferenceKey = "KMMarkupColorCircleFillKey"
  69. private let KMMarkupColorCircleBorderKey: KMPreferenceKey = "KMMarkupColorCircleBorderKey"
  70. private let KMMarkupColorLineKey: KMPreferenceKey = "KMMarkupColorLineKey"
  71. private let KMMarkupColorArrowKey: KMPreferenceKey = "KMMarkupColorArrowKey"
  72. private let KMMarkupFontTextStringKey: KMPreferenceKey = "KMMarkupFontTextStringKey"
  73. private let KMMarkupFontTextAligmentKey: KMPreferenceKey = "KMMarkupFontTextAligmentKey"
  74. private let KMMarkupFontNoteStringKey: KMPreferenceKey = "KMMarkupFontNoteStringKey"
  75. // Tip: 新补充
  76. private let KMMarkupTextFontSizeKey: KMPreferenceKey = "KMMarkupTextFontSizeKey"
  77. private let KMMarkupNoteFontSizeKey: KMPreferenceKey = "KMMarkupNoteFontSizeKey"
  78. /// 偏好设置已改变
  79. private let KMPreferenceDidChangeNotificationName = "KMPreferenceDidChangeNotificationName"
  80. private let KMDefaultFontName = "Helvetica-Oblique"
  81. typealias KMPreference = KMPreferenceManager
  82. @objcMembers class KMPreferenceManager: NSObject {
  83. static let shared = KMPreferenceManager()
  84. private var generalGroupKeys: Array<KMPreferenceKey> = []
  85. private var displayGroupKeys: Array<KMPreferenceKey> = []
  86. private var markupGroupKeys: Array<KMPreferenceKey> = []
  87. public static let didChangeNotification = Notification.Name(KMPreferenceDidChangeNotificationName)
  88. /// general
  89. /// files
  90. public static let openLastUnclosedDocumentWhenAppStartKey = KMOpenLastUnclosedDocumentWhenAppStartKey
  91. public static let openLastUnlockedDocumentWhenAppStartKey = KMOpenLastUnlockedDocumentWhenAppStartKey
  92. public static let documentMaximunDisplayNumberKey = KMDocumentMaximunDisplayNumberKey
  93. public static let autoSaveKey = KMAutoSaveKey
  94. public static let autoSavePerNumberMinuteKey = KMAutoSavePerNumberMinuteKey
  95. public static let closeFilePromptTypeKey = KMCloseFilePromptTypeKey
  96. /// open image file
  97. public static let openImageFileTypeKey = KMOpenImageFileTypeKey
  98. public static let setDefaultPDFReaderKey = KMSetDefaultPDFReaderKey
  99. /// save password
  100. public static let savePasswordTypeKey = KMSavePasswordTypeKey
  101. public static let generalAuthorNameKey = KMGeneralAuthorNameKey
  102. // Tip: 新补充
  103. public static let openDocumentTypeKey = KMOpenDocumentTypeKey
  104. public static let showInMenuBarKey = KMGeneralShowInMenuBarKey
  105. public static let openFileTypeKey = KMOpenFileTypeKey
  106. public static let showLeftSideBarKey = KMShowLeftSideBarKey
  107. public static let rememberSnapshotKey = KMRememberSnapshotKey
  108. public static let revertInitPDFViewSettingTypeKey = KMRevertInitPDFViewSettingTypeKey
  109. public static let autoSaveNoteBackupKey = KMAutoSaveNoteBackupKey
  110. public static let keepSnapshotWindowToTopKey = KMKeepSnapshotWindowToTopKey
  111. /// display
  112. public static let viewPageDisplayTypeKey = KMViewPageDisplayTypeKey
  113. public static let viewZoomScaleTypeKey = KMViewZoomScaleTypeKey
  114. public static let leftSideDisplayTypeKey = KMLeftSideDisplayTypeKey
  115. public static let showOutlineListKey = KMShowOutlineListKey
  116. public static let leftSideExpandTypeKey = KMLeftSideExpandTypeKey
  117. public static let propertyPanelExpandTypeKey = KMPropertyPanelExpandTypeKey
  118. public static let displayBackgroundNormalColorKey = KMDisplayBackgroundNormalColorKey
  119. public static let displayBackgroundFullScreenColorKey = KMDisplayBackgroundFullScreenColorKey
  120. public static let highlightFormsKey = KMHighlightFormsKey
  121. public static let displayFieldHighlightingColorKey = KMDisplayFieldHighlightingColorKey
  122. public static let displayRequiredFieldHighlightingColorKey = KMDisplayRequiredFieldHighlightingColorKey
  123. public static let pageIndicatorTypeKey = KMPageIndicatorTypeKey
  124. public static let highlightLinksKey = KMHighlightLinksKey
  125. // Tip: 新补充
  126. public static let thumbPageSizeKey = KMThumbPageSizeKey
  127. public static let thumbSnapshotSizeKey = KMThumbSnapshotSizeKey
  128. public static let discreteSizeKey = KMDiscreteSizeKey
  129. public static let outlineFontSizeKey = KMOutlineFontSizeKey
  130. public static let greekThresholdKey = KMGreekThresholdKey
  131. public static let antiAliasTextKey = KMAntiAliasTextKey
  132. public static let readBarColorKey = KMReadBarColorKey
  133. public static let invertBarKey = KMInvertBarKey
  134. /// markup
  135. public static let markupColorHighlightKey = KMMarkupColorHighlightKey
  136. public static let markupColorStrikthroughKey = KMMarkupColorStrikthroughKey
  137. public static let markupColorUnderlineKey = KMMarkupColorUnderlineKey
  138. public static let markupColorPenKey = KMMarkupColorPenKey
  139. public static let markupColorTextKey = KMMarkupColorTextKey
  140. public static let markupColorNoteKey = KMMarkupColorNoteKey
  141. public static let markupColorRectangleFillKey = KMMarkupColorRectangleFillKey
  142. public static let markupColorRectangleBorderKey = KMMarkupColorRectangleBorderKey
  143. public static let markupColorCircleFillKey = KMMarkupColorCircleFillKey
  144. public static let markupColorCircleBorderKey = KMMarkupColorCircleBorderKey
  145. public static let markupColorLineKey = KMMarkupColorLineKey
  146. public static let markupColorArrowKey = KMMarkupColorArrowKey
  147. public static let markupFontTextStringKey = KMMarkupFontTextStringKey
  148. public static let markupFontTextAligmentKey = KMMarkupFontTextAligmentKey
  149. public static let markupFontNoteStringKey = KMMarkupFontNoteStringKey
  150. // Tip: - 新补充
  151. public static let markupTextFontSizeKey = KMMarkupTextFontSizeKey
  152. public static let markupNoteFontSizeKey = KMMarkupNoteFontSizeKey
  153. override init() {
  154. super.init()
  155. /// 初始化
  156. generalGroupKeys = self.getDefaultKeys(for: .general)
  157. displayGroupKeys = self.getDefaultKeys(for: .display)
  158. markupGroupKeys = self.getDefaultKeys(for: .markup)
  159. let info = UserDefaults.standard.value(forKey: KMPreferenceInfoKey)
  160. if (info == nil) {
  161. let info = self.getDefaultInfo()
  162. UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
  163. UserDefaults.standard.synchronize()
  164. }
  165. }
  166. // MARK: 保存/获取数据
  167. public func setData(data: Any,forKey key: KMPreferenceKey) -> Bool {
  168. return self.setData(data: data, forKey: key, in: findGroup(forKey: key))
  169. }
  170. public func setData(data: Any,forKey key: KMPreferenceKey, in group: KMPreferenceGroup) -> Bool {
  171. var info: [String : Any]?
  172. if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
  173. info = self.getDefaultInfo()
  174. } else {
  175. info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as! [String : Any])
  176. }
  177. var groupInfo: [String : Any] = info![group.rawValue] as! [String : Any]
  178. groupInfo.updateValue(data, forKey: key)
  179. info?.updateValue(groupInfo, forKey: group.rawValue)
  180. UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
  181. UserDefaults.standard.synchronize()
  182. self.postNotification(object: [group], userInfo: [key : data])
  183. return true
  184. }
  185. public func getData(forKey key: KMPreferenceKey) -> Any {
  186. var info: [String : Any]?
  187. if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
  188. info = self.getDefaultInfo()
  189. } else {
  190. info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as! [String : Any])
  191. }
  192. let groupInfo: [String : Any] = info![findGroup(forKey: key).rawValue] as! [String : Any]
  193. return groupInfo[key] as Any
  194. }
  195. public func resetData(_ group: KMPreferenceGroup) {
  196. var info: [String : Any]?
  197. if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
  198. info = self.getDefaultInfo()
  199. } else {
  200. info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as! [String : Any])
  201. }
  202. let groupInfo = self.getDefaultInfo()[group.rawValue]
  203. info?.updateValue(groupInfo as Any, forKey: group.rawValue)
  204. UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
  205. UserDefaults.standard.synchronize()
  206. self.resetDataToPDFView()
  207. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  208. let info: [String : Any]? = UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]
  209. var groupInfo: [KMPreferenceKey : Any]?
  210. if (info != nil) {
  211. groupInfo = info![group.rawValue] as? [KMPreferenceKey : Any]
  212. }
  213. self.postNotification(object: [group], userInfo: groupInfo != nil ? groupInfo : [:])
  214. }
  215. }
  216. public func resetAllData() {
  217. let info = self.getDefaultInfo()
  218. UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
  219. UserDefaults.standard.synchronize()
  220. self.resetDataToPDFView()
  221. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  222. var groppInfos: [KMPreferenceKey : Any] = [:]
  223. for groupInfo in info.values {
  224. for (key, value) in groupInfo {
  225. groppInfos.updateValue(value, forKey: key)
  226. }
  227. }
  228. self.postNotification(object: [KMPreferenceGroup.general, KMPreferenceGroup.display, KMPreferenceGroup.markup, KMPreferenceGroup.infomation, KMPreferenceGroup.other], userInfo: groppInfos)
  229. }
  230. }
  231. // MARK: 注册 key
  232. public func register(_ key: KMPreferenceKey, to group: KMPreferenceGroup) -> Bool {
  233. if (group == .general) {
  234. if (self.generalGroupKeys.contains(key)) {
  235. return false
  236. }
  237. self.generalGroupKeys.append(key)
  238. }
  239. return true
  240. }
  241. // MARK: -
  242. // MARK: 发布通知
  243. private func postNotification(object: [KMPreferenceGroup]?, userInfo: [KMPreferenceKey : Any]?) {
  244. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
  245. NotificationCenter.default.post(name: KMPreferenceManager.didChangeNotification, object: object, userInfo: userInfo)
  246. }
  247. }
  248. // MARK: 获取信息
  249. private func findGroup(forKey key: KMPreferenceKey) -> KMPreferenceGroup {
  250. if (self.generalGroupKeys.contains(key)) {
  251. return .general
  252. } else if (self.displayGroupKeys.contains(key)) {
  253. return .display
  254. } else if (self.markupGroupKeys.contains(key)) {
  255. return .markup
  256. }
  257. return .other
  258. }
  259. private func getDefaultKeys(for group: KMPreferenceGroup) -> Array<KMPreferenceKey> {
  260. if (group == .general) {
  261. return [KMOpenLastUnclosedDocumentWhenAppStartKey,
  262. KMOpenLastUnlockedDocumentWhenAppStartKey,
  263. KMDocumentMaximunDisplayNumberKey,
  264. KMAutoSaveKey,
  265. KMAutoSavePerNumberMinuteKey,
  266. KMCloseFilePromptTypeKey,
  267. KMOpenImageFileTypeKey,
  268. KMSetDefaultPDFReaderKey,
  269. KMSavePasswordTypeKey,
  270. KMGeneralAuthorNameKey,
  271. // Tip: 新补充
  272. KMOpenDocumentTypeKey, KMGeneralShowInMenuBarKey, KMOpenFileTypeKey, KMShowLeftSideBarKey,
  273. KMRememberSnapshotKey, KMRevertInitPDFViewSettingTypeKey, KMAutoSaveNoteBackupKey, KMKeepSnapshotWindowToTopKey]
  274. } else if (group == .display) {
  275. return [KMViewPageDisplayTypeKey,
  276. KMViewZoomScaleTypeKey,
  277. KMLeftSideDisplayTypeKey,
  278. KMShowOutlineListKey,
  279. KMLeftSideExpandTypeKey,
  280. KMPropertyPanelExpandTypeKey,
  281. KMDisplayBackgroundNormalColorKey,
  282. KMDisplayBackgroundFullScreenColorKey,
  283. KMHighlightFormsKey,
  284. KMDisplayFieldHighlightingColorKey,
  285. KMDisplayRequiredFieldHighlightingColorKey,
  286. KMPageIndicatorTypeKey,
  287. KMHighlightLinksKey,
  288. // Tip: 新补充
  289. KMThumbPageSizeKey, KMThumbSnapshotSizeKey, KMDiscreteSizeKey, KMOutlineFontSizeKey,
  290. KMGreekThresholdKey, KMAntiAliasTextKey, KMReadBarColorKey, KMInvertBarKey]
  291. } else if (group == .markup) {
  292. return [KMMarkupColorHighlightKey,
  293. KMMarkupColorUnderlineKey,
  294. KMMarkupColorStrikthroughKey,
  295. KMMarkupColorPenKey,
  296. KMMarkupColorLineKey,
  297. KMMarkupColorArrowKey,
  298. KMMarkupColorNoteKey,
  299. KMMarkupColorTextKey,
  300. KMMarkupColorCircleFillKey,
  301. KMMarkupColorCircleBorderKey,
  302. KMMarkupColorRectangleFillKey,
  303. KMMarkupColorRectangleBorderKey,
  304. KMMarkupFontTextStringKey,
  305. KMMarkupFontTextAligmentKey,
  306. KMMarkupFontNoteStringKey,
  307. // 新补充
  308. KMMarkupTextFontSizeKey, KMMarkupNoteFontSizeKey]
  309. }
  310. return []
  311. }
  312. private func getDefaultInfo() -> Dictionary<String, Dictionary<String, Any>> {
  313. return [KMPreferenceGroup.general.rawValue : [KMOpenLastUnclosedDocumentWhenAppStartKey : false,
  314. KMOpenLastUnlockedDocumentWhenAppStartKey : true,
  315. KMDocumentMaximunDisplayNumberKey : 10,
  316. KMAutoSaveKey : true,
  317. KMAutoSavePerNumberMinuteKey : 5,
  318. KMCloseFilePromptTypeKey : 0,
  319. KMOpenImageFileTypeKey : 0,
  320. KMSetDefaultPDFReaderKey : true,
  321. KMSavePasswordTypeKey : 2,
  322. KMGeneralAuthorNameKey : NSFullUserName(),
  323. // Tip: 新补充
  324. KMOpenDocumentTypeKey : self.openDocumentTypeDefaultValue.rawValue,
  325. KMGeneralShowInMenuBarKey : self.showInMenuBarDefaultValue,
  326. KMOpenFileTypeKey : self.openFileTypeDefaultValue.rawValue,
  327. KMShowLeftSideBarKey : self.showLeftSideBarDefaultValue,
  328. KMRememberSnapshotKey : self.rememberSnapshotDefaultValue,
  329. KMRevertInitPDFViewSettingTypeKey : self.revertInitPDFViewSettingTypeDefaultValue.rawValue,
  330. KMAutoSaveNoteBackupKey : self.autoSaveNoteBackupDefaultValue,
  331. KMKeepSnapshotWindowToTopKey : self.keepSnapshotWindowToTopDefaultValue()],
  332. KMPreferenceGroup.display.rawValue : [KMViewPageDisplayTypeKey : 1,
  333. KMViewZoomScaleTypeKey : 0,
  334. KMLeftSideDisplayTypeKey : 0,
  335. KMShowOutlineListKey: true,
  336. KMLeftSideExpandTypeKey : 0,
  337. KMPropertyPanelExpandTypeKey : 0,
  338. KMDisplayBackgroundNormalColorKey : self.displayBackgroundNormalColorValues,
  339. KMDisplayBackgroundFullScreenColorKey : self.displayBackgroundFullScreenColorValues,
  340. KMHighlightFormsKey : true,
  341. KMDisplayFieldHighlightingColorKey : self.displayFieldHighlightingColorValues,
  342. KMDisplayRequiredFieldHighlightingColorKey : self.displayRequiredFieldHighlightingColorValues,
  343. KMPageIndicatorTypeKey : 0,
  344. KMHighlightLinksKey : true,
  345. // Tip: 新补充
  346. KMThumbPageSizeKey : self.thumbPageSizeDefaultValue(),
  347. KMThumbSnapshotSizeKey : self.thumbSnapshotSizeDefaultValue(),
  348. KMDiscreteSizeKey : self.discreteSizeDefaultValue(),
  349. KMOutlineFontSizeKey : self.outlineFontSizeDefaultValue(),
  350. KMGreekThresholdKey : self.greekThresholdDefaultValue(),
  351. KMAntiAliasTextKey : self.antiAliasTextDefaultValue(),
  352. KMReadBarColorKey : self.readBarColorValues,
  353. KMInvertBarKey : self.invertBarDefaultValue()],
  354. KMPreferenceGroup.markup.rawValue : [KMMarkupColorHighlightKey : self.markupHighlightColorValues,
  355. KMMarkupColorStrikthroughKey : self.markupStrikthroughColorValues,
  356. KMMarkupColorUnderlineKey : self.markupUnderlineColorValues,
  357. KMMarkupColorPenKey : self.markupPenColorValues,
  358. KMMarkupColorTextKey : self.markupTextColorValues,
  359. KMMarkupColorNoteKey : self.markupNoteColorValues,
  360. KMMarkupColorRectangleFillKey : self.markupRectangleFillColorValues,
  361. KMMarkupColorRectangleBorderKey : self.markupRectangleBorderColorValues,
  362. KMMarkupColorCircleFillKey : self.markupCircleFillColorValues,
  363. KMMarkupColorCircleBorderKey : self.markupCircleBorderColorValues,
  364. KMMarkupColorLineKey : self.markupLineColorValues,
  365. KMMarkupColorArrowKey : self.markupArrowColorValues,
  366. KMMarkupFontTextStringKey : KMDefaultFontName,
  367. KMMarkupFontTextAligmentKey : 0,
  368. KMMarkupFontNoteStringKey : KMDefaultFontName,
  369. // 新补充
  370. KMMarkupTextFontSizeKey : self.textFontSizeDefaultValue(),
  371. KMMarkupNoteFontSizeKey : self.noteFontSizeDefaultValue()],
  372. KMPreferenceGroup.infomation.rawValue : [:],
  373. KMPreferenceGroup.other.rawValue : [:]]
  374. }
  375. }
  376. // MARK: - 默认值
  377. extension KMPreferenceManager {
  378. // General
  379. var openDocumentTypeDefaultValue: KMPreferenceOpenDocumentType {
  380. get {
  381. return .inSameWindow
  382. }
  383. }
  384. var showInMenuBarDefaultValue: Bool {
  385. get {
  386. return false
  387. }
  388. }
  389. var openFileTypeDefaultValue: KMPreferenceOpenFileType {
  390. get {
  391. return .default
  392. }
  393. }
  394. var showLeftSideBarDefaultValue: Bool {
  395. get {
  396. return true
  397. }
  398. }
  399. var rememberSnapshotDefaultValue: Bool {
  400. get {
  401. return true
  402. }
  403. }
  404. var revertInitPDFViewSettingTypeDefaultValue: KMPreferenceRevertInitSettingType {
  405. get {
  406. return .normal
  407. }
  408. }
  409. var autoSaveNoteBackupDefaultValue: Bool {
  410. get {
  411. return false
  412. }
  413. }
  414. // 内联函数
  415. @inline (__always) func keepSnapshotWindowToTopDefaultValue() -> Bool {
  416. return true
  417. }
  418. // Display
  419. @inline (__always) func thumbPageSizeDefaultValue() -> Float {
  420. return 128
  421. }
  422. @inline (__always) func thumbSnapshotSizeDefaultValue() -> Float {
  423. return 128
  424. }
  425. @inline (__always) func discreteSizeDefaultValue() -> Bool {
  426. return false
  427. }
  428. @inline (__always) func outlineFontSizeDefaultValue() -> Float {
  429. return 12
  430. }
  431. @inline (__always) func greekThresholdDefaultValue() -> Float {
  432. return 3
  433. }
  434. @inline (__always) func antiAliasTextDefaultValue() -> Bool {
  435. return true
  436. }
  437. // @inline (__always) func readBarColorDefaultValue() -> Float {
  438. // return 0
  439. // }
  440. @inline (__always) func invertBarDefaultValue() -> Bool {
  441. return false
  442. }
  443. @inline (__always) func textFontSizeDefaultValue() -> Float {
  444. return 11.0
  445. }
  446. @inline (__always) func noteFontSizeDefaultValue() -> Float {
  447. return 12.0
  448. }
  449. }
  450. //protocol KMPreferenceManagerColorPart: NSObjectProtocol {
  451. // var markupHighlightColorValues: [Double] { get }
  452. //}
  453. // MARK: - 扩展 颜色
  454. extension KMPreferenceManager {
  455. fileprivate var displayBackgroundNormalColorValues: [Double] {
  456. get {
  457. return [206/255.0, 208/255.0, 212/255.0, 1.0]
  458. }
  459. }
  460. fileprivate var displayBackgroundFullScreenColorValues: [Double] {
  461. get {
  462. return [54/255.0, 56/255.0, 59/255.0, 1.0]
  463. }
  464. }
  465. fileprivate var displayFieldHighlightingColorValues: [Double] {
  466. get {
  467. return [189/255.0, 223/255.0, 253/255.0, 1.0]
  468. }
  469. }
  470. fileprivate var displayRequiredFieldHighlightingColorValues: [Double] {
  471. get {
  472. return [23/255.0, 112/255.0, 224/255.0, 1.0]
  473. }
  474. }
  475. fileprivate var markupHighlightColorValues: [Double] {
  476. get {
  477. return [255/255.0, 199/255.0, 0.0, 1.0]
  478. }
  479. }
  480. fileprivate var markupStrikthroughColorValues: [Double] {
  481. get {
  482. return [252/255.0, 31/255.0, 31/255.0, 1.0]
  483. }
  484. }
  485. fileprivate var markupUnderlineColorValues: [Double] {
  486. get {
  487. return [30/255.0, 137/255.0, 86/255.0, 1.0]
  488. }
  489. }
  490. fileprivate var markupPenColorValues: [Double] {
  491. get {
  492. self.markupStrikthroughColorValues
  493. }
  494. }
  495. fileprivate var markupTextColorValues: [Double] {
  496. get {
  497. return [37/255.0, 38/255.0, 41/255.0, 1.0]
  498. }
  499. }
  500. fileprivate var markupNoteColorValues: [Double] {
  501. get {
  502. return [255/255.0, 213/255.0, 115/255.0, 1.0]
  503. }
  504. }
  505. fileprivate var markupRectangleFillColorValues: [Double] {
  506. get {
  507. return [0/255.0, 0/255.0, 0/255.0, 0.0]
  508. }
  509. }
  510. fileprivate var markupRectangleBorderColorValues: [Double] {
  511. get {
  512. self.markupStrikthroughColorValues
  513. }
  514. }
  515. fileprivate var markupCircleFillColorValues: [Double] {
  516. get {
  517. self.markupRectangleFillColorValues
  518. }
  519. }
  520. fileprivate var markupCircleBorderColorValues: [Double] {
  521. get {
  522. return self.markupRectangleBorderColorValues
  523. }
  524. }
  525. fileprivate var markupLineColorValues: [Double] {
  526. get {
  527. self.markupStrikthroughColorValues
  528. }
  529. }
  530. fileprivate var markupArrowColorValues: [Double] {
  531. get {
  532. self.markupStrikthroughColorValues
  533. }
  534. }
  535. fileprivate var readBarColorValues: [Double] {
  536. get {
  537. return [23/255.0, 112/255.0, 224/255.0, 1.0]
  538. }
  539. }
  540. private func setColor(_ color: NSColor, forKey key: KMPreferenceKey) -> Bool {
  541. var red: CGFloat = 0.0
  542. var green: CGFloat = 0.0
  543. var blue: CGFloat = 0.0
  544. var alpha: CGFloat = 0.0
  545. color.usingColorSpaceName(.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
  546. return KMPreferenceManager.shared.setData(data: [red, green, blue, alpha], forKey: key)
  547. }
  548. private func getColor(forKey key: KMPreferenceKey) -> NSColor {
  549. var colors: [Double]? = self.getData(forKey: key) as? [Double]
  550. if (colors == nil) {
  551. colors = self.getDefaultColors(forKey: key)
  552. }
  553. return NSColor(red: colors![0], green: colors![1], blue: colors![2], alpha: colors![3])
  554. }
  555. private func dataToColor(colors:[Double]) -> NSColor {
  556. NSColor(red: colors[0], green: colors[1], blue: colors[2], alpha: colors[3])
  557. }
  558. }
  559. // MARK: 扩展 General
  560. extension KMPreferenceManager {
  561. var openLastUnclosedDocumentWhenAppStart: Bool { // SKReopenLastOpenFilesKey
  562. get {
  563. return self.getData(forKey: KMOpenLastUnclosedDocumentWhenAppStartKey) as! Bool
  564. }
  565. set {
  566. let _ = self.setData(data: newValue, forKey: KMOpenLastUnclosedDocumentWhenAppStartKey)
  567. }
  568. }
  569. var openLastUnlockedDocumentWhenAppStart: Bool {
  570. get {
  571. return self.getData(forKey: KMOpenLastUnlockedDocumentWhenAppStartKey) as! Bool
  572. }
  573. set {
  574. let _ = self.setData(data: newValue, forKey: KMOpenLastUnlockedDocumentWhenAppStartKey)
  575. }
  576. }
  577. var documentMaximunDisplayNumber: Int {
  578. get {
  579. return self.getData(forKey: KMDocumentMaximunDisplayNumberKey) as! Int
  580. }
  581. set {
  582. let _ = self.setData(data: newValue, forKey: KMDocumentMaximunDisplayNumberKey)
  583. }
  584. }
  585. var autoSave: Bool {
  586. get {
  587. return self.getData(forKey: KMAutoSaveKey) as! Bool
  588. }
  589. set {
  590. let _ = self.setData(data: newValue, forKey: KMAutoSaveKey)
  591. }
  592. }
  593. var autoSavePerNumberMinute: Int {
  594. get {
  595. return self.getData(forKey: KMAutoSavePerNumberMinuteKey) as! Int
  596. }
  597. set {
  598. let _ = self.setData(data: newValue, forKey: KMAutoSavePerNumberMinuteKey)
  599. }
  600. }
  601. var closeFilePromptType: KMPreferenceCloseFilePromptType {
  602. get {
  603. let type: Int? = self.getData(forKey: KMCloseFilePromptTypeKey) as? Int
  604. if (type != nil && type! == 1) { // 无提示,直接保存
  605. return .noPromp
  606. }
  607. return .promp
  608. }
  609. set {
  610. if (newValue == .promp || newValue == .noPromp) {
  611. let _ = self.setData(data: newValue.rawValue, forKey: KMCloseFilePromptTypeKey)
  612. }
  613. }
  614. }
  615. var openImageFileType: Int {
  616. get {
  617. return self.getData(forKey: KMOpenImageFileTypeKey) as! Int
  618. }
  619. set {
  620. let _ = self.setData(data: newValue, forKey: KMOpenImageFileTypeKey)
  621. }
  622. }
  623. var author: String {
  624. get {
  625. return self.getData(forKey: KMGeneralAuthorNameKey) as! String
  626. }
  627. set {
  628. let _ = self.setData(data: newValue, forKey: KMGeneralAuthorNameKey)
  629. }
  630. }
  631. var setDefaultPDFReader: Bool {
  632. get {
  633. return self.getData(forKey: KMSetDefaultPDFReaderKey) as! Bool
  634. }
  635. set {
  636. let result = KMTools.setDefaultPDFReader(newValue)
  637. if (result) {
  638. let _ = self.setData(data: newValue, forKey: KMSetDefaultPDFReaderKey)
  639. }
  640. }
  641. }
  642. var savePasswordType: KMPreferenceSavePasswordType {
  643. get {
  644. let type: Int? = self.getData(forKey: KMSavePasswordTypeKey) as? Int
  645. if (type == nil || type! == 2) {
  646. return .ask
  647. }
  648. if (type! == 0) {
  649. return .always
  650. } else if (type! == 1) {
  651. return .never
  652. }
  653. return .ask
  654. }
  655. set {
  656. if (newValue == .always || newValue == .never || newValue == .ask) {
  657. let _ = self.setData(data: newValue.rawValue, forKey: KMSavePasswordTypeKey)
  658. }
  659. }
  660. }
  661. var openDocumentType: KMPreferenceOpenDocumentType { // KMOpenDocumentInTab
  662. get {
  663. guard let type = self.getData(forKey: KMOpenDocumentTypeKey) as? Int else {
  664. return self.openDocumentTypeDefaultValue
  665. }
  666. if type == 1 {
  667. return .newWindow
  668. }
  669. return .inSameWindow
  670. }
  671. set {
  672. if (newValue == .inSameWindow || newValue == .newWindow) {
  673. let _ = self.setData(data: newValue.rawValue, forKey: KMOpenDocumentTypeKey)
  674. }
  675. }
  676. }
  677. var showInMenuBar: Bool {
  678. get {
  679. return self.getData(forKey: KMGeneralShowInMenuBarKey) as? Bool ?? self.showInMenuBarDefaultValue
  680. }
  681. set {
  682. _ = self.setData(data: newValue, forKey: KMGeneralShowInMenuBarKey)
  683. }
  684. }
  685. var openFileType: KMPreferenceOpenFileType {
  686. get {
  687. guard let type = self.getData(forKey: KMOpenFileTypeKey) as? Int else {
  688. return .default
  689. }
  690. if type == 1 {
  691. return .maxim
  692. } else if type == 2 {
  693. return .fit
  694. }
  695. return .default
  696. }
  697. set {
  698. if (newValue == .default || newValue == .maxim || newValue == .fit) {
  699. let _ = self.setData(data: newValue.rawValue, forKey: KMOpenFileTypeKey)
  700. }
  701. }
  702. }
  703. var showLeftSideBar: Bool {
  704. get {
  705. return self.getData(forKey: KMShowLeftSideBarKey) as? Bool ?? self.showLeftSideBarDefaultValue
  706. }
  707. set {
  708. _ = self.setData(data: newValue, forKey: KMShowLeftSideBarKey)
  709. }
  710. }
  711. var rememberSnapshot: Bool {
  712. get {
  713. return self.getData(forKey: KMRememberSnapshotKey) as? Bool ?? self.rememberSnapshotDefaultValue
  714. }
  715. set {
  716. _ = self.setData(data: newValue, forKey: KMRememberSnapshotKey)
  717. }
  718. }
  719. var revertInitPDFViewSettingType: KMPreferenceRevertInitSettingType {
  720. get {
  721. guard let type = self.getData(forKey: KMRevertInitPDFViewSettingTypeKey) as? Int else {
  722. return self.revertInitPDFViewSettingTypeDefaultValue
  723. }
  724. if type == 1 {
  725. return .fullScreen
  726. }
  727. return .normal
  728. }
  729. set {
  730. if (newValue == .normal || newValue == .fullScreen) {
  731. let _ = self.setData(data: newValue.rawValue, forKey: KMRevertInitPDFViewSettingTypeKey)
  732. }
  733. }
  734. }
  735. var autoSaveNoteBackup: Bool {
  736. get {
  737. return self.getData(forKey: KMAutoSaveNoteBackupKey) as? Bool ?? self.autoSaveNoteBackupDefaultValue
  738. }
  739. set {
  740. _ = self.setData(data: newValue, forKey: KMAutoSaveNoteBackupKey)
  741. }
  742. }
  743. var keepSnapshotWindowToTop: Bool {
  744. get {
  745. return self.getData(forKey: KMKeepSnapshotWindowToTopKey) as? Bool ?? self.keepSnapshotWindowToTopDefaultValue()
  746. }
  747. set {
  748. _ = self.setData(data: newValue, forKey: KMKeepSnapshotWindowToTopKey)
  749. }
  750. }
  751. }
  752. // MARK: 扩展 Display
  753. extension KMPreferenceManager {
  754. var viewPageDisplayType: KMPDFDisplayType {
  755. get {
  756. let type: Int? = self.getData(forKey: KMViewPageDisplayTypeKey) as? Int
  757. if (type == nil || type == 1) {
  758. return .singlePageContinuous
  759. }
  760. if (type! == 0) {
  761. return .singlePage
  762. } else if (type! == 2) {
  763. return .twoUp
  764. } else if (type! == 3) {
  765. return .twoUpContinuous
  766. } else if (type! == 4) {
  767. return .bookMode
  768. } else if (type! == 5) {
  769. return .bookContinuous
  770. }
  771. return .singlePageContinuous
  772. }
  773. set {
  774. if (newValue == .singlePage || newValue == .singlePageContinuous || newValue == .twoUp ||
  775. newValue == .twoUpContinuous || newValue == .bookMode || newValue == .bookContinuous) {
  776. let _ = self.setData(data: newValue.rawValue, forKey: KMViewPageDisplayTypeKey)
  777. }
  778. }
  779. }
  780. var viewZoomScaleType: KMPDFZoomType {
  781. get {
  782. let type: Int? = self.getData(forKey: KMViewZoomScaleTypeKey) as? Int
  783. if (type == nil || type! == 0) {
  784. return .width
  785. } else if (type! == 1) {
  786. return .fit
  787. } else if (type! == 2) {
  788. return .actualSize
  789. }
  790. return .width
  791. }
  792. set {
  793. if (newValue == .width || newValue == .fit || newValue == .actualSize) {
  794. let _ = self.setData(data: newValue.rawValue, forKey: KMViewZoomScaleTypeKey)
  795. }
  796. }
  797. }
  798. var leftSideDisplayType: KMPreferenceLeftSideDisplayType {
  799. get {
  800. let type: Int? = self.getData(forKey: KMLeftSideDisplayTypeKey) as? Int
  801. if (type == nil || type! == 0) {
  802. return .closeWhenOpenFile
  803. } else if (type! == 1) {
  804. return .openAppSaveLastSelect
  805. } else if (type! == 2) {
  806. return .showOutlineIfHas
  807. }
  808. return .closeWhenOpenFile
  809. }
  810. set {
  811. if (newValue == .closeWhenOpenFile || newValue == .openAppSaveLastSelect || newValue == .showOutlineIfHas) {
  812. let _ = self.setData(data: newValue.rawValue, forKey: KMLeftSideDisplayTypeKey)
  813. }
  814. }
  815. }
  816. // var showOutlineList: Bool {
  817. // get {
  818. // return self.getData(forKey: KMShowOutlineListKey) as! Bool
  819. // }
  820. // set {
  821. // let _ = self.setData(data: newValue, forKey: KMShowOutlineListKey)
  822. // }
  823. // }
  824. // var leftSideExpandType: Int {
  825. // get {
  826. // return self.getData(forKey: KMLeftSideExpandTypeKey) as! Int
  827. // }
  828. // set {
  829. // let _ = self.setData(data: newValue, forKey: KMLeftSideExpandTypeKey)
  830. // }
  831. // }
  832. var propertyPanelExpandType: KMPreferencePropertyPanelExpandType {
  833. get {
  834. let type: Int? = self.getData(forKey: KMPropertyPanelExpandTypeKey) as? Int
  835. if (type == nil || type! == 0) {
  836. return .auto
  837. } else if (type! == 1) {
  838. return .manual
  839. }
  840. return .auto
  841. }
  842. set {
  843. if (newValue == .auto || newValue == .manual) {
  844. let _ = self.setData(data: newValue.rawValue, forKey: KMPropertyPanelExpandTypeKey)
  845. }
  846. }
  847. }
  848. var highlightForms: Bool {
  849. get {
  850. return self.getData(forKey: KMHighlightFormsKey) as! Bool
  851. }
  852. set {
  853. let _ = self.setData(data: newValue, forKey: KMHighlightFormsKey)
  854. }
  855. }
  856. var pageIndicatorType: KMPreferencePageIndicatorDisplayType {
  857. get {
  858. let type: Int? = self.getData(forKey: KMPageIndicatorTypeKey) as? Int
  859. if (type == nil || type! == 2) {
  860. return .never
  861. } else if (type! == 0) {
  862. return .automatic
  863. } else if (type! == 1) {
  864. return .always
  865. }
  866. return .never
  867. }
  868. set {
  869. if (newValue == .automatic || newValue == .always || newValue == .never) {
  870. let _ = self.setData(data: newValue.rawValue, forKey: KMPageIndicatorTypeKey)
  871. }
  872. }
  873. }
  874. var highlightLinks: Bool {
  875. get {
  876. return self.getData(forKey: KMHighlightLinksKey) as! Bool
  877. }
  878. set {
  879. let _ = self.setData(data: newValue, forKey: KMHighlightLinksKey)
  880. }
  881. }
  882. var displayBackgroundNormalColor: NSColor {
  883. get {
  884. return self.getColor(forKey: KMDisplayBackgroundNormalColorKey)
  885. }
  886. set {
  887. let _ = self.setColor(newValue, forKey: KMDisplayBackgroundNormalColorKey)
  888. }
  889. }
  890. var displayBackgroundFullScreenColor: NSColor {
  891. get {
  892. return self.getColor(forKey: KMDisplayBackgroundFullScreenColorKey)
  893. }
  894. set {
  895. let _ = self.setColor(newValue, forKey: KMDisplayBackgroundFullScreenColorKey)
  896. }
  897. }
  898. var displayFieldHighlightingColor: NSColor {
  899. get {
  900. return self.getColor(forKey: KMDisplayFieldHighlightingColorKey)
  901. }
  902. set {
  903. let _ = self.setColor(newValue, forKey: KMDisplayFieldHighlightingColorKey)
  904. }
  905. }
  906. var displayRequiredFieldHighlightingColor: NSColor {
  907. get {
  908. return self.getColor(forKey: KMDisplayRequiredFieldHighlightingColorKey)
  909. }
  910. set {
  911. let _ = self.setColor(newValue, forKey: KMDisplayRequiredFieldHighlightingColorKey)
  912. }
  913. }
  914. // Tip: 新补充
  915. var thumbPageSize: Float { // SKThumbnailSize
  916. get {
  917. return self.getData(forKey: KMThumbPageSizeKey) as? Float ?? self.thumbPageSizeDefaultValue()
  918. }
  919. set {
  920. let _ = self.setData(data: newValue, forKey: KMThumbPageSizeKey)
  921. }
  922. }
  923. var thumbSnapshotSize: Float { // SKSnapshotThumbnailSize
  924. get {
  925. return self.getData(forKey: KMThumbSnapshotSizeKey) as? Float ?? self.thumbSnapshotSizeDefaultValue()
  926. }
  927. set {
  928. let _ = self.setData(data: newValue, forKey: KMThumbSnapshotSizeKey)
  929. }
  930. }
  931. var discreteSize: Bool {
  932. get {
  933. return self.getData(forKey: KMDiscreteSizeKey) as? Bool ?? self.discreteSizeDefaultValue()
  934. }
  935. set {
  936. let _ = self.setData(data: newValue, forKey: KMDiscreteSizeKey)
  937. }
  938. }
  939. var outlineFontSize: Float { // SKTableFontSize
  940. get {
  941. return self.getData(forKey: KMOutlineFontSizeKey) as? Float ?? self.outlineFontSizeDefaultValue()
  942. }
  943. set {
  944. let _ = self.setData(data: newValue, forKey: KMOutlineFontSizeKey)
  945. }
  946. }
  947. var greekThreshold: Float { // SKGreekingThreshold
  948. get {
  949. return self.getData(forKey: KMGreekThresholdKey) as? Float ?? self.greekThresholdDefaultValue()
  950. }
  951. set {
  952. let _ = self.setData(data: newValue, forKey: KMGreekThresholdKey)
  953. }
  954. }
  955. var antiAliasText: Bool {
  956. get {
  957. return self.getData(forKey: KMAntiAliasTextKey) as? Bool ?? self.antiAliasTextDefaultValue()
  958. }
  959. set {
  960. let _ = self.setData(data: newValue, forKey: KMAntiAliasTextKey)
  961. }
  962. }
  963. var readBarColor: NSColor {
  964. get {
  965. return self.getColor(forKey: KMReadBarColorKey)
  966. }
  967. set {
  968. let _ = self.setColor(newValue, forKey: KMReadBarColorKey)
  969. }
  970. }
  971. var invertBar: Bool {
  972. get {
  973. return self.getData(forKey: KMInvertBarKey) as? Bool ?? self.invertBarDefaultValue()
  974. }
  975. set {
  976. let _ = self.setData(data: newValue, forKey: KMInvertBarKey)
  977. }
  978. }
  979. }
  980. // MARK: 扩展 Markup
  981. extension KMPreferenceManager {
  982. var markupHighlightColor: NSColor {
  983. get {
  984. return self.getColor(forKey: KMPreference.markupColorHighlightKey)
  985. }
  986. set {
  987. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorHighlightKey)
  988. let _ = self.setColor(newValue, forKey: KMPreference.markupColorHighlightKey)
  989. }
  990. }
  991. var markupStrikthroughColor: NSColor {
  992. get {
  993. return self.getColor(forKey: KMPreference.markupColorStrikthroughKey)
  994. }
  995. set {
  996. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorStrikthroughKey)
  997. let _ = self.setColor(newValue, forKey: KMPreference.markupColorStrikthroughKey)
  998. }
  999. }
  1000. var markupUnderlineColor: NSColor {
  1001. get {
  1002. return self.getColor(forKey: KMPreference.markupColorUnderlineKey)
  1003. }
  1004. set {
  1005. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorUnderlineKey)
  1006. let _ = self.setColor(newValue, forKey: KMPreference.markupColorUnderlineKey)
  1007. }
  1008. }
  1009. var markupPenColor: NSColor {
  1010. get {
  1011. return self.getColor(forKey: KMPreference.markupColorPenKey)
  1012. }
  1013. set {
  1014. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorPenKey)
  1015. let _ = self.setColor(newValue, forKey: KMPreference.markupColorPenKey)
  1016. }
  1017. }
  1018. var markupTextColor: NSColor {
  1019. get {
  1020. return self.getColor(forKey: KMPreference.markupColorTextKey)
  1021. }
  1022. set {
  1023. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorTextKey)
  1024. let _ = self.setColor(newValue, forKey: KMPreference.markupColorTextKey)
  1025. }
  1026. }
  1027. var markupNoteColor: NSColor {
  1028. get {
  1029. return self.getColor(forKey: KMPreference.markupColorNoteKey)
  1030. }
  1031. set {
  1032. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorNoteKey)
  1033. let _ = self.setColor(newValue, forKey: KMPreference.markupColorNoteKey)
  1034. }
  1035. }
  1036. var markupRectangleFillColor: NSColor {
  1037. get {
  1038. return self.getColor(forKey: KMPreference.markupColorRectangleFillKey)
  1039. }
  1040. set {
  1041. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorRectangleFillKey)
  1042. let _ = self.setColor(newValue, forKey: KMPreference.markupColorRectangleFillKey)
  1043. }
  1044. }
  1045. var markupRectangleBorderColor: NSColor {
  1046. get {
  1047. return self.getColor(forKey: KMPreference.markupColorRectangleBorderKey)
  1048. }
  1049. set {
  1050. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorRectangleBorderKey)
  1051. let _ = self.setColor(newValue, forKey: KMPreference.markupColorRectangleBorderKey)
  1052. }
  1053. }
  1054. var markupCircleFillColor: NSColor {
  1055. get {
  1056. return self.getColor(forKey: KMPreference.markupColorCircleFillKey)
  1057. }
  1058. set {
  1059. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorCircleFillKey)
  1060. let _ = self.setColor(newValue, forKey: KMPreference.markupColorCircleFillKey)
  1061. }
  1062. }
  1063. var markupCircleBorderColor: NSColor {
  1064. get {
  1065. return self.getColor(forKey: KMPreference.markupColorCircleBorderKey)
  1066. }
  1067. set {
  1068. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorCircleBorderKey)
  1069. let _ = self.setColor(newValue, forKey: KMPreference.markupColorCircleBorderKey)
  1070. }
  1071. }
  1072. var markupLineColor: NSColor {
  1073. get {
  1074. return self.getColor(forKey: KMPreference.markupColorLineKey)
  1075. }
  1076. set {
  1077. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorLineKey)
  1078. let _ = self.setColor(newValue, forKey: KMPreference.markupColorLineKey)
  1079. }
  1080. }
  1081. var markupArrowColor: NSColor {
  1082. get {
  1083. return self.getColor(forKey: KMPreference.markupColorArrowKey)
  1084. }
  1085. set {
  1086. self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorArrowKey)
  1087. let _ = self.setColor(newValue, forKey: KMPreference.markupColorArrowKey)
  1088. }
  1089. }
  1090. var markupTextFontSize: Float {
  1091. get {
  1092. return self.getData(forKey: KMPreference.markupTextFontSizeKey) as? Float ?? self.textFontSizeDefaultValue()
  1093. }
  1094. set {
  1095. self.syncDataToPDFView(newValue, forKey: KMPreference.markupTextFontSizeKey)
  1096. _ = self.setData(data: newValue, forKey: KMPreference.markupTextFontSizeKey)
  1097. }
  1098. }
  1099. var markupNoteFontSize: Float {
  1100. get {
  1101. return self.getData(forKey: KMPreference.markupNoteFontSizeKey) as? Float ?? self.noteFontSizeDefaultValue()
  1102. }
  1103. set {
  1104. self.syncDataToPDFView(newValue, forKey: KMPreference.markupNoteFontSizeKey)
  1105. _ = self.setData(data: newValue, forKey: KMPreference.markupNoteFontSizeKey)
  1106. }
  1107. }
  1108. }
  1109. // MARK: -
  1110. // MARK: Additions
  1111. extension KMPreferenceManager {
  1112. var markupFontTextString: String {
  1113. get {
  1114. let string: String? = UserDefaults.standard.object(forKey: CFreeTextNoteFontNameKey) as? String
  1115. if (string == nil) {
  1116. return KMDefaultFontName
  1117. }
  1118. if (KMPreferenceManager.supportFonts.contains(string!)) {
  1119. return string!
  1120. }
  1121. return KMDefaultFontName
  1122. }
  1123. set {
  1124. if (KMPreferenceManager.supportFonts.contains(newValue)) {
  1125. UserDefaults.standard.set(newValue, forKey: CFreeTextNoteFontNameKey)
  1126. UserDefaults.standard.synchronize()
  1127. self.postNotification(object: [.markup], userInfo: [KMMarkupFontTextStringKey : newValue])
  1128. }
  1129. }
  1130. }
  1131. var markupFontTextAligment: NSTextAlignment {
  1132. get {
  1133. let type: Int? = UserDefaults.standard.integer(forKey: CFreeTextNoteAlignmentKey)
  1134. if (type == nil) {
  1135. return .left
  1136. }
  1137. if (type! == 0 || type! == 1 || type == 2) {
  1138. return NSTextAlignment(rawValue: type!)!
  1139. }
  1140. return .left
  1141. }
  1142. set {
  1143. if (newValue == .left || newValue == .center || newValue == .right) {
  1144. UserDefaults.standard.set(newValue.rawValue, forKey: CFreeTextNoteAlignmentKey)
  1145. UserDefaults.standard.synchronize()
  1146. self.postNotification(object: [.markup], userInfo: [KMMarkupFontTextAligmentKey : newValue.rawValue])
  1147. }
  1148. }
  1149. }
  1150. var markupFontNoteString: String {
  1151. get {
  1152. let fontName: String? = KMPreferenceManager.shared.getData(forKey: KMPreference.markupFontNoteStringKey) as? String
  1153. if (fontName == nil) {
  1154. return KMDefaultFontName
  1155. }
  1156. if (KMPreference.supportFonts.contains(fontName!)) {
  1157. return fontName!
  1158. }
  1159. return KMDefaultFontName
  1160. }
  1161. set {
  1162. if (KMPreferenceManager.supportFonts.contains(newValue)) {
  1163. let _ = KMPreferenceManager.shared.setData(data: newValue, forKey: KMPreference.markupFontNoteStringKey)
  1164. }
  1165. }
  1166. }
  1167. class var supportFonts: [String] {
  1168. get {
  1169. var fontNames: Array<String> = []
  1170. for fontInfo in CPDFAnnotationModel.supportFonts() {
  1171. if ((fontInfo is NSDictionary) == false) {
  1172. continue
  1173. }
  1174. for (familyString, styleStrings) in (fontInfo as! NSDictionary) {
  1175. if ((styleStrings is NSArray) == false) {
  1176. break
  1177. }
  1178. for styleString in (styleStrings as! NSArray) {
  1179. fontNames.append("\(familyString)-\(styleString)")
  1180. }
  1181. }
  1182. }
  1183. return fontNames
  1184. }
  1185. }
  1186. private func syncDataToPDFView(_ data: Any, forKey key: KMPreferenceKey) {
  1187. if (key == KMMarkupColorHighlightKey) {
  1188. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CHighlightNoteColorKey)
  1189. } else if (key == KMMarkupColorUnderlineKey) {
  1190. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CUnderlineNoteColorKey)
  1191. } else if (key == KMMarkupColorStrikthroughKey) {
  1192. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CStrikeOutNoteColorKey)
  1193. } else if (key == KMMarkupColorPenKey) {
  1194. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CInkNoteColorKey)
  1195. } else if (key == KMMarkupColorNoteKey) {
  1196. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CAnchoredNoteColorKey)
  1197. } else if (key == KMMarkupColorRectangleFillKey) {
  1198. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CSquareNoteInteriorColorKey)
  1199. } else if (key == KMMarkupColorRectangleBorderKey) {
  1200. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CSquareNoteColorKey)
  1201. } else if (key == KMMarkupColorCircleFillKey) {
  1202. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CCircleNoteInteriorColorKey)
  1203. } else if (key == KMMarkupColorCircleBorderKey) {
  1204. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CCircleNoteColorKey)
  1205. } else if (key == KMMarkupColorLineKey) {
  1206. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CLineNoteColorKey)
  1207. } else if (key == KMMarkupColorArrowKey) {
  1208. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CArrowNoteColorKey)
  1209. } else if (key == KMMarkupColorTextKey) {
  1210. UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CFreeTextNoteColorKey)
  1211. } else if (key == KMMarkupFontTextStringKey) {
  1212. UserDefaults.standard.set(data, forKey: CFreeTextNoteFontNameKey)
  1213. UserDefaults.standard.synchronize()
  1214. } else if (key == KMMarkupFontTextAligmentKey) {
  1215. UserDefaults.standard.set(data, forKey: CFreeTextNoteAlignmentKey)
  1216. UserDefaults.standard.synchronize()
  1217. } else if (key == KMMarkupFontNoteStringKey) {
  1218. // UserDefaults.standard.set(data, forKey: CFreeTextNoteAlignmentKey)
  1219. // UserDefaults.standard.synchronize()
  1220. } else if (key == KMMarkupTextFontSizeKey) {
  1221. UserDefaults.standard.set(data, forKey: CFreeTextNoteFontSizeKey)
  1222. UserDefaults.standard.synchronize()
  1223. } else if (key == KMMarkupNoteFontSizeKey) {
  1224. // UserDefaults.standard.set(data, forKey: CFreeTextNoteFontSizeKey)
  1225. // UserDefaults.standard.synchronize()
  1226. }
  1227. }
  1228. private func getDefaultColors(forKey key: KMPreferenceKey) -> [Double] {
  1229. let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue]!
  1230. for key_i in [KMMarkupColorHighlightKey, KMMarkupColorUnderlineKey, KMMarkupColorStrikthroughKey,
  1231. KMMarkupColorPenKey, KMMarkupColorNoteKey, KMMarkupColorTextKey,
  1232. KMMarkupColorRectangleFillKey, KMMarkupColorRectangleBorderKey,
  1233. KMMarkupColorCircleFillKey, KMMarkupColorCircleBorderKey,
  1234. KMMarkupColorLineKey, KMMarkupColorArrowKey] {
  1235. if (key == key_i) {
  1236. return markupGroupInfo[key] as! [Double]
  1237. }
  1238. }
  1239. let displayGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.display.rawValue]!
  1240. for key_i in [KMDisplayBackgroundNormalColorKey, KMDisplayBackgroundFullScreenColorKey,
  1241. KMDisplayFieldHighlightingColorKey, KMDisplayRequiredFieldHighlightingColorKey] {
  1242. if (key == key_i) {
  1243. return displayGroupInfo[key] as! [Double]
  1244. }
  1245. }
  1246. return [0.0, 0.0, 0.0, 1.0]
  1247. }
  1248. private func getDefaultColor(forKey key: KMPreferenceKey) -> NSColor {
  1249. return self.dataToColor(colors: self.getDefaultColors(forKey: key))
  1250. }
  1251. private func resetDataToPDFView() {
  1252. let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue]!
  1253. for key in [KMMarkupColorHighlightKey, KMMarkupColorUnderlineKey, KMMarkupColorStrikthroughKey,
  1254. KMMarkupColorPenKey, KMMarkupColorNoteKey, KMMarkupColorTextKey,
  1255. KMMarkupColorRectangleFillKey, KMMarkupColorRectangleBorderKey,
  1256. KMMarkupColorCircleFillKey, KMMarkupColorCircleBorderKey,
  1257. KMMarkupColorLineKey, KMMarkupColorArrowKey] {
  1258. self.syncDataToPDFView(self.dataToColor(colors: markupGroupInfo[key] as! [Double]), forKey: key)
  1259. }
  1260. self.syncDataToPDFView(KMDefaultFontName, forKey: KMMarkupFontTextStringKey)
  1261. self.syncDataToPDFView(NSTextAlignment.left.rawValue, forKey: KMMarkupFontTextAligmentKey)
  1262. self.syncDataToPDFView(KMDefaultFontName, forKey: KMMarkupFontNoteStringKey)
  1263. }
  1264. public func resumeDataToPDFView() {
  1265. self.syncDataToPDFView(KMPreferenceManager.shared.markupHighlightColor, forKey: KMMarkupColorHighlightKey)
  1266. self.syncDataToPDFView(KMPreferenceManager.shared.markupUnderlineColor, forKey: KMMarkupColorUnderlineKey)
  1267. self.syncDataToPDFView(KMPreferenceManager.shared.markupStrikthroughColor, forKey: KMMarkupColorStrikthroughKey)
  1268. self.syncDataToPDFView(KMPreferenceManager.shared.markupPenColor, forKey: KMMarkupColorPenKey)
  1269. self.syncDataToPDFView(KMPreferenceManager.shared.markupNoteColor, forKey: KMMarkupColorNoteKey)
  1270. self.syncDataToPDFView(KMPreferenceManager.shared.markupRectangleFillColor, forKey: KMMarkupColorRectangleFillKey)
  1271. self.syncDataToPDFView(KMPreferenceManager.shared.markupRectangleBorderColor, forKey: KMMarkupColorRectangleBorderKey)
  1272. self.syncDataToPDFView(KMPreferenceManager.shared.markupCircleFillColor, forKey: KMMarkupColorCircleFillKey)
  1273. self.syncDataToPDFView(KMPreferenceManager.shared.markupCircleBorderColor, forKey: KMMarkupColorCircleBorderKey)
  1274. self.syncDataToPDFView(KMPreferenceManager.shared.markupLineColor, forKey: KMMarkupColorLineKey)
  1275. self.syncDataToPDFView(KMPreferenceManager.shared.markupArrowColor, forKey: KMMarkupColorArrowKey)
  1276. self.syncDataToPDFView(KMPreferenceManager.shared.markupTextColor, forKey: KMMarkupColorTextKey)
  1277. self.syncDataToPDFView(KMPreferenceManager.shared.markupFontTextString, forKey: KMMarkupFontTextStringKey)
  1278. self.syncDataToPDFView(KMPreferenceManager.shared.markupFontTextAligment.rawValue, forKey: KMMarkupFontTextAligmentKey)
  1279. self.syncDataToPDFView(KMPreferenceManager.shared.markupFontNoteString, forKey: KMMarkupFontNoteStringKey)
  1280. }
  1281. public func initDataForAppLaunch() {
  1282. // KMPreferenceManager.shared.author = NSFullUserName()
  1283. if (KMPreferenceManager.shared.autoSave) {
  1284. Task { @MainActor in
  1285. if await KMLightMemberManager.manager.canPayFunction() == false {
  1286. KMPreferenceManager.shared.autoSave = false
  1287. }
  1288. }
  1289. }
  1290. }
  1291. }
  1292. // MARK: -
  1293. // MARK: UserDefaults
  1294. fileprivate let kKMLastOpenFilepathKey = "lastOpenFilepath"
  1295. fileprivate let kKMLastOpenFilepathKeys = "lastOpenFilepaths"
  1296. fileprivate let kKMViewSettingKey = "viewSetting"
  1297. fileprivate let kKMPageNumberKey = "pageNumber"
  1298. fileprivate let kKMPageScaleKey = "pageScale"
  1299. extension KMPreferenceManager {
  1300. var lastOpenFilepath: String? {
  1301. get {
  1302. return UserDefaults.standard.value(forKey: kKMLastOpenFilepathKey) as? String
  1303. }
  1304. set {
  1305. UserDefaults.standard.set(newValue, forKey: kKMLastOpenFilepathKey)
  1306. UserDefaults.standard.synchronize()
  1307. }
  1308. }
  1309. var lastOpenFilepaths: [String]? {
  1310. get {
  1311. return UserDefaults.standard.value(forKey: kKMLastOpenFilepathKeys) as? [String]
  1312. }
  1313. set {
  1314. UserDefaults.standard.set(newValue, forKey: kKMLastOpenFilepathKeys)
  1315. UserDefaults.standard.synchronize()
  1316. }
  1317. }
  1318. var viewSetting: [KMPreferenceViewSetting : Any]? {
  1319. get {
  1320. return UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [KMPreferenceViewSetting : Any]
  1321. }
  1322. set {
  1323. if (newValue == nil) {
  1324. UserDefaults.standard.set(newValue, forKey: kKMViewSettingKey)
  1325. UserDefaults.standard.synchronize()
  1326. return
  1327. }
  1328. let viewSetting: [String : Any]? = UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [String : Any]
  1329. var info: [String : Any] = [:]
  1330. if (viewSetting != nil) {
  1331. for (key, value) in viewSetting! {
  1332. info.updateValue(value, forKey: key)
  1333. }
  1334. }
  1335. for (key, value) in newValue! {
  1336. if (key == .pageNumber) { // 只处理 枚举
  1337. info.updateValue(value, forKey: key.rawValue)
  1338. }
  1339. }
  1340. UserDefaults.standard.set(info, forKey: kKMViewSettingKey)
  1341. UserDefaults.standard.synchronize()
  1342. }
  1343. }
  1344. func setPageNumber(_ number: Int, forKey key: String) {
  1345. UserDefaults.standard.set(number, forKey: "\(key)+\(kKMPageNumberKey)")
  1346. UserDefaults.standard.synchronize()
  1347. }
  1348. func getPageNumber(forKey key: String) -> Int? {
  1349. return UserDefaults.standard.value(forKey: "\(key)+\(kKMPageNumberKey)") as? Int
  1350. }
  1351. func setPageScale(_ scale: Float, forKey key: String) {
  1352. UserDefaults.standard.set(scale, forKey: "\(key)+\(kKMPageScaleKey)")
  1353. UserDefaults.standard.synchronize()
  1354. }
  1355. func getPageScale(forKey key: String) -> Float? {
  1356. return UserDefaults.standard.value(forKey: "\(key)+\(kKMPageScaleKey)") as? Float
  1357. }
  1358. }
  1359. // MARK: -
  1360. // MARK: Qiuck
  1361. extension KMPreferenceManager {
  1362. internal func closeFileIsPrompt() -> Bool {
  1363. return self.closeFilePromptType == .promp
  1364. }
  1365. func leftSideNeedCloseWhenOpenFile() -> Bool {
  1366. return KMPreferenceManager.shared.leftSideDisplayType == .closeWhenOpenFile
  1367. }
  1368. var autoExpandPropertyPanel: Bool {
  1369. get {
  1370. return KMPreferenceManager.shared.propertyPanelExpandType == .auto
  1371. }
  1372. }
  1373. // 单位: 秒
  1374. var autoSaveTimeInterval: TimeInterval {
  1375. get {
  1376. var minute = KMPreferenceManager.shared.autoSavePerNumberMinute
  1377. if (minute < 5) {
  1378. minute = 5
  1379. } else if (minute > 99) {
  1380. minute = 99
  1381. }
  1382. let interval: TimeInterval = Double(minute) * 60.0
  1383. return interval
  1384. }
  1385. }
  1386. }