Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/an23lm/SleepWithMe into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselm Joseph committed Apr 8, 2021
2 parents 48d58de + 4555ae3 commit b12ed6b
Show file tree
Hide file tree
Showing 17 changed files with 872 additions and 189 deletions.
18 changes: 15 additions & 3 deletions SleepWithMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
F77593DA23368B8A00F797ED /* AppleScriptObjC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F728FD3F20C69CE60008AC5A /* AppleScriptObjC.framework */; };
F77D1B5C244C67340042C076 /* MenuBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77D1B5B244C67340042C076 /* MenuBarView.swift */; };
F783D796244C934D00ADCCDE /* InterfaceStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F783D795244C934D00ADCCDE /* InterfaceStyle.swift */; };
F784BC67261A44B00043E721 /* HotKeyExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F784BC66261A44B00043E721 /* HotKeyExtension.swift */; };
F7BB7DE120C5CE1D00824919 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BB7DE020C5CE1D00824919 /* AppDelegate.swift */; };
F7BB7DE320C5CE1D00824919 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BB7DE220C5CE1D00824919 /* ViewController.swift */; };
F7BB7DE520C5CE1F00824919 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7BB7DE420C5CE1F00824919 /* Assets.xcassets */; };
Expand Down Expand Up @@ -71,6 +72,7 @@
F76DB255210003D40097172D /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
F77D1B5B244C67340042C076 /* MenuBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarView.swift; sourceTree = "<group>"; };
F783D795244C934D00ADCCDE /* InterfaceStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterfaceStyle.swift; sourceTree = "<group>"; };
F784BC66261A44B00043E721 /* HotKeyExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HotKeyExtension.swift; sourceTree = "<group>"; };
F7BB7DDD20C5CE1D00824919 /* SleepWithMe.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SleepWithMe.app; sourceTree = BUILT_PRODUCTS_DIR; };
F7BB7DE020C5CE1D00824919 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
F7BB7DE220C5CE1D00824919 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,6 +164,14 @@
path = Helper;
sourceTree = "<group>";
};
F784BC65261A449C0043E721 /* Extensions */ = {
isa = PBXGroup;
children = (
F784BC66261A44B00043E721 /* HotKeyExtension.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
F7BB7DD420C5CE1D00824919 = {
isa = PBXGroup;
children = (
Expand All @@ -188,6 +198,7 @@
F764D4A3233692B8006ED9AC /* View Controller */,
F764D4A4233692DF006ED9AC /* View */,
F77D1B5D244C68990042C076 /* Model */,
F784BC65261A449C0043E721 /* Extensions */,
F77D1B5E244C68A90042C076 /* Helper */,
F7BB7DE420C5CE1F00824919 /* Assets.xcassets */,
F7BB7DE620C5CE1F00824919 /* Main.storyboard */,
Expand Down Expand Up @@ -324,6 +335,7 @@
buildActionMask = 2147483647;
files = (
F7E03BEC24765F9B00C5794C /* GlobalKeybindPreferences.swift in Sources */,
F784BC67261A44B00043E721 /* HotKeyExtension.swift in Sources */,
F77D1B5C244C67340042C076 /* MenuBarView.swift in Sources */,
F76DB256210003D40097172D /* Constants.swift in Sources */,
F74F10DD20C81BB5000AB074 /* NSTimerButton.swift in Sources */,
Expand Down Expand Up @@ -536,7 +548,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 2.6;
MARKETING_VERSION = 2.7;
PRODUCT_BUNDLE_IDENTIFIER = com.an23lm.SleepWithMe;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -561,7 +573,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 2.6;
MARKETING_VERSION = 2.7;
PRODUCT_BUNDLE_IDENTIFIER = com.an23lm.SleepWithMe;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -607,7 +619,7 @@
repositoryURL = "https://github.com/soffes/HotKey";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.1.3;
minimumVersion = 0.1.2;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
78 changes: 78 additions & 0 deletions SleepWithMe.xcodeproj/xcshareddata/xcschemes/SleepWithMe.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F7BB7DDC20C5CE1D00824919"
BuildableName = "SleepWithMe.app"
BlueprintName = "SleepWithMe"
ReferencedContainer = "container:SleepWithMe.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F7BB7DDC20C5CE1D00824919"
BuildableName = "SleepWithMe.app"
BlueprintName = "SleepWithMe"
ReferencedContainer = "container:SleepWithMe.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F7BB7DDC20C5CE1D00824919"
BuildableName = "SleepWithMe.app"
BlueprintName = "SleepWithMe"
ReferencedContainer = "container:SleepWithMe.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>F7BB7DDC20C5CE1D00824919</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
29 changes: 23 additions & 6 deletions SleepWithMe/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Cocoa
import ServiceManagement
import HotKey

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
Expand All @@ -19,12 +20,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele

private(set) var sleepTimer: SleepTimer! = nil
private var scheduledSleepTimer: Timer? = nil
private var defaultTimer: Int = 0
private var defaultTimer: Int = 30
private var hotKey: HotKey? = nil

private var notification: NSUserNotification? = nil

private var preferences: (autoLaunchEnabled: Bool, isDockEnabled: Bool, isScheduledSleepTimerEnabled: Bool,
scheduledSleepTime: Date, defaultTimer: Int)! = (false, true, false, Date(timeIntervalSince1970: 0), 0)
scheduledSleepTime: Date, defaultTimer: Int)! = (false, true, false, Date(timeIntervalSince1970: 0), 30)

//MARK: - Life cycle methods
func applicationWillFinishLaunching(_ notification: Notification) {
Expand Down Expand Up @@ -63,9 +65,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
if notification.activationType == .actionButtonClicked {
SleepTimer.shared.stopTimer(didComplete: false)
showPopover(notification)
} else if notification.activationType == .additionalActionClicked {
SleepTimer.shared.set(minutes: defaultTimer > 0 ? defaultTimer : 30)
} else if notification.activationType == .contentsClicked {
showPopover(notification)
}
NSUserNotificationCenter.default.removeAllDeliveredNotifications()
}

@objc func willSleepNotification(notification: NSNotification) {
Expand Down Expand Up @@ -110,6 +115,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
notification!.soundName = nil
notification!.hasActionButton = true
notification!.actionButtonTitle = "Stop Timer"
notification!.additionalActions = [ NSUserNotificationAction(identifier: "snooze", title: "Snooze") ]

let center = NSUserNotificationCenter.default
center.deliver(notification!)
Expand All @@ -122,7 +128,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
task.launch()
}

@objc internal func togglePopover(_ sender: Any) {
@objc internal func togglePopover(_ sender: Any?) {
if popover.isShown {
closePopover(sender)
} else {
Expand All @@ -149,6 +155,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
statusButton.addSubview(statusItemView)
statusButton.action = #selector(togglePopover)
}

}

private func setupPopoverAsset() {
Expand Down Expand Up @@ -179,7 +186,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
let date = Date(timeIntervalSince1970: 0)
let ti: Double = date.timeIntervalSince1970
UserDefaults.standard.set(ti, forKey: Constants.sleepTime)
UserDefaults.standard.set(0, forKey: Constants.defaultTimer)
UserDefaults.standard.set(30, forKey: Constants.defaultTimer)
UserDefaults.standard.synchronize()
}

Expand All @@ -204,7 +211,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele

let diff = Calendar.current.dateComponents([.day, .hour, .minute], from: Date(), to: date)
print(diff)
if diff.day! == 0 && diff.hour! == 0 && diff.minute! <= 30 {
if diff.day! == 0 && diff.hour! == 0 && diff.minute! <= 30 && diff.minute! > 5 {
self.autoSleep(minutes: diff.minute!)
} else {
let fDate = Calendar.current.date(byAdding: .minute, value: -30, to: date)!
Expand Down Expand Up @@ -245,6 +252,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
preferences.defaultTimer = defaultTimer
SleepTimer.shared.set(minutes: defaultTimer)
}
if let globalShortcutKeybind = UserDefaults.standard.string(forKey: Constants.globalShortcutKeybind) {
hotKey = HotKey(keys: globalShortcutKeybind) {
if (self.defaultTimer > 0) {
SleepTimer.shared.toggleTimer()
SleepTimer.shared.set(minutes: self.defaultTimer)
} else {
self.togglePopover(nil)
}
}
}
}

@objc func autoSleep(_ sender: Any) {
Expand All @@ -266,7 +283,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele

//MARK: - Menu Methods
@IBAction func closeKeyWindow(_ sender: Any) {
NSApplication.shared.keyWindow?.close()
NSApplication.shared.keyWindow?.performClose(sender)
}

@IBAction func openTimerWindow(_ sender: Any) {
Expand Down
6 changes: 3 additions & 3 deletions SleepWithMe/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "icons8-settings-filled-100.png",
"idiom" : "universal",
"scale" : "2x"
},
{
Expand All @@ -15,7 +15,7 @@
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
12 changes: 12 additions & 0 deletions SleepWithMe/Assets.xcassets/gear.symbolset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"symbols" : [
{
"filename" : "gear.svg",
"idiom" : "universal"
}
]
}
Loading

0 comments on commit b12ed6b

Please sign in to comment.