feat: moved the pause/resume button from the application settings to the menu navigation (#1263)

This commit is contained in:
Serhiy Mytrovtsiy
2023-01-20 19:32:26 +01:00
parent 0c773463eb
commit 58ec37e171
10 changed files with 93 additions and 42 deletions

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "outline_pause_white_24pt_1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "outline_pause_white_24pt_2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "outline_pause_white_24pt_3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 B

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "baseline_play_arrow_white_24pt_1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "baseline_play_arrow_white_24pt_2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "baseline_play_arrow_white_24pt_3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

View File

@@ -26,19 +26,9 @@ class ApplicationSettings: NSStackView {
}
}
private var pauseState: Bool {
get {
return Store.shared.bool(key: "pause", defaultValue: false)
}
set {
Store.shared.set(key: "pause", value: newValue)
}
}
private let updateWindow: UpdateWindow = UpdateWindow()
private var updateSelector: NSPopUpButton?
private var startAtLoginBtn: NSButton?
private var pauseButton: NSButton?
private var uninstallHelperButton: NSButton?
private var buttonsContainer: NSStackView?
@@ -55,7 +45,6 @@ class ApplicationSettings: NSStackView {
self.addArrangedSubview(self.separatorView())
self.addArrangedSubview(self.buttonsView())
NotificationCenter.default.addObserver(self, selector: #selector(listenForPause), name: .pause, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(toggleUninstallHelperButton), name: .fanHelperState, object: nil)
}
@@ -64,7 +53,6 @@ class ApplicationSettings: NSStackView {
}
deinit {
NotificationCenter.default.removeObserver(self, name: .pause, object: nil)
NotificationCenter.default.removeObserver(self, name: .fanHelperState, object: nil)
}
@@ -200,13 +188,6 @@ class ApplicationSettings: NSStackView {
reset.target = self
reset.action = #selector(self.resetSettings)
let pause: NSButton = NSButton()
pause.title = localizedString(self.pauseState ? "Resume the Stats" : "Pause the Stats")
pause.bezelStyle = .rounded
pause.target = self
pause.action = #selector(self.togglePause)
self.pauseButton = pause
let uninstall: NSButton = NSButton()
uninstall.title = localizedString("Uninstall fan helper")
uninstall.bezelStyle = .rounded
@@ -215,7 +196,6 @@ class ApplicationSettings: NSStackView {
self.uninstallHelperButton = uninstall
view.addArrangedSubview(reset)
view.addArrangedSubview(pause)
if SMCHelper.shared.isInstalled {
view.addArrangedSubview(uninstall)
}
@@ -324,16 +304,6 @@ class ApplicationSettings: NSStackView {
}
}
@objc func togglePause(_ sender: NSButton) {
self.pauseState = !self.pauseState
self.pauseButton?.title = localizedString(self.pauseState ? "Resume the Stats" : "Pause the Stats")
NotificationCenter.default.post(name: .pause, object: nil, userInfo: ["state": self.pauseState])
}
@objc func listenForPause() {
self.pauseButton?.title = localizedString(self.pauseState ? "Resume the Stats" : "Pause the Stats")
}
@objc private func toggleUninstallHelperButton(_ notification: Notification) {
guard let state = notification.userInfo?["state"] as? Bool, let v = self.uninstallHelperButton else {
return

View File

@@ -268,6 +268,16 @@ private class SidebarView: NSStackView {
private let scrollView: ScrollableStackView
private let supportPopover = NSPopover()
private var pauseButton: NSButton? = nil
private var pauseState: Bool {
get {
return Store.shared.bool(key: "pause", defaultValue: false)
}
set {
Store.shared.set(key: "pause", value: newValue)
}
}
private var dashboardIcon: NSImage {
if #available(macOS 11.0, *), let icon = NSImage(systemSymbolName: "circle.grid.3x3.fill", accessibilityDescription: nil) {
@@ -283,22 +293,19 @@ private class SidebarView: NSStackView {
}
private var bugIcon: NSImage {
// if #available(macOS 11.0, *), let icon = NSImage(systemSymbolName: "ladybug", accessibilityDescription: nil) {
// return icon
// }
return NSImage(named: NSImage.Name("bug"))!
NSImage(named: NSImage.Name("bug"))!
}
private var supportIcon: NSImage {
// if #available(macOS 11.0, *), let icon = NSImage(systemSymbolName: "heart.fill", accessibilityDescription: nil) {
// return icon
// }
return NSImage(named: NSImage.Name("donate"))!
NSImage(named: NSImage.Name("donate"))!
}
private var pauseIcon: NSImage {
NSImage(named: NSImage.Name("pause"))!
}
private var resumeIcon: NSImage {
NSImage(named: NSImage.Name("resume"))!
}
private var closeIcon: NSImage {
// if #available(macOS 11.0, *), let icon = NSImage(systemSymbolName: "power.circle", accessibilityDescription: nil) {
// return icon
// }
return NSImage(named: NSImage.Name("power"))!
NSImage(named: NSImage.Name("power"))!
}
override init(frame: NSRect) {
@@ -326,8 +333,12 @@ private class SidebarView: NSStackView {
additionalButtons.distribution = .fillEqually
additionalButtons.spacing = 0
let pauseButton = self.makeButton(title: localizedString("Pause the Stats"), image: self.pauseState ? self.resumeIcon : self.pauseIcon, action: #selector(togglePause))
self.pauseButton = pauseButton
additionalButtons.addArrangedSubview(self.makeButton(title: localizedString("Report a bug"), image: self.bugIcon, action: #selector(reportBug)))
additionalButtons.addArrangedSubview(self.makeButton(title: localizedString("Support the application"), image: self.supportIcon, action: #selector(donate)))
additionalButtons.addArrangedSubview(pauseButton)
additionalButtons.addArrangedSubview(self.makeButton(title: localizedString("Close application"), image: self.closeIcon, action: #selector(closeApp)))
let emptySpace = NSView()
@@ -338,6 +349,12 @@ private class SidebarView: NSStackView {
}
self.addArrangedSubview(self.scrollView)
self.addArrangedSubview(additionalButtons)
NotificationCenter.default.addObserver(self, selector: #selector(listenForPause), name: .pause, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: .pause, object: nil)
}
required init?(coder: NSCoder) {
@@ -460,6 +477,18 @@ private class SidebarView: NSStackView {
@objc private func closeApp(_ sender: Any) {
NSApp.terminate(sender)
}
@objc private func togglePause(_ sender: NSButton) {
self.pauseState = !self.pauseState
self.pauseButton?.toolTip = localizedString(self.pauseState ? "Resume the Stats" : "Pause the Stats")
self.pauseButton?.image = self.pauseState ? self.resumeIcon : self.pauseIcon
NotificationCenter.default.post(name: .pause, object: nil, userInfo: ["state": self.pauseState])
}
@objc func listenForPause() {
self.pauseButton?.toolTip = localizedString(self.pauseState ? "Resume the Stats" : "Pause the Stats")
self.pauseButton?.image = self.pauseState ? self.resumeIcon : self.pauseIcon
}
}
private class MenuItem: NSView {