Skip to content

Commit

Permalink
Fixed preferences not saving correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamik423 committed Feb 9, 2022
1 parent 4ab7ac7 commit dbcc026
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Padbury Clock Revived.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.hans.Padbury-Clock-Revived";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -307,7 +307,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.hans.Padbury-Clock-Revived";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Binary file not shown.
50 changes: 34 additions & 16 deletions Padbury Clock Revived/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,63 @@ import Foundation
import ScreenSaver

class Preferences: NSObject {

static var shared: Preferences? = nil

private let defaults: UserDefaults

override init() {
defaults = ScreenSaverDefaults(forModuleWithName: Bundle(for: Preferences.self).bundleIdentifier!)!
super.init()
Preferences.shared = self
}

var useSystemFont: Bool {
get { return (defaults.value(forKey: "UseSystemFont") as? Bool) ?? true }
set { defaults.setValue(newValue, forKey: "UseSystemFont") }
set {
defaults.setValue(newValue, forKey: "UseSystemFont")
defaults.synchronize()
}
}

var darkTheme: Bool {
get { return (defaults.value(forKey: "DarkTheme") as? Bool) ?? true }
set { defaults.setValue(newValue, forKey: "DarkTheme") }
set {
defaults.setValue(newValue, forKey: "DarkTheme")
defaults.synchronize()
}
}

var useAmPm: Bool {
get { return !((defaults.value(forKey: "24h") as? Bool) ?? true) }
set { defaults.setValue(!newValue, forKey: "24h") }
set {
defaults.setValue(!newValue, forKey: "24h")
defaults.synchronize()
}
}

var showTimeSeparators: Bool {
get { return (defaults.value(forKey: "showTimeSeparators") as? Bool) ?? false }
set { defaults.setValue(newValue, forKey: "showTimeSeparators") }
set {
defaults.setValue(newValue, forKey: "showTimeSeparators")
defaults.synchronize()
}
}

var fontWeight: NSFont.Weight {
get { return NSFont.Weight.from(name: (defaults.value(forKey: "fontWeight") as? String) ?? "Ultra Light") }
set { defaults.setValue(newValue.name, forKey: "fontWeight") }
set {
defaults.setValue(newValue.name, forKey: "fontWeight")
defaults.synchronize()
}
}

var showSeconds: Bool {
get { return (defaults.value(forKey: "ShowSeconds") as? Bool) ?? true }
set { defaults.setValue(newValue, forKey: "ShowSeconds") }
set {
defaults.setValue(newValue, forKey: "ShowSeconds")
defaults.synchronize()
}
}
}

Expand All @@ -70,7 +88,7 @@ extension NSFont.Weight {
}
}
}

static func from(name: String) -> NSFont.Weight {
switch name {
case "Ultra Light": return .ultraLight
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ With the new version you will also be able to select San Francisco, Apple's new

Download [the latest version](https://github.com/Kamik423/Padbury-Clock-Revived/releases/latest/download/Padbury.Clock.Revived.saver.zip) from [the releases page](https://github.com/Kamik423/Padbury-Clock-Revived/releases).

## Changelog

### 1.0.2 (2022-02-10)

* Fixed settings not saving correctly

### 1.0.1 (2022-02-09)

* Rebuilt as Universal Binary

### 1.0.0 (2022-02-08)

* Initial Release

## License

This project is licensed under the [MIT license](LICENSE.md).
Expand Down

0 comments on commit dbcc026

Please sign in to comment.