Skip to content

Commit

Permalink
fix: fixed widget settings reset after restart in GPU module (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
exelban committed Apr 22, 2021
1 parent d807709 commit 0e5c747
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ModuleKit/Widgets/Mini.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import Cocoa
import StatsKit

public class Mini: WidgetWrapper {
private let defaultTitle: String

private var labelState: Bool = true
private var colorState: Color = .monochrome

Expand All @@ -26,6 +24,8 @@ public class Mini: WidgetWrapper {

private var value: Double = 0
private var pressureLevel: Int = 0
private var defaultLabel: String
private var label: String

private var width: CGFloat {
get {
Expand Down Expand Up @@ -63,7 +63,8 @@ public class Mini: WidgetWrapper {
}
}

self.defaultTitle = widgetTitle
self.defaultLabel = widgetTitle
self.label = widgetTitle
super.init(.mini, title: widgetTitle, frame: CGRect(
x: 0,
y: Constants.Widget.margin.y,
Expand Down Expand Up @@ -98,7 +99,7 @@ public class Mini: WidgetWrapper {
NSAttributedString.Key.paragraphStyle: NSMutableParagraphStyle()
]
let rect = CGRect(x: origin.x, y: 12, width: 20, height: 7)
let str = NSAttributedString.init(string: self.title, attributes: stringAttributes)
let str = NSAttributedString.init(string: self.label, attributes: stringAttributes)
str.draw(with: rect)

origin.y = 1
Expand Down Expand Up @@ -148,16 +149,16 @@ public class Mini: WidgetWrapper {
}

public func setTitle(_ newTitle: String?) {
var title = self.defaultTitle
if newTitle != nil {
title = newTitle!
guard var title = newTitle else {
return
}

if self.title == title {
title = self.defaultLabel
if self.label == newTitle {
return
}

self.title = title
self.label = title
DispatchQueue.main.async(execute: {
self.needsDisplay = true
})
Expand Down

0 comments on commit 0e5c747

Please sign in to comment.