forked from codler/Battery-Time-Remaining
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sandboxing start at login (codler#4)
- Loading branch information
Showing
13 changed files
with
633 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// LLManager.h | ||
// LaunchAtLogin | ||
// | ||
// Created by David Keegan on 4/20/12. | ||
// Copyright (c) 2012 David Keegan. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface LLManager : NSObject | ||
|
||
+ (BOOL)launchAtLogin; | ||
+ (void)setLaunchAtLogin:(BOOL)value; | ||
|
||
@property (assign) BOOL launchAtLogin; | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// LLManager.m | ||
// LaunchAtLogin | ||
// | ||
// Created by David Keegan on 4/20/12. | ||
// Copyright (c) 2012 David Keegan. All rights reserved. | ||
// | ||
|
||
#import "LLManager.h" | ||
#import "LLStrings.h" | ||
#import <ServiceManagement/ServiceManagement.h> | ||
|
||
@implementation LLManager | ||
|
||
+ (BOOL)launchAtLogin{ | ||
BOOL launch = NO; | ||
CFArrayRef cfJobs = SMCopyAllJobDictionaries(kSMDomainUserLaunchd); | ||
#if __has_feature(objc_arc) | ||
NSArray *jobs = [NSArray arrayWithArray:(__bridge NSArray *)cfJobs]; | ||
#else | ||
NSArray *jobs = [NSArray arrayWithArray:(NSArray *)cfJobs]; | ||
#endif | ||
CFRelease(cfJobs); | ||
if([jobs count]){ | ||
for(NSDictionary *job in jobs){ | ||
if([job[@"Label"] isEqualToString:LLHelperBundleIdentifier]){ | ||
launch = [job[@"OnDemand"] boolValue]; | ||
break; | ||
} | ||
} | ||
} | ||
return launch; | ||
} | ||
|
||
+ (void)setLaunchAtLogin:(BOOL)value{ | ||
if(!SMLoginItemSetEnabled((CFStringRef)LLHelperBundleIdentifier, value)){ | ||
NSLog(@"SMLoginItemSetEnabled failed!"); | ||
} | ||
} | ||
|
||
#pragma mark - Bindings support | ||
|
||
- (BOOL)launchAtLogin { | ||
return [[self class] launchAtLogin]; | ||
} | ||
|
||
- (void)setLaunchAtLogin:(BOOL)launchAtLogin { | ||
[self willChangeValueForKey:@"launchAtLogin"]; | ||
[[self class] setLaunchAtLogin:launchAtLogin]; | ||
[self didChangeValueForKey:@"launchAtLogin"]; | ||
} | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// strings used by LLManager and LaunchAtLoginHelper | ||
// | ||
|
||
#define LLURLScheme @"com.codler.Battery-Time-Remaining" | ||
#define LLHelperBundleIdentifier @"com.codler.Battery-Time-Remaining-Helper" |
243 changes: 243 additions & 0 deletions
243
LaunchAtLoginHelper/LaunchAtLoginHelper.xcodeproj/project.pbxproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
// !$*UTF8*$! | ||
{ | ||
archiveVersion = 1; | ||
classes = { | ||
}; | ||
objectVersion = 46; | ||
objects = { | ||
|
||
/* Begin PBXBuildFile section */ | ||
734C379915414CE200994189 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 734C379815414CE200994189 /* Cocoa.framework */; }; | ||
73C920E915414E7800C2A75A /* LLHAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 73C920E615414E7800C2A75A /* LLHAppDelegate.m */; }; | ||
73C920EA15414E7800C2A75A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 73C920E715414E7800C2A75A /* main.m */; }; | ||
73C920EB15414E7800C2A75A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 73C920E815414E7800C2A75A /* MainMenu.xib */; }; | ||
/* End PBXBuildFile section */ | ||
|
||
/* Begin PBXFileReference section */ | ||
734C379415414CE200994189 /* LaunchAtLoginHelper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LaunchAtLoginHelper.app; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
734C379815414CE200994189 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; | ||
734C379B15414CE200994189 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; | ||
734C379D15414CE200994189 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; | ||
73C920E515414E7800C2A75A /* LLHAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLHAppDelegate.h; path = LaunchAtLoginHelper/LLHAppDelegate.h; sourceTree = "<group>"; }; | ||
73C920E615414E7800C2A75A /* LLHAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LLHAppDelegate.m; path = LaunchAtLoginHelper/LLHAppDelegate.m; sourceTree = "<group>"; }; | ||
73C920E715414E7800C2A75A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = LaunchAtLoginHelper/main.m; sourceTree = "<group>"; }; | ||
73C920E815414E7800C2A75A /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = MainMenu.xib; path = LaunchAtLoginHelper/MainMenu.xib; sourceTree = "<group>"; }; | ||
73C920FA15414F7000C2A75A /* LLStrings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LLStrings.h; sourceTree = SOURCE_ROOT; }; | ||
73C920FB15414FC900C2A75A /* LaunchAtLoginHelper.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = LaunchAtLoginHelper.entitlements; path = LaunchAtLoginHelper/LaunchAtLoginHelper.entitlements; sourceTree = "<group>"; }; | ||
/* End PBXFileReference section */ | ||
|
||
/* Begin PBXFrameworksBuildPhase section */ | ||
734C379115414CE200994189 /* Frameworks */ = { | ||
isa = PBXFrameworksBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
734C379915414CE200994189 /* Cocoa.framework in Frameworks */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXFrameworksBuildPhase section */ | ||
|
||
/* Begin PBXGroup section */ | ||
734C378915414CE200994189 = { | ||
isa = PBXGroup; | ||
children = ( | ||
73C920E715414E7800C2A75A /* main.m */, | ||
73C920FA15414F7000C2A75A /* LLStrings.h */, | ||
73C920E515414E7800C2A75A /* LLHAppDelegate.h */, | ||
73C920E615414E7800C2A75A /* LLHAppDelegate.m */, | ||
73C920E815414E7800C2A75A /* MainMenu.xib */, | ||
73C920FB15414FC900C2A75A /* LaunchAtLoginHelper.entitlements */, | ||
734C379715414CE200994189 /* Frameworks */, | ||
734C379515414CE200994189 /* Products */, | ||
); | ||
sourceTree = "<group>"; | ||
}; | ||
734C379515414CE200994189 /* Products */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
734C379415414CE200994189 /* LaunchAtLoginHelper.app */, | ||
); | ||
name = Products; | ||
sourceTree = "<group>"; | ||
}; | ||
734C379715414CE200994189 /* Frameworks */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
734C379B15414CE200994189 /* AppKit.framework */, | ||
734C379D15414CE200994189 /* Foundation.framework */, | ||
734C379815414CE200994189 /* Cocoa.framework */, | ||
); | ||
name = Frameworks; | ||
sourceTree = "<group>"; | ||
}; | ||
/* End PBXGroup section */ | ||
|
||
/* Begin PBXNativeTarget section */ | ||
734C379315414CE200994189 /* LaunchAtLoginHelper */ = { | ||
isa = PBXNativeTarget; | ||
buildConfigurationList = 734C37B215414CE200994189 /* Build configuration list for PBXNativeTarget "LaunchAtLoginHelper" */; | ||
buildPhases = ( | ||
734C379015414CE200994189 /* Sources */, | ||
734C379115414CE200994189 /* Frameworks */, | ||
734C379215414CE200994189 /* Resources */, | ||
); | ||
buildRules = ( | ||
); | ||
dependencies = ( | ||
); | ||
name = LaunchAtLoginHelper; | ||
productName = LaunchAtLoginHelper; | ||
productReference = 734C379415414CE200994189 /* LaunchAtLoginHelper.app */; | ||
productType = "com.apple.product-type.application"; | ||
}; | ||
/* End PBXNativeTarget section */ | ||
|
||
/* Begin PBXProject section */ | ||
734C378B15414CE200994189 /* Project object */ = { | ||
isa = PBXProject; | ||
attributes = { | ||
CLASSPREFIX = LLH; | ||
LastUpgradeCheck = 0450; | ||
ORGANIZATIONNAME = "David Keegan"; | ||
}; | ||
buildConfigurationList = 734C378E15414CE200994189 /* Build configuration list for PBXProject "LaunchAtLoginHelper" */; | ||
compatibilityVersion = "Xcode 3.2"; | ||
developmentRegion = English; | ||
hasScannedForEncodings = 0; | ||
knownRegions = ( | ||
en, | ||
); | ||
mainGroup = 734C378915414CE200994189; | ||
productRefGroup = 734C379515414CE200994189 /* Products */; | ||
projectDirPath = ""; | ||
projectRoot = ""; | ||
targets = ( | ||
734C379315414CE200994189 /* LaunchAtLoginHelper */, | ||
); | ||
}; | ||
/* End PBXProject section */ | ||
|
||
/* Begin PBXResourcesBuildPhase section */ | ||
734C379215414CE200994189 /* Resources */ = { | ||
isa = PBXResourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
73C920EB15414E7800C2A75A /* MainMenu.xib in Resources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXResourcesBuildPhase section */ | ||
|
||
/* Begin PBXSourcesBuildPhase section */ | ||
734C379015414CE200994189 /* Sources */ = { | ||
isa = PBXSourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
73C920E915414E7800C2A75A /* LLHAppDelegate.m in Sources */, | ||
73C920EA15414E7800C2A75A /* main.m in Sources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXSourcesBuildPhase section */ | ||
|
||
/* Begin XCBuildConfiguration section */ | ||
734C37B015414CE200994189 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
ARCHS = "$(ARCHS_STANDARD_64_BIT)"; | ||
COMBINE_HIDPI_IMAGES = YES; | ||
COPY_PHASE_STRIP = NO; | ||
GCC_C_LANGUAGE_STANDARD = gnu99; | ||
GCC_DYNAMIC_NO_PIC = NO; | ||
GCC_ENABLE_OBJC_EXCEPTIONS = YES; | ||
GCC_OPTIMIZATION_LEVEL = 0; | ||
GCC_PREPROCESSOR_DEFINITIONS = ( | ||
"DEBUG=1", | ||
"$(inherited)", | ||
); | ||
GCC_SYMBOLS_PRIVATE_EXTERN = NO; | ||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0; | ||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
MACOSX_DEPLOYMENT_TARGET = 10.6; | ||
ONLY_ACTIVE_ARCH = YES; | ||
SDKROOT = macosx; | ||
SKIP_INSTALL = YES; | ||
}; | ||
name = Debug; | ||
}; | ||
734C37B115414CE200994189 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
ARCHS = "$(ARCHS_STANDARD_64_BIT)"; | ||
COMBINE_HIDPI_IMAGES = YES; | ||
COPY_PHASE_STRIP = YES; | ||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; | ||
GCC_C_LANGUAGE_STANDARD = gnu99; | ||
GCC_ENABLE_OBJC_EXCEPTIONS = YES; | ||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0; | ||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
MACOSX_DEPLOYMENT_TARGET = 10.6; | ||
SDKROOT = macosx; | ||
SKIP_INSTALL = YES; | ||
}; | ||
name = Release; | ||
}; | ||
734C37B315414CE200994189 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
CODE_SIGN_ENTITLEMENTS = LaunchAtLoginHelper/LaunchAtLoginHelper.entitlements; | ||
CODE_SIGN_IDENTITY = "Mac Developer"; | ||
INFOPLIST_FILE = "LaunchAtLoginHelper/LaunchAtLoginHelper-Info.plist"; | ||
MACOSX_DEPLOYMENT_TARGET = 10.6.8; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
PROVISIONING_PROFILE = ""; | ||
WRAPPER_EXTENSION = app; | ||
}; | ||
name = Debug; | ||
}; | ||
734C37B415414CE200994189 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
CODE_SIGN_ENTITLEMENTS = LaunchAtLoginHelper/LaunchAtLoginHelper.entitlements; | ||
CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; | ||
INFOPLIST_FILE = "LaunchAtLoginHelper/LaunchAtLoginHelper-Info.plist"; | ||
MACOSX_DEPLOYMENT_TARGET = 10.6.8; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
PROVISIONING_PROFILE = ""; | ||
WRAPPER_EXTENSION = app; | ||
}; | ||
name = Release; | ||
}; | ||
/* End XCBuildConfiguration section */ | ||
|
||
/* Begin XCConfigurationList section */ | ||
734C378E15414CE200994189 /* Build configuration list for PBXProject "LaunchAtLoginHelper" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
734C37B015414CE200994189 /* Debug */, | ||
734C37B115414CE200994189 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
734C37B215414CE200994189 /* Build configuration list for PBXNativeTarget "LaunchAtLoginHelper" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
734C37B315414CE200994189 /* Debug */, | ||
734C37B415414CE200994189 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
/* End XCConfigurationList section */ | ||
}; | ||
rootObject = 734C378B15414CE200994189 /* Project object */; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// LLHAppDelegate.h | ||
// LaunchAtLoginHelper | ||
// | ||
// Created by David Keegan on 4/20/12. | ||
// Copyright (c) 2012 David Keegan. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface LLHAppDelegate : NSObject <NSApplicationDelegate> | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// LLHAppDelegate.m | ||
// LaunchAtLoginHelper | ||
// | ||
// Created by David Keegan on 4/20/12. | ||
// Copyright (c) 2012 David Keegan. All rights reserved. | ||
// | ||
|
||
#import "LLHAppDelegate.h" | ||
#import "LLStrings.h" | ||
|
||
@implementation LLHAppDelegate | ||
|
||
- (void)applicationDidFinishLaunching:(NSNotification *)notification{ | ||
// Call the scheme to launch the app | ||
NSString *scheme = [NSString stringWithFormat:@"%@://", LLURLScheme]; | ||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:scheme]]; | ||
|
||
// Call the app again this time with `launchedAtLogin` so it knows how it was launched | ||
NSString *schemeLaunchedAtLogin = | ||
[NSString stringWithFormat:@"%@://launchedAtLogin", LLURLScheme]; | ||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:schemeLaunchedAtLogin]]; | ||
[NSApp terminate:self]; | ||
} | ||
|
||
@end |
Oops, something went wrong.