KMRateWindowController.swift 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // KMRateWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by liujiajie on 2024/1/12.
  6. //
  7. import Cocoa
  8. typealias rateCloseBlock = (_ wc: KMRateWindowController) -> ()
  9. class KMRateWindow: NSWindow{
  10. override func close() {
  11. super.close()
  12. self.orderOut(self.windowController)
  13. }
  14. }
  15. class KMRateWindowController: NSWindowController, NSWindowDelegate{
  16. @IBOutlet var imageView: NSImageView!
  17. @IBOutlet var rateUsButton: NSButton!
  18. @IBOutlet var feedBackButton: NSButton!
  19. @IBOutlet var introduceLabel: NSTextField!
  20. var closeBlock: rateCloseBlock?
  21. convenience init() {
  22. self.init(windowNibName: "KMRateWindowController")
  23. }
  24. override func windowDidLoad() {
  25. super.windowDidLoad()
  26. self.window?.title = NSLocalizedString("Rate Us", comment: "")
  27. self.introduceLabel.stringValue = NSLocalizedString("We would appreciate your input! \nPlease take one minute to give us a great review on the App Store to help other people make a right decision.", comment: "")
  28. #if VERSION_FREE
  29. self.imageView.image = NSImage(named: "rate_pic_free")
  30. #else
  31. self.imageView.image = NSImage(named: "rate_pic_pro")
  32. #endif
  33. //Title Color
  34. let ps = NSMutableParagraphStyle()
  35. ps.alignment = NSTextAlignment.center
  36. let color = NSColor.white
  37. let color1 = NSColor(red: 26/255.0, green: 136/255.0, blue: 255/255.0, alpha: 1)
  38. let textDictionary: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: color, NSAttributedString.Key.paragraphStyle: ps, NSAttributedString.Key.font: NSFont.systemFont(ofSize: 13)]
  39. let textDictionary1: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: color1, NSAttributedString.Key.paragraphStyle: ps, NSAttributedString.Key.font: NSFont.systemFont(ofSize: 13)]
  40. let rateUsButtonString = NSMutableAttributedString(string: NSLocalizedString("Give a 5-Star", comment: ""), attributes: textDictionary)
  41. self.rateUsButton.attributedTitle = rateUsButtonString
  42. let feedBackButtonString = NSMutableAttributedString(string: NSLocalizedString("Give a suggestion", comment: ""), attributes: textDictionary1)
  43. self.feedBackButton.attributedTitle = feedBackButtonString
  44. self.rateUsButton.wantsLayer = true
  45. self.rateUsButton.layer?.backgroundColor = color1.cgColor
  46. self.feedBackButton.wantsLayer = true
  47. self.feedBackButton.layer?.backgroundColor = NSColor(red: 235/255.0, green: 245/255.0, blue: 255/255.0, alpha: 1).cgColor
  48. self.rateUsButton.layer?.cornerRadius = 4
  49. self.feedBackButton.layer?.cornerRadius = 4
  50. iRate.sharedInstance().lastReminded = Date()
  51. }
  52. func windowShouldClose(_ sender: NSWindow) -> Bool {
  53. iRate.sharedInstance().remindMeLater()
  54. return true
  55. }
  56. @IBAction func rateUsAction(_ sender: Any) {
  57. iRate.sharedInstance().ratedThisVersion = true
  58. iRate.sharedInstance().openRatingsPageInAppStore()
  59. close()
  60. }
  61. @IBAction func feedBackAction(_ sender: Any) {
  62. iRate.sharedInstance().remindMeLater()
  63. close()
  64. }
  65. override func close() {
  66. super.close()
  67. if (self.closeBlock != nil) {
  68. closeBlock!(self)
  69. }
  70. }
  71. }