let sysStatusBar = NSStatusBar.systemStatusBar()
dispatch_async(dispatch_main(){
let dele = NSApp.delegate as? AppDelegate
dele.statusBarValue = 100.0
// from the delegate or a singleton method, have statusbarValue observed
// and update the App.delegate.statusBarItem.image accordingly.
// make sure it happens on the main thread... then the image / text
// will update...
}
1 回答
之前遇到过它:
https://github.com/adamhartford/PopStatusItem
很好,在弹出项目上似乎是线程友好的(已经使用异步线程测试过) . 编辑
另外,因为用户需要实际状态栏图像/文本更新而不是弹出窗口...
您正在做的是更新您添加NSStatusBarItem并在那里更新图像的代理 . 在我的示例中,我更新了“statusBarValue”,但如果只是为该值添加绑定或观察者,则可以轻松更新图像 .
ONCE AGAIN 确保在主线程上发生这种情况,或者UI只是忽略您的更新 . 所以来自后台线程等的更新......需要在主线程上调用 .