Makes some members private.
This commit is contained in:
parent
34e193df21
commit
3ca0eddd23
|
@ -1,10 +1,10 @@
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
protocol NotifierWindowDelegate: AnyObject {
|
private protocol NotifierWindowDelegate: AnyObject {
|
||||||
func windowDidBecomeClicked(_ window: NotifierWindow)
|
func windowDidBecomeClicked(_ window: NotifierWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
class NotifierWindow: NSWindow {
|
private class NotifierWindow: NSWindow {
|
||||||
weak var clickDelegate: NotifierWindowDelegate?
|
weak var clickDelegate: NotifierWindowDelegate?
|
||||||
|
|
||||||
override func mouseDown(with event: NSEvent) {
|
override func mouseDown(with event: NSEvent) {
|
||||||
|
@ -12,8 +12,8 @@ class NotifierWindow: NSWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let kWindowWidth: CGFloat = 160.0
|
private let kWindowWidth: CGFloat = 160.0
|
||||||
let kWindowHeight: CGFloat = 80.0
|
private let kWindowHeight: CGFloat = 80.0
|
||||||
|
|
||||||
public class NotifierController: NSWindowController, NotifierWindowDelegate {
|
public class NotifierController: NSWindowController, NotifierWindowDelegate {
|
||||||
private var messageTextField: NSTextField
|
private var messageTextField: NSTextField
|
||||||
|
@ -64,18 +64,18 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
|
||||||
controller.show()
|
controller.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
static func increaseInstanceCount() {
|
private static func increaseInstanceCount() {
|
||||||
instanceCount += 1
|
instanceCount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
static func decreaseInstanceCount() {
|
private static func decreaseInstanceCount() {
|
||||||
instanceCount -= 1
|
instanceCount -= 1
|
||||||
if instanceCount < 0 {
|
if instanceCount < 0 {
|
||||||
instanceCount = 0
|
instanceCount = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public init() {
|
private init() {
|
||||||
let screenRect = NSScreen.main?.visibleFrame ?? NSRect.zero
|
let screenRect = NSScreen.main?.visibleFrame ?? NSRect.zero
|
||||||
let contentRect = NSRect(x: 0, y: 0, width: kWindowWidth, height: kWindowHeight)
|
let contentRect = NSRect(x: 0, y: 0, width: kWindowWidth, height: kWindowHeight)
|
||||||
var windowRect = contentRect
|
var windowRect = contentRect
|
||||||
|
@ -107,41 +107,41 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func setStartLocation() {
|
private func show() {
|
||||||
if NotifierController.instanceCount == 0 {
|
func setStartLocation() {
|
||||||
return
|
if NotifierController.instanceCount == 0 {
|
||||||
}
|
return
|
||||||
let lastLocation = NotifierController.lastLocation
|
}
|
||||||
let screenRect = NSScreen.main?.visibleFrame ?? NSRect.zero
|
let lastLocation = NotifierController.lastLocation
|
||||||
var windowRect = self.window?.frame ?? NSRect.zero
|
let screenRect = NSScreen.main?.visibleFrame ?? NSRect.zero
|
||||||
windowRect.origin.x = lastLocation.x
|
var windowRect = self.window?.frame ?? NSRect.zero
|
||||||
windowRect.origin.y = lastLocation.y - 10 - windowRect.height
|
windowRect.origin.x = lastLocation.x
|
||||||
|
windowRect.origin.y = lastLocation.y - 10 - windowRect.height
|
||||||
|
|
||||||
if windowRect.origin.y < screenRect.minY {
|
if windowRect.origin.y < screenRect.minY {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.window?.setFrame(windowRect, display: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.window?.setFrame(windowRect, display: true)
|
func moveIn() {
|
||||||
}
|
let afterRect = self.window?.frame ?? NSRect.zero
|
||||||
|
NotifierController.lastLocation = afterRect.origin
|
||||||
|
var beforeRect = afterRect
|
||||||
|
beforeRect.origin.y += 10
|
||||||
|
window?.setFrame(beforeRect, display: true)
|
||||||
|
window?.orderFront(self)
|
||||||
|
window?.setFrame(afterRect, display: true, animate: true)
|
||||||
|
}
|
||||||
|
|
||||||
func moveIn() {
|
|
||||||
let afterRect = self.window?.frame ?? NSRect.zero
|
|
||||||
NotifierController.lastLocation = afterRect.origin
|
|
||||||
var beforeRect = afterRect
|
|
||||||
beforeRect.origin.y += 10
|
|
||||||
window?.setFrame(beforeRect, display: true)
|
|
||||||
window?.orderFront(self)
|
|
||||||
window?.setFrame(afterRect, display: true, animate: true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func show() {
|
|
||||||
setStartLocation()
|
setStartLocation()
|
||||||
moveIn()
|
moveIn()
|
||||||
NotifierController.increaseInstanceCount()
|
NotifierController.increaseInstanceCount()
|
||||||
waitTimer = Timer.scheduledTimer(timeInterval: shouldStay ? 5 : 1, target: self, selector: #selector(fadeOut), userInfo: nil, repeats: false)
|
waitTimer = Timer.scheduledTimer(timeInterval: shouldStay ? 5 : 1, target: self, selector: #selector(fadeOut), userInfo: nil, repeats: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func doFadeOut(_ timer: Timer) {
|
@objc private func doFadeOut(_ timer: Timer) {
|
||||||
let opacity = self.window?.alphaValue ?? 0
|
let opacity = self.window?.alphaValue ?? 0
|
||||||
if opacity <= 0 {
|
if opacity <= 0 {
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -150,7 +150,7 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func fadeOut() {
|
@objc private func fadeOut() {
|
||||||
waitTimer?.invalidate()
|
waitTimer?.invalidate()
|
||||||
waitTimer = nil
|
waitTimer = nil
|
||||||
NotifierController.decreaseInstanceCount()
|
NotifierController.decreaseInstanceCount()
|
||||||
|
@ -165,7 +165,7 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
|
||||||
super.close()
|
super.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func windowDidBecomeClicked(_ window: NotifierWindow) {
|
fileprivate func windowDidBecomeClicked(_ window: NotifierWindow) {
|
||||||
self.fadeOut()
|
self.fadeOut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ public class OpenCCBridge: NSObject {
|
||||||
private static let shared = OpenCCBridge()
|
private static let shared = OpenCCBridge()
|
||||||
private var converter: ChineseConverter?
|
private var converter: ChineseConverter?
|
||||||
|
|
||||||
override init() {
|
private override init() {
|
||||||
try? converter = ChineseConverter(options: .simplify)
|
try? converter = ChineseConverter(options: .simplify)
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
public class TooltipController: NSWindowController {
|
public class TooltipController: NSWindowController {
|
||||||
let backgroundColor = NSColor(calibratedHue: 0.16, saturation: 0.22, brightness: 0.97, alpha: 1.0)
|
private let backgroundColor = NSColor(calibratedHue: 0.16, saturation: 0.22, brightness: 0.97, alpha: 1.0)
|
||||||
var messageTextField: NSTextField
|
private var messageTextField: NSTextField
|
||||||
var tooltip: String = "" {
|
private var tooltip: String = "" {
|
||||||
didSet {
|
didSet {
|
||||||
messageTextField.stringValue = tooltip
|
messageTextField.stringValue = tooltip
|
||||||
adjustSize()
|
adjustSize()
|
||||||
|
|
Loading…
Reference in New Issue