Fix sleep

This commit is contained in:
Zhigang Fang
2017-11-28 01:37:50 +08:00
parent ec8f1c8b16
commit eeedf2dc6a
3 changed files with 9 additions and 3 deletions

View File

@@ -7,4 +7,5 @@ Changelog
* In recent entries, sort project by usage.
* When showing recent entries, enter key autocomplete instead of start timer.
* Add option to reminder you at certain interval.
* Add option to auto apply yes on interval timeout.
* Add option to auto apply yes on interval timeout.
* Disable reminder when computer went to sleep.

View File

@@ -24,6 +24,7 @@
041E2BB41F9EF0370036687C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
041E2BB51F9EF0370036687C /* FloatingToggl.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FloatingToggl.entitlements; sourceTree = "<group>"; };
041E2BBB1F9EF3450036687C /* FloatingPannel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingPannel.swift; sourceTree = "<group>"; };
04D507151FCC84360038E7E0 /* CHANGELOG */ = {isa = PBXFileReference; lastKnownFileType = text; path = CHANGELOG; sourceTree = "<group>"; };
60799DCC63FBAD0197655FF4 /* Pods-FloatingToggl.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FloatingToggl.release.xcconfig"; path = "Pods/Target Support Files/Pods-FloatingToggl/Pods-FloatingToggl.release.xcconfig"; sourceTree = "<group>"; };
6A61B7517328FB18AF3456FF /* Pods-FloatingToggl.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FloatingToggl.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FloatingToggl/Pods-FloatingToggl.debug.xcconfig"; sourceTree = "<group>"; };
B3256CA209129AD71D5691BF /* Pods_FloatingToggl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FloatingToggl.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -44,6 +45,7 @@
041E2B9F1F9EF0370036687C = {
isa = PBXGroup;
children = (
04D507151FCC84360038E7E0 /* CHANGELOG */,
041E2BAA1F9EF0370036687C /* FloatingToggl */,
041E2BA91F9EF0370036687C /* Products */,
AB897BA953C7D862BCC1F2D0 /* Pods */,

View File

@@ -125,6 +125,7 @@ class TogglViewModel {
let input = Variable<String>("")
let active = Variable<Bool>(NSApplication.shared.isActive)
let awake = Variable<Bool>(true)
private let disposeBag = DisposeBag()
@@ -197,6 +198,7 @@ class TogglViewModel {
NSWorkspace.shared.notificationCenter
.rx.notification(NSWorkspace.screensDidSleepNotification)
.subscribe(onNext: {[weak self] _ in
self?.awake.value = false
guard let entry = self?.current.value else { return }
self?.timeEntryWhenSlept = entry
self?.screenSleptAt = Date()
@@ -206,6 +208,7 @@ class TogglViewModel {
NSWorkspace.shared.notificationCenter
.rx.notification(NSWorkspace.screensDidWakeNotification)
.subscribe(onNext: {[weak self] _ in
self?.awake.value = true
guard
let date = self?.screenSleptAt,
let timer = self?.timeEntryWhenSlept,
@@ -224,11 +227,11 @@ class TogglViewModel {
var presentReminder: Observable<()> {
return Observable.merge([
self.active.asObservable().distinctUntilChanged().map({_ in ()}),
self.awake.asObservable().distinctUntilChanged().map({_ in ()}),
NotificationCenter.default.rx.notification(.reminderIntervalUpdated).map({_ in ()}),
self.input.asObservable().distinctUntilChanged().map({_ in ()})
]).flatMapLatest({[weak self] _ -> Observable<()> in
if self?.active.value != true { return .empty() }
if self?.awake.value != true { return .empty() }
let interval = UserDefaults.standard.reminderInterval
if interval == 0 { return .empty() }
return Observable<Int>.interval(RxTimeInterval(interval * 60), scheduler: MainScheduler.asyncInstance).map({ _ in ()})