From 512b5b3ef591742fc42ef8ba0cbfe34451c4662a Mon Sep 17 00:00:00 2001
From: waydabber <37590873+waydabber@users.noreply.github.com>
Date: Tue, 10 Aug 2021 13:10:56 +0200
Subject: [PATCH] Various bug fixes - Fix hide menu icon after logoff/login. -
Handle sleep better - fix when user sleeps, wakes, resleeps etc during the
sobering period. - Fix menu icon and lowerContrastAfterBrightness when Reset
Preferences.
---
MonitorControl/AppDelegate.swift | 54 +++++++++----------
.../Extensions/Preferences+Extension.swift | 1 -
MonitorControl/Info.plist | 2 +-
MonitorControl/UI/SliderHandler.swift | 2 +-
MonitorControl/UI/de.lproj/Main.strings | 2 +-
MonitorControl/UI/fr.lproj/Main.strings | 2 +-
MonitorControl/UI/hu.lproj/Main.strings | 8 +--
MonitorControl/UI/it.lproj/Main.strings | 2 +-
MonitorControl/UI/ja.lproj/Main.strings | 2 +-
MonitorControl/UI/pl.lproj/Main.strings | 2 +-
MonitorControl/UI/ru.lproj/Main.strings | 2 +-
MonitorControl/UI/uk.lproj/Main.strings | 2 +-
MonitorControl/UI/zh-Hans.lproj/Main.strings | 2 +-
.../AdvancedPrefsViewController.swift | 3 +-
.../MainPrefsViewController.swift | 19 ++++---
MonitorControlHelper/Info.plist | 2 +-
16 files changed, 52 insertions(+), 55 deletions(-)
diff --git a/MonitorControl/AppDelegate.swift b/MonitorControl/AppDelegate.swift
index 201096b..a3a4e7e 100644
--- a/MonitorControl/AppDelegate.swift
+++ b/MonitorControl/AppDelegate.swift
@@ -18,7 +18,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let coreAudio = SimplyCoreAudio()
var accessibilityObserver: NSObjectProtocol!
var willReconfigureDisplay: Bool = false // A reconfigure display command is already dispatched
- var displaySleep: Bool = false // Don't reconfigure display as the system or display is sleeping or wake just recently.
+ var displaySleep: Int = 0 // Don't reconfigure display as the system or display is sleeping or wake just recently.
lazy var preferencesWindowController: PreferencesWindowController = {
let storyboard = NSStoryboard(name: "Main", bundle: Bundle.main)
let mainPrefsVc = storyboard.instantiateController(withIdentifier: "MainPrefsVC") as? MainPrefsViewController
@@ -39,20 +39,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.subscribeEventListeners()
self.setDefaultPrefs()
self.updateMediaKeyTap()
- if prefs.bool(forKey: Utils.PrefKeys.hideMenuIcon.rawValue) {
- self.statusItem.isVisible = false
- } else {
- self.statusItem.isVisible = true
- }
- defer {
- self.statusItem.isVisible = true
- }
if #available(macOS 11.0, *) {
self.statusItem.button?.image = NSImage(systemSymbolName: "sun.max", accessibilityDescription: "MonitorControl")
} else {
self.statusItem.button?.image = NSImage(named: "status")
- self.statusItem.isVisible = false
}
+ self.statusItem.isVisible = prefs.bool(forKey: Utils.PrefKeys.hideMenuIcon.rawValue) ? false : true
self.statusItem.menu = self.statusMenu
self.checkPermissions()
CGDisplayRegisterReconfigurationCallback({ _, _, _ in app.displayReconfigured() }, nil)
@@ -64,8 +56,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return true
}
- func applicationWillTerminate(_: Notification) {
- os_log("Goodbye!", type: .info)
+ func resetContrastAfterBrightness() {
for externalDisplay in DisplayManager.shared.getExternalDisplays() where externalDisplay.isContrastAfterBrightnessMode {
let contrastRestoreValue = externalDisplay.getRestoreValue(for: .contrast)
guard externalDisplay.writeDDCValues(command: .contrast, value: UInt16(contrastRestoreValue)) == true else {
@@ -73,6 +64,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
externalDisplay.saveValue(contrastRestoreValue, for: .contrast)
}
+ }
+
+ func applicationWillTerminate(_: Notification) {
+ os_log("Goodbye!", type: .info)
+ self.resetContrastAfterBrightness()
self.statusItem.isVisible = true
}
@@ -159,7 +155,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
func displayReconfigured() {
- if !self.willReconfigureDisplay, !self.displaySleep {
+ if !self.willReconfigureDisplay, self.displaySleep == 0 {
self.willReconfigureDisplay = true
os_log("Display to be reconfigured via updateDisplay in 2 seconds", type: .info)
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
@@ -169,7 +165,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
func updateDisplays() {
- guard !self.displaySleep else {
+ guard self.displaySleep == 0 else {
return
}
os_log("Request for updateDisplay", type: .info)
@@ -290,24 +286,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
@objc private func sleepNotification() {
- if !self.displaySleep {
- os_log("Sleeping...zZz.", type: .info)
- self.displaySleep = true
- }
+ self.displaySleep += 1
+ os_log("Sleeping with sleep %{public}@", type: .info, String(self.displaySleep))
}
@objc private func wakeNotofication() {
- os_log("Wake up!", type: .info)
- DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { // Some displays take time to recover...
- self.soberNow()
+ if self.displaySleep != 0 {
+ os_log("Waking up from sleep %{public}@", type: .info, String(self.displaySleep))
+ let sleepID = self.displaySleep
+ DispatchQueue.main.asyncAfter(deadline: .now() + 6.0) { // Some displays take time to recover...
+ self.soberNow(sleepID: sleepID)
+ }
}
}
- private func soberNow() {
- if self.displaySleep {
- os_log("Sober now!", type: .info)
- self.displaySleep = false
- self.displayReconfigured()
+ private func soberNow(sleepID: Int) {
+ if self.displaySleep == sleepID {
+ os_log("Sober from sleep %{public}@", type: .info, String(self.displaySleep))
+ self.displaySleep = 0
+ self.updateDisplays()
}
}
@@ -348,7 +345,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
extension AppDelegate: MediaKeyTapDelegate {
func handle(mediaKey: MediaKey, event: KeyEvent?, modifiers: NSEvent.ModifierFlags?) {
- guard !self.displaySleep && !self.willReconfigureDisplay else {
+ guard self.displaySleep == 0 && !self.willReconfigureDisplay else {
return
}
if self.handleOpenPrefPane(mediaKey: mediaKey, event: event, modifiers: modifiers) {
@@ -379,7 +376,7 @@ extension AppDelegate: MediaKeyTapDelegate {
}
private func sendDisplayCommand(mediaKey: MediaKey, isRepeat: Bool, isSmallIncrement: Bool) {
- guard !self.displaySleep, !self.willReconfigureDisplay else {
+ guard self.displaySleep == 0, !self.willReconfigureDisplay else {
return
}
let displays = DisplayManager.shared.getAllDisplays()
@@ -443,6 +440,7 @@ extension AppDelegate: MediaKeyTapDelegate {
self.updateDisplays()
self.checkPermissions()
self.updateMediaKeyTap()
+ self.resetContrastAfterBrightness()
}
private func updateMediaKeyTap() {
diff --git a/MonitorControl/Extensions/Preferences+Extension.swift b/MonitorControl/Extensions/Preferences+Extension.swift
index bf3f4a6..84250ad 100644
--- a/MonitorControl/Extensions/Preferences+Extension.swift
+++ b/MonitorControl/Extensions/Preferences+Extension.swift
@@ -10,7 +10,6 @@ import Preferences
extension Preferences.PaneIdentifier {
static let main = Self("Main")
- static let keys = Self("Keys")
static let advanced = Self("Advanced")
static let display = Self("Display")
}
diff --git a/MonitorControl/Info.plist b/MonitorControl/Info.plist
index 9f4a999..0811cdb 100644
--- a/MonitorControl/Info.plist
+++ b/MonitorControl/Info.plist
@@ -19,7 +19,7 @@
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
- 1629
+ 1657
LSApplicationCategoryType
public.app-category.utilities
LSMinimumSystemVersion
diff --git a/MonitorControl/UI/SliderHandler.swift b/MonitorControl/UI/SliderHandler.swift
index 80fb17c..328ac93 100644
--- a/MonitorControl/UI/SliderHandler.swift
+++ b/MonitorControl/UI/SliderHandler.swift
@@ -37,7 +37,7 @@ class SliderHandler {
}
}
- guard !app.displaySleep, !app.willReconfigureDisplay else {
+ guard app.displaySleep == 0, !app.willReconfigureDisplay else {
return
}
diff --git a/MonitorControl/UI/de.lproj/Main.strings b/MonitorControl/UI/de.lproj/Main.strings
index 31d4190..5d69cae 100644
--- a/MonitorControl/UI/de.lproj/Main.strings
+++ b/MonitorControl/UI/de.lproj/Main.strings
@@ -38,7 +38,7 @@
"FoA-yh-Yx3.title" = "Aus";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "Warnung ⚠️\nDas Ändern dieser Einstellungen kann zum Einfrieren des Systems oder unerwartetem Verhalten führen.";
+"frw-j2-tE1.title" = "⚠️ Warnung! Das Ändern dieser Einstellungen kann zum Einfrieren des Systems oder unerwartetem Verhalten führen.";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "Verzögerung";
diff --git a/MonitorControl/UI/fr.lproj/Main.strings b/MonitorControl/UI/fr.lproj/Main.strings
index 2b30e1c..47fb211 100644
--- a/MonitorControl/UI/fr.lproj/Main.strings
+++ b/MonitorControl/UI/fr.lproj/Main.strings
@@ -38,7 +38,7 @@
"FoA-yh-Yx3.title" = "None";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "Warning ⚠️\nChanging some of these setting may cause system freezes or unexpected behaviour. ";
+"frw-j2-tE1.title" = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. ";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "Longer Delay";
diff --git a/MonitorControl/UI/hu.lproj/Main.strings b/MonitorControl/UI/hu.lproj/Main.strings
index b9ab28e..0c7012c 100644
--- a/MonitorControl/UI/hu.lproj/Main.strings
+++ b/MonitorControl/UI/hu.lproj/Main.strings
@@ -38,7 +38,7 @@
"FoA-yh-Yx3.title" = "Nincs";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "Figyelem ⚠️\nAz alábbi beállítások megváltoztatása lefagyást vagy váratlan működést eredményezhet!";
+"frw-j2-tE1.title" = "⚠️ Figyelem! Az alábbi beállítások megváltoztatása lefagyást vagy váratlan működést eredményezhet!";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "Hosszabb várakozás";
@@ -47,7 +47,7 @@
"gxn-NH-Qhb.headerCell.title" = "Mintavételezési mód";
/* Class = "NSTextFieldCell"; title = "Brightness keys:"; ObjectID = "hdd-Zz-buN"; */
-"hdd-Zz-buN.title" = "Brightness keys:";
+"hdd-Zz-buN.title" = "Fényerő billentyűk:";
/* Class = "NSMenuItem"; title = "Brightness only"; ObjectID = "hjz-0c-rvK"; */
"hjz-0c-rvK.title" = "Csak a fényerő billentyűk";
@@ -59,7 +59,7 @@
"JKW-oY-bSb.headerCell.title" = "Azonosító";
/* Class = "NSTextFieldCell"; title = "You can control the Brighness and Volume of your display using the Brightness and Volume keys off Apple Keyboards."; ObjectID = "K2r-aD-eec"; */
-"K2r-aD-eec.title" = "You can control the Brighness and Volume of your display using the Brightness and Volume keys off Apple Keyboards.";
+"K2r-aD-eec.title" = "A képernyő fényerejét és hangerejét az Apple Billentyűzet fényerő és hangerő gombjaival lehet szabályozni.";
/* Class = "NSButton"; ibShadowedToolTip = "More Info"; ObjectID = "kqn-gU-mZX"; */
"kqn-gU-mZX.ibShadowedToolTip" = "További információ";
@@ -83,7 +83,7 @@
"Nvp-hI-w4x.headerCell.title" = "Modell";
/* Class = "NSTextFieldCell"; title = "Application:"; ObjectID = "okD-DG-pYa"; */
-"okD-DG-pYa.title" = "Application:";
+"okD-DG-pYa.title" = "Alkalmazás:";
/* Class = "NSTextFieldCell"; title = "If Menu is hidden, just relaunch the app to reveal Preferences!"; ObjectID = "PVE-y7-zIk"; */
"PVE-y7-zIk.title" = "Ha rejtett, indítsa el újra az alkalmazást a beállítások megnyitásához!";
diff --git a/MonitorControl/UI/it.lproj/Main.strings b/MonitorControl/UI/it.lproj/Main.strings
index 4ffa2c4..52193a1 100644
--- a/MonitorControl/UI/it.lproj/Main.strings
+++ b/MonitorControl/UI/it.lproj/Main.strings
@@ -38,7 +38,7 @@
"FoA-yh-Yx3.title" = "None";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "Warning ⚠️\nChanging some of these setting may cause system freezes or unexpected behaviour. ";
+"frw-j2-tE1.title" = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. ";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "Longer Delay";
diff --git a/MonitorControl/UI/ja.lproj/Main.strings b/MonitorControl/UI/ja.lproj/Main.strings
index fdb4353..e7eac66 100644
--- a/MonitorControl/UI/ja.lproj/Main.strings
+++ b/MonitorControl/UI/ja.lproj/Main.strings
@@ -47,7 +47,7 @@
"FoA-yh-Yx3.title" = "設定しない";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "⚠️ 注意 ⚠️\n下の設定を変更するとMacがフリーズしたり予期せぬ挙動になる場合があります。";
+"frw-j2-tE1.title" = "⚠️ 注意 下の設定を変更するとMacがフリーズしたり予期せぬ挙動になる場合があります。";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "遅延を長くする";
diff --git a/MonitorControl/UI/pl.lproj/Main.strings b/MonitorControl/UI/pl.lproj/Main.strings
index b11abe5..aa55eb7 100644
--- a/MonitorControl/UI/pl.lproj/Main.strings
+++ b/MonitorControl/UI/pl.lproj/Main.strings
@@ -41,7 +41,7 @@
"FoA-yh-Yx3.title" = "Nikt";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "Uwaga ⚠️\nZmiana niektórych z tych ustawień może spowodować zawieszenia systemu lub nieoczekiwane zachowanie.";
+"frw-j2-tE1.title" = "⚠️ Uwaga! Zmiana niektórych z tych ustawień może spowodować zawieszenia systemu lub nieoczekiwane zachowanie.";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "Dłuższe opóźnienie";
diff --git a/MonitorControl/UI/ru.lproj/Main.strings b/MonitorControl/UI/ru.lproj/Main.strings
index 019085f..3c6bd55 100644
--- a/MonitorControl/UI/ru.lproj/Main.strings
+++ b/MonitorControl/UI/ru.lproj/Main.strings
@@ -38,7 +38,7 @@
"FoA-yh-Yx3.title" = "Нет";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "Внимание ⚠️\nИзменение некоторых из этих настроек может привести к зависанию системы или неожиданному поведению.";
+"frw-j2-tE1.title" = "⚠️ Внимание! Изменение некоторых из этих настроек может привести к зависанию системы или неожиданному поведению.";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "Длительный опрос";
diff --git a/MonitorControl/UI/uk.lproj/Main.strings b/MonitorControl/UI/uk.lproj/Main.strings
index 639db4b..77014da 100644
--- a/MonitorControl/UI/uk.lproj/Main.strings
+++ b/MonitorControl/UI/uk.lproj/Main.strings
@@ -38,7 +38,7 @@
"FoA-yh-Yx3.title" = "Немає";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "Увага! ⚠️\nЗміна деяких із цих налаштувань може привести до зависання системи або неочікуванних наслідків.";
+"frw-j2-tE1.title" = "⚠️ Увага! Зміна деяких із цих налаштувань може привести до зависання системи або неочікуванних наслідків.";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "Затримка";
diff --git a/MonitorControl/UI/zh-Hans.lproj/Main.strings b/MonitorControl/UI/zh-Hans.lproj/Main.strings
index 408aeb8..e0c3b7f 100644
--- a/MonitorControl/UI/zh-Hans.lproj/Main.strings
+++ b/MonitorControl/UI/zh-Hans.lproj/Main.strings
@@ -38,7 +38,7 @@
"FoA-yh-Yx3.title" = "不请求";
/* Class = "NSTextFieldCell"; title = "⚠️ Warning! Changing some of these setting may cause system freezes or unexpected behaviour. "; ObjectID = "frw-j2-tE1"; */
-"frw-j2-tE1.title" = "警告 ⚠️\n更改这些设置可能会导致系统冻结或者其它的意外情况。";
+"frw-j2-tE1.title" = "⚠️ 警告 更改这些设置可能会导致系统冻结或者其它的意外情况。";
/* Class = "NSTableColumn"; headerCell.title = "Longer Delay"; ObjectID = "grO-Kr-l4d"; */
"grO-Kr-l4d.headerCell.title" = "增加延时";
diff --git a/MonitorControl/View Controllers/AdvancedPrefsViewController.swift b/MonitorControl/View Controllers/AdvancedPrefsViewController.swift
index d7f07e5..8787495 100644
--- a/MonitorControl/View Controllers/AdvancedPrefsViewController.swift
+++ b/MonitorControl/View Controllers/AdvancedPrefsViewController.swift
@@ -48,10 +48,11 @@ class AdvancedPrefsViewController: NSViewController, PreferencePane, NSTableView
alert.addButton(withTitle: NSLocalizedString("Yes", comment: "Shown in the alert dialog"))
alert.addButton(withTitle: NSLocalizedString("No", comment: "Shown in the alert dialog"))
alert.alertStyle = NSAlert.Style.warning
-
if let window = self.view.window {
alert.beginSheetModal(for: window, completionHandler: { modalResponse in
if modalResponse == NSApplication.ModalResponse.alertFirstButtonReturn {
+ app.resetContrastAfterBrightness()
+ app.statusItem.isVisible = true
if let bundleID = Bundle.main.bundleIdentifier {
UserDefaults.standard.removePersistentDomain(forName: bundleID)
NotificationCenter.default.post(name: Notification.Name(Utils.PrefKeys.preferenceReset.rawValue), object: nil)
diff --git a/MonitorControl/View Controllers/MainPrefsViewController.swift b/MonitorControl/View Controllers/MainPrefsViewController.swift
index 38b6a3c..e4336e9 100644
--- a/MonitorControl/View Controllers/MainPrefsViewController.swift
+++ b/MonitorControl/View Controllers/MainPrefsViewController.swift
@@ -54,16 +54,14 @@ class MainPrefsViewController: NSViewController, PreferencePane {
}
@IBAction func hideMenuIconClicked(_ sender: NSButton) {
- if let delegate = (NSApplication.shared.delegate) as? AppDelegate {
- switch sender.state {
- case .on:
- self.prefs.set(true, forKey: Utils.PrefKeys.hideMenuIcon.rawValue)
- delegate.statusItem.isVisible = false
- case .off:
- self.prefs.set(false, forKey: Utils.PrefKeys.hideMenuIcon.rawValue)
- delegate.statusItem.isVisible = true
- default: break
- }
+ switch sender.state {
+ case .on:
+ self.prefs.set(true, forKey: Utils.PrefKeys.hideMenuIcon.rawValue)
+ app.statusItem.isVisible = false
+ case .off:
+ self.prefs.set(false, forKey: Utils.PrefKeys.hideMenuIcon.rawValue)
+ app.statusItem.isVisible = true
+ default: break
}
}
@@ -115,6 +113,7 @@ class MainPrefsViewController: NSViewController, PreferencePane {
NotificationCenter.default.post(name: Notification.Name(Utils.PrefKeys.showContrast.rawValue), object: nil)
case .off:
self.prefs.set(false, forKey: Utils.PrefKeys.lowerContrast.rawValue)
+ app.resetContrastAfterBrightness()
default: break
}
#if DEBUG
diff --git a/MonitorControlHelper/Info.plist b/MonitorControlHelper/Info.plist
index 57f6ac4..2519862 100644
--- a/MonitorControlHelper/Info.plist
+++ b/MonitorControlHelper/Info.plist
@@ -19,7 +19,7 @@
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
- 1629
+ 1657
LSApplicationCategoryType
public.app-category.utilities
LSBackgroundOnly