Skip to content

Commit

Permalink
add code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raygesualdo committed Aug 11, 2019
1 parent 37c5630 commit 3f21176
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions program/Sources/amiunlocked/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import Configuration
import Foundation
import Just

// Enumerate valid states for our computer: "locked" and "unlocked"
enum State: String {
case locked
case unlocked
}

// Section: configuration

// Section: Configuration
// Start a configuration manager, load configuration from an adjacent
// `config.json` file, cast config values to appropriate types, and
// fail if required config values are not present
let manager = ConfigurationManager()
manager.load(file: "config.json")
let url = manager["url"] as? String ?? ""
Expand All @@ -23,8 +26,9 @@ if writeKey == "" {
fatalError("The config parameter 'writeKey' is required. Set it in 'config.json' and please try again.")
}

// Section: network requests

// Section: Network Requests
// Functions to create UTC timestamps and make network requests
// to the kvdb bucket with a given `State`
func getISOTimestamp() -> String {
if #available(macOS 10.12, *) {
let date = Date()
Expand All @@ -48,8 +52,10 @@ func sendRequest(state: State) {
}
}

// Section: event listeners

// Section: Event Listeners
// The event listeners listening for `screenIsLocked` and `screenIsUnlocked`
// events, and the callback function to log and make a network request in
// response to a triggered event
func logAndSendRequest(notification: Notification, state: State) {
NSLog("Event: \(notification.name.rawValue)")
sendRequest(state: state)
Expand Down

0 comments on commit 3f21176

Please sign in to comment.