From 85742785e76338450bd22e1326a19367cf9f326a Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Tue, 3 Nov 2020 21:10:03 +0100 Subject: [PATCH] - fix app crash when start (#136) (font bug) --- ModuleKit/Widgets/Sensors.swift | 32 ++++++++----------- Modules/Disk/Bridge.h | 17 ---------- Modules/Fans/main.swift | 4 +-- Modules/Fans/readers.swift | 4 +-- Modules/Sensors/main.swift | 6 +--- Stats.xcodeproj/project.pbxproj | 10 +++--- Stats/Supporting Files/Info.plist | 2 +- .../pl.lproj/Localizable.strings | 2 +- 8 files changed, 25 insertions(+), 52 deletions(-) delete mode 100644 Modules/Disk/Bridge.h diff --git a/ModuleKit/Widgets/Sensors.swift b/ModuleKit/Widgets/Sensors.swift index 0e8db024..56333226 100644 --- a/ModuleKit/Widgets/Sensors.swift +++ b/ModuleKit/Widgets/Sensors.swift @@ -75,12 +75,12 @@ public class SensorsWidget: Widget { while i < self.values.count { switch self.modeState { case "automatic", "twoRows": - let firstSensor: SensorValue_t? = self.values[i] + let firstSensor: SensorValue_t = self.values[i] let secondSensor: SensorValue_t? = self.values.indices.contains(i+1) ? self.values[i+1] : nil var width: CGFloat = 0 if self.modeState == "automatic" && secondSensor == nil { - width += self.drawOneRow(firstSensor!, x: x) + width += self.drawOneRow(firstSensor, x: x) } else { width += self.drawTwoRows(topSensor: firstSensor, bottomSensor: secondSensor, x: x) } @@ -145,25 +145,22 @@ public class SensorsWidget: Widget { return width } - private func drawTwoRows(topSensor: SensorValue_t?, bottomSensor: SensorValue_t?, x: CGFloat) -> CGFloat { + private func drawTwoRows(topSensor: SensorValue_t, bottomSensor: SensorValue_t?, x: CGFloat) -> CGFloat { var width: CGFloat = 0 var paddingLeft: CGFloat = 0 let rowHeight: CGFloat = self.frame.height / 2 - var font: NSFont = NSFont.systemFont(ofSize: 9, weight: .light) - if #available(OSX 10.15, *) { - font = NSFont.monospacedSystemFont(ofSize: 9, weight: .light) - } + let font: NSFont = NSFont.systemFont(ofSize: 9, weight: .light) let style = NSMutableParagraphStyle() style.alignment = .right - let firstRowWidth = topSensor?.value.widthOfString(usingFont: font) + let firstRowWidth = topSensor.value.widthOfString(usingFont: font) let secondRowWidth = bottomSensor?.value.widthOfString(usingFont: font) - width = max(20, max(firstRowWidth ?? 0, secondRowWidth ?? 0)).rounded(.up) + width = max(20, max(firstRowWidth, secondRowWidth ?? 0)).rounded(.up) - if self.iconState && (topSensor?.icon != nil || bottomSensor?.icon != nil) { + if self.iconState && (topSensor.icon != nil || bottomSensor?.icon != nil) { let iconSize: CGFloat = 8 - if let icon = topSensor?.icon { + if let icon = topSensor.icon { icon.draw(in: NSRect(x: x, y: rowHeight+((rowHeight-iconSize)/2), width: iconSize, height: iconSize)) } if let icon = bottomSensor?.icon { @@ -180,15 +177,13 @@ public class SensorsWidget: Widget { NSAttributedString.Key.paragraphStyle: style ] - if topSensor != nil { - let rect = CGRect(x: x+paddingLeft, y: rowHeight+1, width: width-paddingLeft, height: rowHeight) - let str = NSAttributedString.init(string: topSensor!.value, attributes: attributes) - str.draw(with: rect) - } + var rect = CGRect(x: x+paddingLeft, y: rowHeight+1, width: width-paddingLeft, height: rowHeight) + var str = NSAttributedString.init(string: topSensor.value, attributes: attributes) + str.draw(with: rect) if bottomSensor != nil { - let rect = CGRect(x: x+paddingLeft, y: 1, width: width-paddingLeft, height: rowHeight) - let str = NSAttributedString.init(string: bottomSensor!.value, attributes: attributes) + rect = CGRect(x: x+paddingLeft, y: 1, width: width-paddingLeft, height: rowHeight) + str = NSAttributedString.init(string: bottomSensor!.value, attributes: attributes) str.draw(with: rect) } @@ -246,5 +241,6 @@ public class SensorsWidget: Widget { } self.modeState = key store?.pointee.set(key: "\(self.title)_\(self.type.rawValue)_mode", value: key) + self.display() } } diff --git a/Modules/Disk/Bridge.h b/Modules/Disk/Bridge.h deleted file mode 100644 index d04b8b2c..00000000 --- a/Modules/Disk/Bridge.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// Bridge.h -// Disk -// -// Created by Serhiy Mytrovtsiy on 07/08/2020. -// Using Swift 5.0. -// Running on macOS 10.15. -// -// Copyright © 2020 Serhiy Mytrovtsiy. All rights reserved. -// - -#ifndef Bridge_h -#define Bridge_h - -#include - -#endif /* Bridge_h */ diff --git a/Modules/Fans/main.swift b/Modules/Fans/main.swift index a549c4e9..5df87bc3 100644 --- a/Modules/Fans/main.swift +++ b/Modules/Fans/main.swift @@ -76,7 +76,7 @@ public class Fans: Module { } public override func isAvailable() -> Bool { - return smc.pointee.getValue("FNum") != nil && smc.pointee.getValue("FNum") != 0 + return smc.pointee.getValue("FNum") != nil && smc.pointee.getValue("FNum") != 0 && !self.fansReader.list.isEmpty } private func checkIfNoSensorsEnabled() { @@ -97,7 +97,7 @@ public class Fans: Module { value!.forEach { (f: Fan) in if let value = f.formattedValue, f.state { let str = label ? "\(f.name.prefix(1).uppercased()): \(value)" : value - list.append(SensorValue_t(str, icon: Bundle(identifier: "eu.exelban.Stats.ModuleKit")?.image(forResource: "fan"))) + list.append(SensorValue_t(str)) } } diff --git a/Modules/Fans/readers.swift b/Modules/Fans/readers.swift index 42813cab..1d2aa20d 100644 --- a/Modules/Fans/readers.swift +++ b/Modules/Fans/readers.swift @@ -31,8 +31,8 @@ internal class FansReader: Reader<[Fan]> { self.list.append(Fan( id: i, name: smc.pointee.getStringValue("F\(i)ID") ?? "Fan #\(i)", - minSpeed: smc.pointee.getValue("F\(i)Mn") ?? 0, - maxSpeed: smc.pointee.getValue("F\(i)Mx") ?? 0, + minSpeed: smc.pointee.getValue("F\(i)Mn") ?? 1, + maxSpeed: smc.pointee.getValue("F\(i)Mx") ?? 1, value: smc.pointee.getValue("F\(i)Ac") )) } diff --git a/Modules/Sensors/main.swift b/Modules/Sensors/main.swift index 391ab71a..0ad7b19b 100644 --- a/Modules/Sensors/main.swift +++ b/Modules/Sensors/main.swift @@ -64,11 +64,7 @@ public class Sensors: Module { var list: [SensorValue_t] = [] value!.forEach { (s: Sensor_t) in if s.state { - var icon: NSImage? = nil - if s.type == SensorType.Temperature.rawValue { - icon = Bundle(identifier: "eu.exelban.Stats.ModuleKit")?.image(forResource: "temperature") - } - list.append(SensorValue_t(s.formattedMiniValue, icon: icon)) + list.append(SensorValue_t(s.formattedMiniValue)) } } diff --git a/Stats.xcodeproj/project.pbxproj b/Stats.xcodeproj/project.pbxproj index 39d754dd..506999a6 100644 --- a/Stats.xcodeproj/project.pbxproj +++ b/Stats.xcodeproj/project.pbxproj @@ -1924,7 +1924,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 127; DEVELOPMENT_TEAM = RP2S87B72W; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -1938,7 +1938,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 2.4.0; + MARKETING_VERSION = 2.4.1; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1957,7 +1957,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 127; DEVELOPMENT_TEAM = RP2S87B72W; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -1971,7 +1971,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; - MARKETING_VERSION = 2.4.0; + MARKETING_VERSION = 2.4.1; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2557,7 +2557,6 @@ PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats.Disk; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; - SWIFT_OBJC_BRIDGING_HEADER = Modules/Disk/Bridge.h; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -2590,7 +2589,6 @@ PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats.Disk; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; - SWIFT_OBJC_BRIDGING_HEADER = Modules/Disk/Bridge.h; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/Stats/Supporting Files/Info.plist b/Stats/Supporting Files/Info.plist index 4ce21a03..8c8c473b 100755 --- a/Stats/Supporting Files/Info.plist +++ b/Stats/Supporting Files/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 67 + 151 Description Simple macOS system monitor in your menu bar LSApplicationCategoryType diff --git a/Stats/Supporting Files/pl.lproj/Localizable.strings b/Stats/Supporting Files/pl.lproj/Localizable.strings index 78dcc0d8..efbff9e4 100644 --- a/Stats/Supporting Files/pl.lproj/Localizable.strings +++ b/Stats/Supporting Files/pl.lproj/Localizable.strings @@ -70,7 +70,7 @@ "Base" = "Podstawa"; "Display mode" = "Tryb wyświetlania"; "One row" = "Jeden wiersz"; -"Two rows" = "Dwa wierszy"; +"Two rows" = "Dwa wiersze"; // Module Kit "Open module settings" = "Otwórz ustawienie modulu";