This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
class EventMonitor { | |
private let handler: (NSEvent) -> Void | |
private let mask: NSEvent.EventTypeMask | |
private var monitor: Any? | |
init(mask: NSEvent.EventTypeMask, handler: @escaping (NSEvent) -> Void) { | |
self.handler = handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let homeDirectory: String = { | |
let home = getpwuid(getuid()).pointee.pw_dir! | |
return FileManager.default.string(withFileSystemRepresentation: home, length: Int(strlen(home))) | |
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct SparkleCleanup { | |
private static let oldDownloadAge: TimeInterval = 86400 // 24 hours | |
/// The location where Sparkle caches file downloads. | |
private static var cacheURL: URL { | |
guard let bundleIdentifier = Bundle.main.bundleIdentifier else { | |
fatalError("Unable to get bundle identifier.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class URLSchemeHandler { | |
private let urlHandler: (URL) -> Void | |
init(urlHandler: @escaping (URL) -> Void) { | |
self.urlHandler = urlHandler | |
NSAppleEventManager.shared().setEventHandler( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
struct ScreenshotManager { | |
/// Matches macOS' screenshot filename format. | |
private static let filenameFormatter: DateFormatter = { | |
let formatter = DateFormatter() | |
formatter.dateFormat = "'Screen Shot' yyyy-MM-dd 'at' HH.mm.ss" | |
return formatter | |
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func isPortInUse(_ port: Int) -> Bool { | |
// Use netstat to find ports in use then grep for one we're interested in. | |
// See this solution for piping shell commands: http://stackoverflow.com/a/16650638 | |
let process = Process() | |
process.launchPath = "/bin/sh" | |
process.arguments = ["-c", "netstat -an | grep '\\b\(port)\\b' | grep LISTEN"] | |
process.standardOutput = Pipe() | |
process.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let iso8601Formatter: DateFormatter = { | |
let formatter = DateFormatter() | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" | |
return formatter | |
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
protocol OutlineViewDelegate { | |
func outlineView(outlineView: NSOutlineView, menuForItem item: Any) -> NSMenu? | |
} | |
extension OutlineViewDelegate { | |
func outlineView(outlineView: NSOutlineView, menuForItem item: Any) -> NSMenu? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
class VerticallyCenteredTextFieldCell: NSTextFieldCell { | |
// Adapted from http://stackoverflow.com/a/8626071 | |
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { | |
let adjustedFrame = adjusted(frame: cellFrame) | |
super.drawInterior(withFrame: adjustedFrame, in: controlView) | |
} |