diff --git a/ModuleKit/Widgets/Battery.swift b/ModuleKit/Widgets/Battery.swift index ffe6190c..da91ebc7 100644 --- a/ModuleKit/Widgets/Battery.swift +++ b/ModuleKit/Widgets/Battery.swift @@ -17,6 +17,7 @@ public class BatterykWidget: Widget { private var timeFormat: String = "short" private var iconState: Bool = true private var colorState: Bool = false + private var hideAdditionalWhenFull: Bool = true private let store: UnsafePointer? @@ -32,13 +33,14 @@ public class BatterykWidget: Widget { self.title = widgetTitle self.type = .battery self.preview = preview - self.canDrawConcurrently = true + self.wantsLayer = true if self.store != nil { self.additional = store!.pointee.string(key: "\(self.title)_\(self.type.rawValue)_additional", defaultValue: self.additional) self.timeFormat = store!.pointee.string(key: "\(self.title)_timeFormat", defaultValue: self.timeFormat) self.iconState = store!.pointee.bool(key: "\(self.title)_\(self.type.rawValue)_icon", defaultValue: self.iconState) self.colorState = store!.pointee.bool(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState) + self.hideAdditionalWhenFull = store!.pointee.bool(key: "\(self.title)_\(self.type.rawValue)_hideAdditionalWhenFull", defaultValue: self.hideAdditionalWhenFull) } if self.preview { @@ -60,38 +62,40 @@ public class BatterykWidget: Widget { var x: CGFloat = Constants.Widget.margin+1 let isShortTimeFormat: Bool = self.timeFormat == "short" - switch self.additional { - case "percentage": - let rowWidth = self.drawOneRow( - value: "\(Int((self.percentage.rounded(toPlaces: 2)) * 100))%", - x: x - ).rounded(.up) - width += rowWidth + Constants.Widget.margin - x += rowWidth + Constants.Widget.margin - case "time": - let rowWidth = self.drawOneRow( - value: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat), - x: x - ).rounded(.up) - width += rowWidth + Constants.Widget.margin - x += rowWidth + Constants.Widget.margin - case "percentageAndTime": - let rowWidth = self.drawTwoRows( - first: "\(Int((self.percentage.rounded(toPlaces: 2)) * 100))%", - second: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat), - x: x - ).rounded(.up) - width += rowWidth + Constants.Widget.margin - x += rowWidth + Constants.Widget.margin - case "timeAndPercentage": - let rowWidth = self.drawTwoRows( - first: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat), - second: "\(Int((self.percentage.rounded(toPlaces: 2)) * 100))%", - x: x - ).rounded(.up) - width += rowWidth + Constants.Widget.margin - x += rowWidth + Constants.Widget.margin - default: break + if !self.hideAdditionalWhenFull || (self.hideAdditionalWhenFull && self.percentage != 1) { + switch self.additional { + case "percentage": + let rowWidth = self.drawOneRow( + value: "\(Int((self.percentage.rounded(toPlaces: 2)) * 100))%", + x: x + ).rounded(.up) + width += rowWidth + Constants.Widget.margin + x += rowWidth + Constants.Widget.margin + case "time": + let rowWidth = self.drawOneRow( + value: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat), + x: x + ).rounded(.up) + width += rowWidth + Constants.Widget.margin + x += rowWidth + Constants.Widget.margin + case "percentageAndTime": + let rowWidth = self.drawTwoRows( + first: "\(Int((self.percentage.rounded(toPlaces: 2)) * 100))%", + second: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat), + x: x + ).rounded(.up) + width += rowWidth + Constants.Widget.margin + x += rowWidth + Constants.Widget.margin + case "timeAndPercentage": + let rowWidth = self.drawTwoRows( + first: Double(self.time*60).printSecondsToHoursMinutesSeconds(short: isShortTimeFormat), + second: "\(Int((self.percentage.rounded(toPlaces: 2)) * 100))%", + x: x + ).rounded(.up) + width += rowWidth + Constants.Widget.margin + x += rowWidth + Constants.Widget.margin + default: break + } } let w: CGFloat = 28 - (Constants.Widget.margin*2) - 4 @@ -245,19 +249,31 @@ public class BatterykWidget: Widget { public override func settings(superview: NSView) { let rowHeight: CGFloat = 30 - let height: CGFloat = ((rowHeight + Constants.Settings.margin) * 2) + Constants.Settings.margin + let height: CGFloat = ((rowHeight + Constants.Settings.margin) * 3) + Constants.Settings.margin superview.setFrameSize(NSSize(width: superview.frame.width, height: height)) - let view: NSView = NSView(frame: NSRect(x: Constants.Settings.margin, y: Constants.Settings.margin, width: superview.frame.width - (Constants.Settings.margin*2), height: superview.frame.height - (Constants.Settings.margin*2))) + let view: NSView = NSView(frame: NSRect( + x: Constants.Settings.margin, + y: Constants.Settings.margin, + width: superview.frame.width - (Constants.Settings.margin*2), + height: superview.frame.height - (Constants.Settings.margin*2) + )) view.addSubview(SelectRow( - frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 1, width: view.frame.width, height: rowHeight), + frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 2, width: view.frame.width, height: rowHeight), title: LocalizedString("Additional information"), action: #selector(toggleAdditional), items: BatteryAdditionals, selected: self.additional )) + view.addSubview(ToggleTitleRow( + frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 1, width: view.frame.width, height: rowHeight), + title: LocalizedString("Hide additional information when full"), + action: #selector(toggleHideAdditionalWhenFull), + state: self.hideAdditionalWhenFull + )) + view.addSubview(ToggleTitleRow( frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 0, width: view.frame.width, height: rowHeight), title: LocalizedString("Colorize"), @@ -277,6 +293,18 @@ public class BatterykWidget: Widget { self.display() } + @objc private func toggleHideAdditionalWhenFull(_ sender: NSControl) { + var state: NSControl.StateValue? = nil + if #available(OSX 10.15, *) { + state = sender is NSSwitch ? (sender as! NSSwitch).state: nil + } else { + state = sender is NSButton ? (sender as! NSButton).state: nil + } + self.hideAdditionalWhenFull = state! == .on ? true : false + self.store?.pointee.set(key: "\(self.title)_\(self.type.rawValue)_hideAdditionalWhenFull", value: self.hideAdditionalWhenFull) + self.display() + } + @objc private func toggleColor(_ sender: NSControl) { var state: NSControl.StateValue? = nil if #available(OSX 10.15, *) { diff --git a/Stats/Supporting Files/de.lproj/Localizable.strings b/Stats/Supporting Files/de.lproj/Localizable.strings index 4d8d0925..eae8bf47 100644 --- a/Stats/Supporting Files/de.lproj/Localizable.strings +++ b/Stats/Supporting Files/de.lproj/Localizable.strings @@ -160,3 +160,4 @@ "Percentage and time" = "Prozentsatz und Zeit"; "Time and percentage" = "Zeit und Prozentsatz"; "Time format" = "Zeitformat"; +"Hide additional information when full" = "Verstecken Zusätzliche Informationen, wenn der Akku voll ist"; diff --git a/Stats/Supporting Files/en.lproj/Localizable.strings b/Stats/Supporting Files/en.lproj/Localizable.strings index fe2d0b7f..ea13a090 100644 --- a/Stats/Supporting Files/en.lproj/Localizable.strings +++ b/Stats/Supporting Files/en.lproj/Localizable.strings @@ -161,3 +161,4 @@ "Percentage and time" = "Percentage and time"; "Time and percentage" = "Time and percentage"; "Time format" = "Time format"; +"Hide additional information when full" = "Hide additional information when full"; diff --git a/Stats/Supporting Files/es.lproj/Localizable.strings b/Stats/Supporting Files/es.lproj/Localizable.strings index be56c325..e6e01690 100644 --- a/Stats/Supporting Files/es.lproj/Localizable.strings +++ b/Stats/Supporting Files/es.lproj/Localizable.strings @@ -157,3 +157,4 @@ "Percentage and time" = "Porcentaje y tiempo"; "Time and percentage" = "Tiempo y porcentaje"; "Time format" = "Formato de tiempo"; +"Hide additional information when full" = "Ocultar información adicional cuando la batería está llena"; diff --git a/Stats/Supporting Files/fr.lproj/Localizable.strings b/Stats/Supporting Files/fr.lproj/Localizable.strings index 9d7b4f98..fb88bc2b 100644 --- a/Stats/Supporting Files/fr.lproj/Localizable.strings +++ b/Stats/Supporting Files/fr.lproj/Localizable.strings @@ -160,3 +160,4 @@ "Percentage and time" = "Pourcentage et temps"; "Time and percentage" = "Temps et pourcentage"; "Time format" = "Format de l'heure"; +"Hide additional information when full" = "Masquer les informations supplémentaires lorsque la batterie est pleine"; diff --git a/Stats/Supporting Files/ko.lproj/Localizable.strings b/Stats/Supporting Files/ko.lproj/Localizable.strings index 96d9eedb..89c83683 100644 --- a/Stats/Supporting Files/ko.lproj/Localizable.strings +++ b/Stats/Supporting Files/ko.lproj/Localizable.strings @@ -160,3 +160,4 @@ "Percentage and time" = "비율과 시간"; "Time and percentage" = "시간과 비율"; "Time format" = "시간 형식"; +"Hide additional information when full" = "배터리가 가득 차면 추가 정보 숨기기"; diff --git a/Stats/Supporting Files/pl.lproj/Localizable.strings b/Stats/Supporting Files/pl.lproj/Localizable.strings index 8e677130..6966d760 100644 --- a/Stats/Supporting Files/pl.lproj/Localizable.strings +++ b/Stats/Supporting Files/pl.lproj/Localizable.strings @@ -161,3 +161,4 @@ "Percentage and time" = "Procenty i czas"; "Time and percentage" = "Czas i procenty"; "Time format" = "Format czasu"; +"Hide additional information when full" = "Ukryj dodatkowe informacje, gdy bateria jest naładowana"; diff --git a/Stats/Supporting Files/ru.lproj/Localizable.strings b/Stats/Supporting Files/ru.lproj/Localizable.strings index bb9c9614..88d2731d 100644 --- a/Stats/Supporting Files/ru.lproj/Localizable.strings +++ b/Stats/Supporting Files/ru.lproj/Localizable.strings @@ -161,3 +161,4 @@ "Percentage and time" = "Проценты и время"; "Time and percentage" = "Время и Проценты"; "Time format" = "Формат времени"; +"Hide additional information when full" = "Скрыть дополнительную информацию при полном заряде"; diff --git a/Stats/Supporting Files/tr.lproj/Localizable.strings b/Stats/Supporting Files/tr.lproj/Localizable.strings index f3ec1862..823b62fe 100644 --- a/Stats/Supporting Files/tr.lproj/Localizable.strings +++ b/Stats/Supporting Files/tr.lproj/Localizable.strings @@ -160,3 +160,4 @@ "Percentage and time" = "Yüzde ve zaman"; "Time and percentage" = "Zaman ve yüzde"; "Time format" = "Zaman formatı"; +"Hide additional information when full" = "Pil dolduğunda ek bilgileri gizle"; diff --git a/Stats/Supporting Files/uk.lproj/Localizable.strings b/Stats/Supporting Files/uk.lproj/Localizable.strings index 5888895d..400fac27 100644 --- a/Stats/Supporting Files/uk.lproj/Localizable.strings +++ b/Stats/Supporting Files/uk.lproj/Localizable.strings @@ -161,3 +161,4 @@ "Percentage and time" = "Проценти і час"; "Time and percentage" = "Час і проценти"; "Time format" = "Формат часу"; +"Hide additional information when full" = "Приховати додаткову інформацію, якщо акумулятор заряджений"; diff --git a/Stats/Supporting Files/vi.lproj/Localizable.strings b/Stats/Supporting Files/vi.lproj/Localizable.strings index 277da09e..33909949 100644 --- a/Stats/Supporting Files/vi.lproj/Localizable.strings +++ b/Stats/Supporting Files/vi.lproj/Localizable.strings @@ -160,3 +160,4 @@ "Percentage and time" = "Phần trăm và thời gian"; "Time and percentage" = "Thời gian và tỷ lệ phần trăm"; "Time format" = "Định dạng thời gian"; +"Hide additional information when full" = "Ẩn thông tin bổ sung khi pin đầy"; diff --git a/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings b/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings index 62fa9a0d..2457c8a6 100644 --- a/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings +++ b/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings @@ -160,3 +160,4 @@ "Percentage and time" = "百分比和时间"; "Time and percentage" = "时间和百分比"; "Time format" = "时间格式"; +"Hide additional information when full" = "电池充满后隐藏其他信息"; diff --git a/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings b/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings index 7751a31d..b4f0c476 100644 --- a/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings +++ b/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings @@ -156,3 +156,4 @@ "Percentage and time" = "百分比和時間"; "Time and percentage" = "時間和百分比"; "Time format" = "時間格式"; +"Hide additional information when full" = "電池充滿後隱藏其他信息";