55// Created by Caldis on 2018/3/7.
66// Copyright © 2018年 Caldis. All rights reserved.
77//
8-
98import Cocoa
109
1110enum STATUS_ITEM_TYPE {
@@ -18,17 +17,14 @@ class StatusItemManager: NSMenu, NSMenuDelegate {
1817 // 状态栏类型
1918 let TYPE = STATUS_ITEM_TYPE . menu
2019
21-
22- // 单例
23- static let shared = StatusItemManager ( )
24-
2520 // 状态栏引用
26- let item = NSStatusBar . system. statusItem ( withLength: NSStatusItem . variableLength)
21+ static let statusItem = NSStatusBar . system. statusItem ( withLength: NSStatusItem . variableLength)
22+ let item = StatusItemManager . statusItem
2723
2824 // 初始化
2925 override func awakeFromNib( ) {
3026 NSLog ( " Module initialized: StatusItemManager " )
31- // 设置图标
27+ // 设置图标/行为
3228 item. image = #imageLiteral( resourceName: " AppStatusBarIcon " )
3329 // 设置事件响应
3430 switch TYPE {
@@ -140,19 +136,19 @@ extension StatusItemManager {
140136 **/
141137extension StatusItemManager {
142138 // 显示状态栏图标
143- func showStatusItem( ) {
139+ class func showStatusItem( ) {
144140 if #available( OSX 10 . 12 , * ) {
145- item . isVisible = true
141+ self . statusItem . isVisible = true
146142 } else {
147- item . length = NSStatusItem . variableLength
143+ self . statusItem . length = NSStatusItem . variableLength
148144 }
149145 }
150146 // 隐藏状态栏图标
151- func hideStatusItem( ) {
147+ class func hideStatusItem( ) {
152148 if #available( OSX 10 . 12 , * ) {
153- item . isVisible = false
149+ self . statusItem . isVisible = false
154150 } else {
155- item . length = 0.0
151+ self . statusItem . length = 0.0
156152 }
157153 }
158154}
0 commit comments