Skip to content

Commit 6121145

Browse files
committed
fix: hide status item
1 parent ce6749b commit 6121145

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

Mos/Managers/StatusItemManager.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by Caldis on 2018/3/7.
66
// Copyright © 2018年 Caldis. All rights reserved.
77
//
8-
98
import Cocoa
109

1110
enum 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
**/
141137
extension 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
}

Mos/Options/Options.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ extension Options {
6565
scrollAdvanced.precision = UserDefaults.standard.double(forKey: "precision")
6666
// 解锁
6767
readingOptionsLock = false
68-
NSLog("Option readed")
6968
}
7069

7170
// 写入到 UserDefaults

Mos/Utils/Constants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class OPTIONS_GENERAL_DEFAULT {
7878
}
7979
// 隐藏
8080
var hideStatusItem = false {
81-
willSet {newValue ? StatusItemManager.shared.hideStatusItem() : StatusItemManager.shared.showStatusItem()}
81+
willSet {newValue ? StatusItemManager.hideStatusItem() : StatusItemManager.showStatusItem()}
8282
didSet {Options.shared.saveOptions()}
8383
}
8484
// 例外

0 commit comments

Comments
 (0)