-
Notifications
You must be signed in to change notification settings - Fork 895
/
Copy pathAboutModalController.swift
132 lines (95 loc) · 3.78 KB
/
AboutModalController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// AboutModalController.swift
// TelegramMac
//
// Created by keepcoder on 06/12/2016.
// Copyright © 2016 Telegram. All rights reserved.
//
import Cocoa
import TGUIKit
var APP_VERSION_STRING: String {
var vText = "\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "1").\(Bundle.main.infoDictionary?["CFBundleVersion"] ?? "0")"
#if STABLE
vText += " Stable"
#elseif APP_STORE
vText += " AppStore"
#elseif ALPHA
vText += " Alpha"
#else
vText += " Beta"
#endif
return vText
}
fileprivate class AboutModalView : Control {
fileprivate let copyright:TextView = TextView()
fileprivate let descView:TextView = TextView()
required init(frame frameRect: NSRect) {
super.init(frame: frameRect)
let formatter = DateFormatter()
formatter.dateFormat = "yyyy"
let copyrightLayout = TextViewLayout(.initialize(string: "Copyright © 2016 - \(formatter.string(from: Date(timeIntervalSinceReferenceDate: Date.timeIntervalSinceReferenceDate))) TELEGRAM MESSENGER", color: theme.colors.grayText, font: .normal(.text)), alignment: .center)
copyrightLayout.measure(width:frameRect.width - 40)
let vText = APP_VERSION_STRING
let attr = NSMutableAttributedString()
_ = attr.append(string: appName, color: theme.colors.text, font: .medium(.header))
_ = attr.append(string: "\n\(vText)", color: theme.colors.link, font: .medium(.text))
attr.addAttribute(.link, value: "copy", range: attr.range)
_ = attr.append(string: "\n\n")
_ = attr.append(string: strings().aboutDescription, color: theme.colors.text, font: .normal(.text))
let descLayout = TextViewLayout(attr, alignment: .center)
descLayout.measure(width:frameRect.width - 40)
descLayout.interactions.copy = {
copyToClipboard(APP_VERSION_STRING)
return true
}
descLayout.interactions.processURL = { _ in
var bp:Int = 0
bp += 1
}
copyright.update(copyrightLayout)
descView.update(descLayout)
copyright.backgroundColor = theme.colors.background
descView.backgroundColor = theme.colors.background
addSubview(copyright)
addSubview(descView)
descView.isSelectable = false
copyright.isSelectable = false
}
fileprivate override func layout() {
super.layout()
descView.centerX(y: 20)
copyright.centerX(y:frame.height - copyright.frame.height - 20)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class AboutModalController: ModalViewController {
override func viewClass() -> AnyClass {
return AboutModalView.self
}
override init() {
super.init(frame: NSMakeRect(0, 0, 300, 190))
bar = .init(height: 0)
}
override func close(animationType: ModalAnimationCloseBehaviour = .common) {
super.close(animationType: animationType)
}
override func viewDidLoad() {
super.viewDidLoad()
genericView.descView.textLayout?.interactions.processURL = { [weak self] url in
if let url = url as? inAppLink {
execute(inapp: url)
} else if let url = url as? String, url == "copy" {
copyToClipboard(APP_VERSION_STRING)
self?.show(toaster: ControllerToaster(text: strings().shareLinkCopied))
return
}
self?.close()
}
readyOnce()
}
private var genericView:AboutModalView {
return self.view as! AboutModalView
}
}