Skip to content

Commit

Permalink
Merged dev into master
Browse files Browse the repository at this point in the history
  • Loading branch information
masich committed Apr 11, 2020
2 parents b0a49d3 + 790d1eb commit 3594efe
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
Binary file modified Images/Readme/Screenshots/MenuAppScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/Readme/Screenshots/NotificationsScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Break time - time in minutes to rest your eyes.
Features:
* Some general predefined work and break time intervals sets.
* Time settings selected by the user are saved in local storage.
* Automatically pauses and resumes timer depending on user activity.
* Automatically pauses and resumes timer depending on user activity.
* Sends reminder notifications based on the time presets selected by the user.

The app is built using ```SwiftUI``` and requires macOS 10.15 to run.

Expand Down
8 changes: 4 additions & 4 deletions SaveMyEyes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 17;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_ASSET_PATHS = "\"SaveMyEyes/Preview Content\"";
DEVELOPMENT_TEAM = 5PYHR2J538;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -369,7 +369,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.3;
MARKETING_VERSION = 0.31;
PRODUCT_BUNDLE_IDENTIFIER = com.masich.SaveMyEyes;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -384,7 +384,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 17;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_ASSET_PATHS = "\"SaveMyEyes/Preview Content\"";
DEVELOPMENT_TEAM = 5PYHR2J538;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -395,7 +395,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.3;
MARKETING_VERSION = 0.31;
PRODUCT_BUNDLE_IDENTIFIER = com.masich.SaveMyEyes;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
13 changes: 13 additions & 0 deletions SaveMyEyes/Source/Common/Extentions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ extension String {
return NSString.localizedUserNotificationString(forKey: self, arguments: nil)
}
}

extension UserDefaults {
/// Returns stored value for provided `key` or `nil` if there is no stored value availble for a `key`.
public func optional<T>(forKey key: String) -> T? {
return self.value(forKey: key) as? T
}

/// Returns stored value for provided `key` or `defaultValue` if there is no stored value availble for a `key`.
public func value<T>(forKey key: String, defaultValue: T) -> T {
let storedValue: T? = optional(forKey: key)
return storedValue ?? defaultValue
}
}
25 changes: 15 additions & 10 deletions SaveMyEyes/Source/Common/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ class Preferences{
private static let selectedBreakTimeKey = "SelectedBreakTime";
private static let isSoundEnabledKey = "IsSoundEnabled";

private static let defaults = UserDefaults.standard
private static let userDefaults = UserDefaults.standard

public static func registerDefaults(defaults: [String : Any]) {
userDefaults.register(defaults: defaults)
}

/**
Returns selected time interval index retrieved from the local storage

returns `Int`: Localy saved user selected time interval or `0` when there is no
saved time interval
*/
public static func getWorkIntervalIndexValue() -> Int {
return defaults.integer(forKey: selectedTimeIntervalKey)
public static func getWorkIntervalIndexValue(_ defaultValue: Int) -> Int {
return userDefaults.value(forKey: selectedTimeIntervalKey, defaultValue: defaultValue)

}

/**
Expand All @@ -31,8 +36,8 @@ class Preferences{
returns `Int`: Localy saved user selected break time index or `0` when there is
no saved break time index
*/
public static func getBreakIntervalIndexValue() -> Int {
return defaults.integer(forKey: selectedBreakTimeKey)
public static func getBreakIntervalIndexValue(_ defaultValue: Int) -> Int {
return userDefaults.value(forKey: selectedBreakTimeKey, defaultValue: defaultValue)
}

/**
Expand All @@ -41,20 +46,20 @@ class Preferences{
returns `Bool`: Localy saved is sound enabled value or `false` when there is
no saved is sound enabled value
*/
public static func isSoundEnabled() -> Bool {
return defaults.bool(forKey: isSoundEnabledKey)
public static func isSoundEnabled(_ defaultValue: Bool) -> Bool {
return userDefaults.value(forKey: isSoundEnabledKey, defaultValue: defaultValue)
}

public static func setWorkTimeIntervalIndexValue(_ value: Int) {
defaults.set(value, forKey: selectedTimeIntervalKey)
userDefaults.set(value, forKey: selectedTimeIntervalKey)
}

public static func setBreakIntervalIndexValue(_ value: Int) {
defaults.set(value, forKey: selectedBreakTimeKey)
userDefaults.set(value, forKey: selectedBreakTimeKey)
}

public static func setSoundEnabled(_ value: Bool) {
defaults.set(value, forKey: isSoundEnabledKey)
userDefaults.set(value, forKey: isSoundEnabledKey)
}
}

Expand Down
6 changes: 3 additions & 3 deletions SaveMyEyes/Source/Main/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class MainViewModel: ObservableObject {
@Published private(set) var remainingMins: Int = 0

@Published var shouldTimerRun = Observable<Bool>(false)
@Published var isSoundEnabled = Observable<Bool>(Preferences.isSoundEnabled())
@Published var workIntervalIndex = Observable<Int>(Preferences.getWorkIntervalIndexValue())
@Published var breakIntervalIndex = Observable<Int>(Preferences.getBreakIntervalIndexValue())
@Published var isSoundEnabled = Observable<Bool>(Preferences.isSoundEnabled(true))
@Published var workIntervalIndex = Observable<Int>(Preferences.getWorkIntervalIndexValue(0))
@Published var breakIntervalIndex = Observable<Int>(Preferences.getBreakIntervalIndexValue(0))

private var timerWorker: TimerWorker!
private var cancellables = [AnyCancellable]()
Expand Down

0 comments on commit 3594efe

Please sign in to comment.