Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 8071894cc278e881a018babec3d971300aaf00b1 @RISCfuture RISCfuture committed Aug 2, 2010
4 .gitignore
@@ -0,0 +1,4 @@
+.DS_Store
+Coffee Time.xcodeproj/*.mode2v3
+Coffee Time.xcodeproj/*.mode1v3
+Coffee Time.xcodeproj/*.pbxuser
298 Coffee Time.xcodeproj/project.pbxproj
@@ -0,0 +1,298 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 45;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 01B85D5512024CC800A322CB /* growlnotify in Resources */ = {isa = PBXBuildFile; fileRef = 01B85D5412024CC800A322CB /* growlnotify */; };
+ 01C4476F120227CA006052EF /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 01C44766120227B9006052EF /* Icon.icns */; };
+ 01C44770120227CA006052EF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 01C44767120227B9006052EF /* InfoPlist.strings */; };
+ 01C44771120227CA006052EF /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01C44768120227B9006052EF /* MainMenu.xib */; };
+ 01C44772120227DA006052EF /* Coffee_TimeAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 01C4476C120227B9006052EF /* Coffee_TimeAppDelegate.m */; };
+ 01C4479912022C38006052EF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 01C4476D120227B9006052EF /* main.m */; };
+ 01C4484A1202381C006052EF /* coffee_check.rb in Resources */ = {isa = PBXBuildFile; fileRef = 01C448491202381C006052EF /* coffee_check.rb */; };
+ 01C4486D12023CB5006052EF /* com.scribd.CoffeeTime.plist in Resources */ = {isa = PBXBuildFile; fileRef = 01C4486C12023CB5006052EF /* com.scribd.CoffeeTime.plist */; };
+ 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 01B85D5412024CC800A322CB /* growlnotify */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = growlnotify; sourceTree = "<group>"; };
+ 01C44766120227B9006052EF /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = "<group>"; };
+ 01C44767120227B9006052EF /* InfoPlist.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = InfoPlist.strings; sourceTree = "<group>"; };
+ 01C44768120227B9006052EF /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
+ 01C4476B120227B9006052EF /* Coffee_TimeAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Coffee_TimeAppDelegate.h; sourceTree = "<group>"; };
+ 01C4476C120227B9006052EF /* Coffee_TimeAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Coffee_TimeAppDelegate.m; sourceTree = "<group>"; };
+ 01C4476D120227B9006052EF /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 01C44774120227EB006052EF /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 01C4477812022B8F006052EF /* Coffee_Time-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Coffee_Time-Info.plist"; sourceTree = SOURCE_ROOT; };
+ 01C448491202381C006052EF /* coffee_check.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = coffee_check.rb; sourceTree = "<group>"; };
+ 01C4485012023C1D006052EF /* Coffee_Time_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Coffee_Time_Prefix.pch; sourceTree = SOURCE_ROOT; };
+ 01C4486C12023CB5006052EF /* com.scribd.CoffeeTime.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = com.scribd.CoffeeTime.plist; sourceTree = "<group>"; };
+ 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
+ 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
+ 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
+ 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+ 8D1107320486CEB800E47090 /* Coffee Time.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Coffee Time.app"; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 8D11072E0486CEB800E47090 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 01C44765120227B9006052EF /* Resources */ = {
+ isa = PBXGroup;
+ children = (
+ 01B85D5412024CC800A322CB /* growlnotify */,
+ 01C4477812022B8F006052EF /* Coffee_Time-Info.plist */,
+ 01C44766120227B9006052EF /* Icon.icns */,
+ 01C44767120227B9006052EF /* InfoPlist.strings */,
+ 01C44768120227B9006052EF /* MainMenu.xib */,
+ 01C448491202381C006052EF /* coffee_check.rb */,
+ 01C4486C12023CB5006052EF /* com.scribd.CoffeeTime.plist */,
+ );
+ path = Resources;
+ sourceTree = "<group>";
+ };
+ 01C44769120227B9006052EF /* Sources */ = {
+ isa = PBXGroup;
+ children = (
+ 01C4485012023C1D006052EF /* Coffee_Time_Prefix.pch */,
+ 01C4476A120227B9006052EF /* Application */,
+ 01C4476E120227B9006052EF /* Daemon */,
+ );
+ path = Sources;
+ sourceTree = "<group>";
+ };
+ 01C4476A120227B9006052EF /* Application */ = {
+ isa = PBXGroup;
+ children = (
+ 01C4476B120227B9006052EF /* Coffee_TimeAppDelegate.h */,
+ 01C4476C120227B9006052EF /* Coffee_TimeAppDelegate.m */,
+ 01C4476D120227B9006052EF /* main.m */,
+ );
+ path = Application;
+ sourceTree = "<group>";
+ };
+ 01C4476E120227B9006052EF /* Daemon */ = {
+ isa = PBXGroup;
+ children = (
+ 01C44774120227EB006052EF /* main.m */,
+ );
+ path = Daemon;
+ sourceTree = "<group>";
+ };
+ 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
+ );
+ name = "Linked Frameworks";
+ sourceTree = "<group>";
+ };
+ 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 29B97324FDCFA39411CA2CEA /* AppKit.framework */,
+ 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */,
+ 29B97325FDCFA39411CA2CEA /* Foundation.framework */,
+ );
+ name = "Other Frameworks";
+ sourceTree = "<group>";
+ };
+ 19C28FACFE9D520D11CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 8D1107320486CEB800E47090 /* Coffee Time.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 29B97314FDCFA39411CA2CEA /* Coffee Time */ = {
+ isa = PBXGroup;
+ children = (
+ 01C44769120227B9006052EF /* Sources */,
+ 01C44765120227B9006052EF /* Resources */,
+ 29B97323FDCFA39411CA2CEA /* Frameworks */,
+ 19C28FACFE9D520D11CA2CBB /* Products */,
+ );
+ name = "Coffee Time";
+ sourceTree = "<group>";
+ };
+ 29B97323FDCFA39411CA2CEA /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
+ 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 8D1107260486CEB800E47090 /* Coffee Time */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "Coffee Time" */;
+ buildPhases = (
+ 8D11072C0486CEB800E47090 /* Sources */,
+ 8D1107290486CEB800E47090 /* Resources */,
+ 8D11072E0486CEB800E47090 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = "Coffee Time";
+ productInstallPath = "$(HOME)/Applications";
+ productName = "Coffee Time";
+ productReference = 8D1107320486CEB800E47090 /* Coffee Time.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 29B97313FDCFA39411CA2CEA /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Coffee Time" */;
+ compatibilityVersion = "Xcode 3.1";
+ hasScannedForEncodings = 1;
+ mainGroup = 29B97314FDCFA39411CA2CEA /* Coffee Time */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 8D1107260486CEB800E47090 /* Coffee Time */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 8D1107290486CEB800E47090 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 01C4476F120227CA006052EF /* Icon.icns in Resources */,
+ 01C44770120227CA006052EF /* InfoPlist.strings in Resources */,
+ 01C44771120227CA006052EF /* MainMenu.xib in Resources */,
+ 01C4484A1202381C006052EF /* coffee_check.rb in Resources */,
+ 01C4486D12023CB5006052EF /* com.scribd.CoffeeTime.plist in Resources */,
+ 01B85D5512024CC800A322CB /* growlnotify in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 8D11072C0486CEB800E47090 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 01C4479912022C38006052EF /* main.m in Sources */,
+ 01C44772120227DA006052EF /* Coffee_TimeAppDelegate.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ C01FCF4B08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ COPY_PHASE_STRIP = NO;
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SRCROOT)/Frameworks\"",
+ );
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = Coffee_Time_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ INFOPLIST_FILE = "Coffee_Time-Info.plist";
+ INSTALL_PATH = "$(HOME)/Applications";
+ PRODUCT_NAME = "Coffee Time";
+ };
+ name = Debug;
+ };
+ C01FCF4C08A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SRCROOT)/Frameworks\"",
+ );
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = Coffee_Time_Prefix.pch;
+ INFOPLIST_FILE = "Coffee_Time-Info.plist";
+ INSTALL_PATH = "$(HOME)/Applications";
+ PRODUCT_NAME = "Coffee Time";
+ };
+ name = Release;
+ };
+ C01FCF4F08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ PREBINDING = NO;
+ SDKROOT = macosx10.6;
+ };
+ name = Debug;
+ };
+ C01FCF5008A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ PREBINDING = NO;
+ SDKROOT = macosx10.6;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "Coffee Time" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4B08A954540054247B /* Debug */,
+ C01FCF4C08A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Coffee Time" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4F08A954540054247B /* Debug */,
+ C01FCF5008A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
+}
34 Coffee_Time-Info.plist
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string>Icon.icns</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.scribd.CoffeeTime</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>CofT</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+ <key>CoffeeURL</key>
+ <string>http://coffeetime.heroku.com/coffees</string>
+</dict>
+</plist>
7 Coffee_Time_Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'Coffee Time' target in the 'Coffee Time' project
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
BIN Resources/Icon.icns
Binary file not shown.
4 Resources/InfoPlist.strings
@@ -0,0 +1,4 @@
+/* Localized versions of Info.plist keys */
+
+CFBundleDisplayName = "Coffee Time";
+NSHumanReadableCopyright = "Copyright ©2010 Scribd Inc. By Tim Morgan.";
4,452 Resources/MainMenu.xib
4,452 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
22 Resources/coffee_check.rb
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+require 'net/http'
+
+latest_coffee = Net::HTTP.get(URI.parse("http://coffeetime.heroku.com/coffees"))
+exit if latest_coffee == "No Coffee Yet"
+
+name, time = latest_coffee.split(/\n/)
+time = time.to_i
+
+if Time.now.to_i - time < 32 then
+ full_name = `dscl . -read /Users/#{ENV['USER']} RealName`.split(/\n\s?/).last
+ if full_name != name then
+ system "/Users/#{ENV['USER']}/Library/Application Support/Coffee Time/growlnotify", '-n', "Coffee Time".inspect,
+ '-m', "#{name} says it's coffee time!",
+ '-a', "Coffee Time",
+ '-p', '1',
+ '--sticky',
+ '-d', 'ItsCoffeeTime',
+ "It's Coffee Time!"
+ end
+end
20 Resources/com.scribd.CoffeeTime.plist
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.scribd.CoffeeTime</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/bin/env</string>
+ <string>ruby</string>
+ <string>__SCRIPT_PATH__</string>
+ </array>
+ <key>RunAtLoad</key>
+ <true/>
+ <key>StartInterval</key>
+ <integer>30</integer>
+</dict>
+</plist>
BIN Resources/growlnotify
Binary file not shown.
13 Sources/Application/Coffee_TimeAppDelegate.h
@@ -0,0 +1,13 @@
+#import <Cocoa/Cocoa.h>
+
+@interface Coffee_TimeAppDelegate : NSObject <NSApplicationDelegate> {
+ NSWindow *window;
+ IBOutlet NSTextField *checkmark;
+ IBOutlet NSProgressIndicator *spinner;
+}
+
+@property (assign) IBOutlet NSWindow *window;
+
+- (IBAction) coffeeTime:(id)sender;
+
+@end
103 Sources/Application/Coffee_TimeAppDelegate.m
@@ -0,0 +1,103 @@
+//
+// Coffee_TimeAppDelegate.m
+// Coffee Time
+//
+// Created by Tim Morgan on 7/29/10.
+// Copyright 2010 Scribd. All rights reserved.
+//
+
+#import "Coffee_TimeAppDelegate.h"
+
+@implementation Coffee_TimeAppDelegate
+
+@synthesize window;
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+ // check for app support folder and script
+
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
+ NSString *appSupportPath = [basePath stringByAppendingPathComponent:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]];
+
+ NSError *error = NULL;
+ if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportPath])
+ [[NSFileManager defaultManager] createDirectoryAtPath:appSupportPath withIntermediateDirectories:YES attributes:NULL error:&error];
+ NSString *scriptPath = [appSupportPath stringByAppendingPathComponent:@"coffee_check.rb"];
+ if (![[NSFileManager defaultManager] fileExistsAtPath:scriptPath])
+ [[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"coffee_check" ofType:@"rb"]
+ toPath:scriptPath
+ error:&error];
+
+ // check for growlnotify
+
+ NSString *binPath = [appSupportPath stringByAppendingPathComponent:@"growlnotify"];
+ if (![[NSFileManager defaultManager] fileExistsAtPath:binPath])
+ [[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"growlnotify" ofType:NULL]
+ toPath:binPath
+ error:&error];
+
+ // check for launch agent
+
+ paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
+ NSString *libraryPath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
+
+ NSString *agentPath = [libraryPath stringByAppendingPathComponent:@"LaunchAgents"];
+ NSString *agent = @"com.scribd.CoffeeTime.plist";
+ if (![[NSFileManager defaultManager] fileExistsAtPath:agentPath])
+ [[NSFileManager defaultManager] createDirectoryAtPath:agentPath withIntermediateDirectories:YES attributes:NULL error:&error];
+ NSString *agentFilePath = [agentPath stringByAppendingPathComponent:agent];
+ if (![[NSFileManager defaultManager] fileExistsAtPath:agentFilePath]) {
+ NSMutableString *agentString = [[NSMutableString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com.scribd.CoffeeTime" ofType:@"plist"]];
+ [agentString replaceOccurrencesOfString:@"__SCRIPT_PATH__" withString:scriptPath options:0 range:NSMakeRange(0, [agentString length])];
+ [agentString writeToFile:agentFilePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
+ [agentString release];
+
+ NSArray *arguments = [[NSArray alloc] initWithObjects:@"load", @"-w", agentFilePath, NULL];
+ [NSTask launchedTaskWithLaunchPath:@"/bin/launchctl" arguments:arguments];
+ [arguments release];
+ }
+}
+
+- (IBAction) coffeeTime:(id)sender {
+ [checkmark setHidden:YES];
+ NSURL *URL = [[NSURL alloc] initWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CoffeeURL"]];
+ NSMutableURLRequest *ping = [[NSMutableURLRequest alloc] initWithURL:URL];
+ [URL release];
+ [ping setHTTPMethod:@"POST"];
+ NSString *body = [[NSString alloc] initWithFormat:@"%@=%@",
+ [@"coffee[name]" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+ [NSFullUserName() stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+ [ping setHTTPBody:[body dataUsingEncoding:NSASCIIStringEncoding]];
+ [body release];
+
+ NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:ping delegate:self];
+ [conn autorelease];
+ [spinner setHidden:NO];
+}
+
+- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
+ [spinner setHidden:YES];
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert setMessageText:@"Couldn't connect to the Coffee Server."];
+ [alert setInformativeText:@"Have you made sure that you have Internet access?"];
+ [alert addButtonWithTitle:@"D'oh"];
+ [alert runModal];
+}
+
+- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response {
+ [spinner setHidden:YES];
+ if ([response statusCode] == 200) [checkmark setHidden:NO];
+ else {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ NSString *message = [[NSString alloc] initWithFormat:@"Got a %d response from the Coffee Server.", [response statusCode]];
+ [alert setMessageText:message];
+ [message release];
+ [alert setInformativeText:@"Maybe go bug Tim and tell him to fix his shit?"];
+ [alert addButtonWithTitle:@"Ah Nuts"];
+ [alert runModal];
+ }
+}
+
+@end
14 Sources/Application/main.m
@@ -0,0 +1,14 @@
+//
+// main.m
+// Coffee Time
+//
+// Created by Tim Morgan on 7/29/10.
+// Copyright 2010 Scribd. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, char *argv[])
+{
+ return NSApplicationMain(argc, (const char **) argv);
+}
26 Sources/Daemon/main.m
@@ -0,0 +1,26 @@
+int main(int argc, char *argv[]) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSURL *URL = [[NSURL alloc] initWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CoffeeURL"]];
+ NSString *latestCoffee = [[NSString alloc] initWithContentsOfURL:URL];
+ [URL release];
+
+ NSArray *components = [latestCoffee componentsSeparatedByString:@"\n"];
+ NSString *name = [components objectAtIndex:0];
+ NSInteger time = [[components objectAtIndex:1] integerValue];
+ NSInteger lastTime = [[NSUserDefaults standardUserDefaults] integerForKey:@"LastCoffee"];
+
+ if (time > lastTime) {
+ if (![name isEqualToString:NSFullUserName()])
+ [GrowlApplicationBridge notifyWithTitle:@"It's Coffee Time!"
+ description:[NSString stringWithFormat:@"%@ says it's coffee time!", name]
+ notificationName:@"ItsCoffeeTime"
+ iconData:NULL
+ priority:1
+ isSticky:YES
+ clickContext:NULL];
+ [[NSUserDefaults standardUserDefaults] setInteger:time forKey:@"LastCoffee"];
+ }
+
+ [pool release];
+}
1 build/.gitignore
@@ -0,0 +1 @@
+*

0 comments on commit 8071894

Please sign in to comment.