- fix app crash when start (#136) (font bug)

This commit is contained in:
Serhiy Mytrovtsiy
2020-11-03 21:10:03 +01:00
parent 28b5d996d7
commit 85742785e7
8 changed files with 25 additions and 52 deletions

View File

@@ -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()
}
}

View File

@@ -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 <libproc.h>
#endif /* Bridge_h */

View File

@@ -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))
}
}

View File

@@ -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")
))
}

View File

@@ -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))
}
}

View File

@@ -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 = "";

View File

@@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>67</string>
<string>151</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>

View File

@@ -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";