Skip to content

Commit

Permalink
fix: send feedback crashed the app on submit (closes #172)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Mar 12, 2020
1 parent 2e500b5 commit c34b8a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/logic/DebugProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DebugProfile {
private static func appPreferences() -> String {
return nestedSeparator + Preferences.all
.sorted { $0.0 < $1.0 }
.map { $0.key + intraSeparator + Preferences.getAsString($0.key)! }
.map { $0.key + intraSeparator + Preferences.getAsString($0.key) }
.joined(separator: nestedSeparator)
}

Expand Down
10 changes: 7 additions & 3 deletions src/logic/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,23 @@ class Preferences {
defaults.register(defaults: defaultValues)
}

static func get(_ key: String) -> Any? {
static func getObject(_ key: String) -> Any? {
defaults.object(forKey: key)
}

static func getAsString(_ key: String) -> String? {
static func getString(_ key: String) -> String? {
defaults.string(forKey: key)
}

static func getAsString(_ key: String) -> String {
String(describing: defaults.object(forKey: key))
}

static func set(_ key: String, _ value: Any?) {
defaults.set(value, forKey: key)
}

static var all: [String: Any] { defaults.dictionaryRepresentation() }
static var all: [String: Any] { defaults.persistentDomain(forName: NSRunningApplication.current.bundleIdentifier!)! }
}

struct Theme {
Expand Down
8 changes: 4 additions & 4 deletions src/ui/preferences-window/LabelAndControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Cocoa

class LabelAndControl: NSObject {
static func makeLabelWithInput(_ labelText: String, _ rawName: String, _ width: CGFloat, _ suffixText: String? = nil, _ suffixUrl: String? = nil, _ validator: ((String) -> Bool)? = nil) -> [NSView] {
let input = TextField(Preferences.getAsString(rawName)!)
let input = TextField(Preferences.getString(rawName)!)
input.validationHandler = validator
input.delegate = input
input.visualizeValidationState()
Expand All @@ -13,19 +13,19 @@ class LabelAndControl: NSObject {

static func makeLabelWithCheckbox(_ labelText: String, _ rawName: String, extraAction: ActionClosure? = nil) -> [NSView] {
let checkbox = NSButton(checkboxWithTitle: "", target: nil, action: nil)
setControlValue(checkbox, Preferences.getAsString(rawName)!)
setControlValue(checkbox, Preferences.getString(rawName)!)
return makeLabelWithProvidedControl(labelText, rawName, checkbox, extraAction: extraAction)
}

static func makeLabelWithDropdown(_ labelText: String, _ rawName: String, _ values: [String], _ suffixText: String? = nil) -> [NSView] {
let popUp = NSPopUpButton()
popUp.addItems(withTitles: values)
popUp.selectItem(withTitle: Preferences.getAsString(rawName)!)
popUp.selectItem(withTitle: Preferences.getString(rawName)!)
return makeLabelWithProvidedControl(labelText, rawName, popUp, suffixText)
}

static func makeLabelWithSlider(_ labelText: String, _ rawName: String, _ minValue: Double, _ maxValue: Double, _ numberOfTickMarks: Int, _ allowsTickMarkValuesOnly: Bool, _ unitText: String = "") -> [NSView] {
let value = Preferences.getAsString(rawName)!
let value = Preferences.getString(rawName)!
let suffixText = value + "" + unitText
let slider = NSSlider()
slider.minValue = minValue
Expand Down

0 comments on commit c34b8a5

Please sign in to comment.