Skip to content
This repository has been archived by the owner on Jul 18, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/EasySIMBL-1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
norio-nomura committed Nov 25, 2013
2 parents 379dfae + 6f25c56 commit 83022d5
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 48 deletions.
4 changes: 4 additions & 0 deletions EasySIMBL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
6C564497159E7C0900215467 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = AppDelegate.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
6C56449A159E7C0900215467 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
6C5644B7159E7D3900215467 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; };
6C6AF45E1842DE3700E2ACBB /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
6CCA2AEE15AAB8670085ABB4 /* SIMBL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = SIMBL.h; path = ../src/SIMBL.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
6CCA2AEF15AAB8670085ABB4 /* SIMBL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = SIMBL.m; path = ../src/SIMBL.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
AA7EB1D915A45EC100D76CFC /* ESPluginListManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ESPluginListManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -111,6 +112,7 @@
6C564475159E7C0800215467 = {
isa = PBXGroup;
children = (
6C6AF45E1842DE3700E2ACBB /* README.md */,
6C3A4C2B159E7E6F00985CCD /* SIMBL.xcodeproj */,
6C56448A159E7C0800215467 /* EasySIMBL */,
6C564483159E7C0800215467 /* Frameworks */,
Expand Down Expand Up @@ -325,6 +327,7 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
Expand Down Expand Up @@ -358,6 +361,7 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
Expand Down
4 changes: 2 additions & 2 deletions EasySIMBL/EasySIMBL-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.1</string>
<string>1.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>9</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ Changes from [original SIMBL](http://www.culater.net/software/SIMBL/SIMBL.php)
- Drag and Drop install to `/Applications` or `~/Applications` folder, no uninstaller required.
- Change injection method.
- Install plugins(.bundle) from Finder.
- **NEW** Support injecting plugins into background process `LSBackgroundOnly=1` and agent process `LSUIElement=1`, if plugin has explicitly targeting application bundle identifier (not `*`. e.g. `com.apple.appkit.xpc.openAndSavePanelService`, `com.apple.dock` or `com.apple.security.pboxd`).

How to install
--------------
1. Download [EasySIMBL-1.5.1.zip](http://github.com/norio-nomura/EasySIMBL/releases/download/EasySIMBL-1.5.1/EasySIMBL-1.5.1.zip) (2013/10/29 updated)
1. Download [EasySIMBL-1.6.zip](http://github.com/norio-nomura/EasySIMBL/releases/download/EasySIMBL-1.6/EasySIMBL-1.6.zip) (2013/11/25 updated)
2. Extract and move `EasySIMBL.app` into `/Applications` or `~/Applications`.
3. Launch `EasySIMBL.app` and check `Use SIMBL`, then quit `EasySIMBL.app`.

Expand Down Expand Up @@ -41,6 +42,7 @@ Tested combinations of OS X and applications
- Finder & [ColorfulSidebar 1.1.1](http://cooviewerzoom.web.fc2.com/colorfulsidebar.html) (without PowerboxInjector)
- Safari 7.0 & [SafariStand 6.0.200](https://github.com/hetima/SafariStand)
- [Echofon for Mac 1.8.0](https://itunes.apple.com/jp/app/echofon-for-twitter/id403830270?mt=12) & [SimblPluginsForEchofon-1.4](https://github.com/norio-nomura/SimblPluginsForEchofon)
- Dock & [BlackDock 0.8.0](http://cooviewerzoom.web.fc2.com/blackdock.html)

_PowerboxInjector is not compatible with EasySIMBL. Sorry, the reason exists on EasySIMBL side._

Expand Down
79 changes: 53 additions & 26 deletions SIMBL Agent/SIMBLAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ - (void) applicationDidFinishLaunching:(NSNotification*)notificaion
[defaults synchronize];

NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
[[workspace notificationCenter] addObserver:self
selector:@selector(applicationLaunched:)
name:NSWorkspaceDidLaunchApplicationNotification object:nil];
[workspace addObserver:self
forKeyPath:@"runningApplications"
options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld
context:NULL];

// inject into resumed applications
for (NSRunningApplication *runningApp in [workspace runningApplications]) {
Expand All @@ -85,13 +86,6 @@ - (id) eventDidFail:(const AppleEvent *)event withError:(NSError *)error;
return nil;
}

#pragma mark NSWorkspaceDidLaunchApplicationNotification

- (void) applicationLaunched:(NSNotification*)notification
{
[self injectSIMBL:[[notification userInfo]objectForKey:NSWorkspaceApplicationKey]];
}

#pragma mark NSKeyValueObserving Protocol

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
Expand All @@ -101,6 +95,31 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
[object removeObserver:self forKeyPath:keyPath];

[self injectContainerForApplication:(NSRunningApplication*)object enabled:NO];
} else if ([keyPath isEqualToString:@"runningApplications"]) {
// for apps which will be terminated without called @"isFinishedLaunching"
static NSMutableSet *appsObservingFinishedLaunching = nil;
if (!appsObservingFinishedLaunching) {
appsObservingFinishedLaunching = [NSMutableSet set];
}

for (NSRunningApplication *app in [change objectForKey:NSKeyValueChangeNewKey]) {
if (app.isFinishedLaunching) {
SIMBLLogDebug(@"runningApp %@ is already isFinishedLaunching", app);
[self injectSIMBL:app];
} else {
[app addObserver:self forKeyPath:@"isFinishedLaunching" options:NSKeyValueObservingOptionNew context:NULL];
[appsObservingFinishedLaunching addObject:app];
}
}
for (NSRunningApplication *app in [change objectForKey:NSKeyValueChangeOldKey]) {
if ([appsObservingFinishedLaunching containsObject:app]) {
[app removeObserver:self forKeyPath:@"isFinishedLaunching"];
[appsObservingFinishedLaunching removeObject:app];
}
}
} else if ([keyPath isEqualToString:@"isFinishedLaunching"]) {
SIMBLLogDebug(@"runningApp %@ isFinishedLaunching.", object);
[self injectSIMBL:(NSRunningApplication*)object];
}
}

Expand Down Expand Up @@ -129,12 +148,17 @@ - (void) injectSIMBL:(NSRunningApplication *)runningApp
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults synchronize];

if ([[NSRunningApplication currentApplication]isEqual:runningApp]) {
return;
}

NSString* appName = [runningApp localizedName];
SIMBLLogInfo(@"%@ started", appName);
SIMBLLogDebug(@"app start notification: %@", runningApp);

// check to see if there are plugins to load
if (![runningApp bundleURL] || [SIMBL shouldInstallPluginsIntoApplication:[NSBundle bundleWithURL:[runningApp bundleURL]]] == NO) {
if ([SIMBL shouldInstallPluginsIntoApplication:runningApp] == NO) {
SIMBLLogDebug(@"No plugins match for %@", runningApp);
return;
}

Expand Down Expand Up @@ -249,8 +273,10 @@ - (void) injectSIMBL:(NSRunningApplication *)runningApp
- (void)injectContainerForApplication:(NSRunningApplication*)runningApp enabled:(BOOL)bEnabled;
{
NSString *identifier = [runningApp bundleIdentifier];
if ([self injectContainerBundleIdentifier:identifier enabled:bEnabled]) {
if (bEnabled) {
if (bEnabled) {
if ([self injectContainerBundleIdentifier:identifier enabled:YES]) {
SIMBLLogDebug(@"Start observing %@'s 'isTerminated'.", identifier);

[runningApp addObserver:self forKeyPath:@"isTerminated" options:NSKeyValueObservingOptionNew context:NULL];
[self.runningSandboxedApplications addObject:runningApp];

Expand All @@ -261,17 +287,18 @@ - (void)injectContainerForApplication:(NSRunningApplication*)runningApp enabled:
[[NSUserDefaults standardUserDefaults]setObject:[injectedSandboxBundleIdentifierSet allObjects]
forKey:kInjectedSandboxBundleIdentifiers];
[[NSUserDefaults standardUserDefaults]synchronize];

[[NSProcessInfo processInfo]disableSuddenTermination];
} else {
BOOL (^hasSameBundleIdentifier)(id, NSUInteger, BOOL *) = ^(id obj, NSUInteger idx, BOOL *stop) {
return *stop = [identifier isEqualToString:[(NSRunningApplication*)obj bundleIdentifier]];
};

[self.runningSandboxedApplications removeObject:runningApp];
// check multi instance application
if (NSNotFound == [self.runningSandboxedApplications indexOfObjectWithOptions:NSEnumerationConcurrent
passingTest:hasSameBundleIdentifier]) {
}
} else {
BOOL (^hasSameBundleIdentifier)(id, NSUInteger, BOOL *) = ^(id obj, NSUInteger idx, BOOL *stop) {
return *stop = [identifier isEqualToString:[(NSRunningApplication*)obj bundleIdentifier]];
};

[self.runningSandboxedApplications removeObject:runningApp];
// check multi instance application
if (NSNotFound == [self.runningSandboxedApplications indexOfObjectWithOptions:NSEnumerationConcurrent
passingTest:hasSameBundleIdentifier]) {
if ([self injectContainerBundleIdentifier:identifier enabled:NO]) {

NSMutableSet *injectedSandboxBundleIdentifierSet = [NSMutableSet set];
for (NSRunningApplication *app in self.runningSandboxedApplications) {
[injectedSandboxBundleIdentifierSet addObject:[app bundleIdentifier]];
Expand All @@ -280,8 +307,6 @@ - (void)injectContainerForApplication:(NSRunningApplication*)runningApp enabled:
forKey:kInjectedSandboxBundleIdentifiers];
[[NSUserDefaults standardUserDefaults]synchronize];
}

[[NSProcessInfo processInfo]enableSuddenTermination];
}
}
}
Expand Down Expand Up @@ -310,6 +335,7 @@ - (BOOL)injectContainerBundleIdentifier:(NSString*)bundleIdentifier enabled:(BOO
SIMBLLogNotice(@"linkItemAtPath error:%@",error);
}
bResult = YES;
SIMBLLogDebug(@"%@'s container has been injected.", bundleIdentifier);
} else {
if (![fileManager removeItemAtPath:containerScriptingAddtionsPath error:&error]) {
SIMBLLogNotice(@"removeItemAtPath error:%@",error);
Expand All @@ -321,6 +347,7 @@ - (BOOL)injectContainerBundleIdentifier:(NSString*)bundleIdentifier enabled:(BOO
SIMBLLogNotice(@"removeItemAtPath error:%@",error);
}
bResult = YES;
SIMBLLogDebug(@"%@'s container has been uninjected.", bundleIdentifier);
}
}
return bResult;
Expand Down
6 changes: 4 additions & 2 deletions SIMBL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = src/SIMBL_Prefix.pch;
Expand All @@ -373,7 +374,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_VERSION = 0.10.7;
PRODUCT_VERSION = 0.10.8;
SDKROOT = macosx;
};
name = Debug;
Expand All @@ -383,6 +384,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = src/SIMBL_Prefix.pch;
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
Expand All @@ -392,7 +394,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_VERSION = 0.10.7;
PRODUCT_VERSION = 0.10.8;
SDKROOT = macosx;
};
name = Release;
Expand Down
4 changes: 3 additions & 1 deletion src/SIMBL.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- (NSString*) _dt_version;
- (NSString*) _dt_bundleVersion;
- (NSString*) _dt_name;
- (BOOL) SIMBL_isLSUIElement;
- (BOOL) SIMBL_isLSBackgroundOnly;

@end

Expand Down Expand Up @@ -60,7 +62,7 @@

+ (void) logMessage:(NSString*)message atLevel:(int)level;
+ (void) installPlugins;
+ (BOOL) shouldInstallPluginsIntoApplication:(NSBundle*)_appBundle;
+ (BOOL) shouldInstallPluginsIntoApplication:(NSRunningApplication*)runningApp;

+ (NSString*)applicationSupportPath;

Expand Down
56 changes: 40 additions & 16 deletions src/SIMBL.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ - (NSString*) _dt_name
return [self SIMBL_objectForInfoDictionaryKey:(NSString*)kCFBundleNameKey];
}

- (BOOL) SIMBL_isLSUIElement
{
return [[self SIMBL_objectForInfoDictionaryKey:@"LSUIElement"]boolValue];
}

- (BOOL) SIMBL_isLSBackgroundOnly
{
return [[self SIMBL_objectForInfoDictionaryKey:@"LSBackgroundOnly"]boolValue];
}

@end

/*
Expand Down Expand Up @@ -98,7 +108,7 @@ + (void) logMessage:(NSString*)message atLevel:(int)level
[defaults addSuiteNamed:EasySIMBLSuiteBundleIdentifier];
}
if ([defaults integerForKey:SIMBLPrefKeyLogLevel] <= level) {
NSLog(@"%@", message);
NSLog(@"#EasySIMBL %@", message);
}
}

Expand Down Expand Up @@ -142,12 +152,14 @@ + (void) installPlugins
}


+ (BOOL) shouldInstallPluginsIntoApplication:(NSBundle*)_appBundle
+ (BOOL) shouldInstallPluginsIntoApplication:(NSRunningApplication*)runningApp;
{
for (NSString* path in [SIMBL pluginPathList]) {
BOOL bundleLoaded = [SIMBL shouldApplication:_appBundle loadBundleAtPath:path];
if (bundleLoaded)
BOOL bundleShouldInstallPlugins = [SIMBL shouldApplication:runningApp loadBundleAtPath:path];
if (bundleShouldInstallPlugins) {
SIMBLLogDebug(@"should install plugin %@", path);
return YES;
}
}
return NO;
}
Expand All @@ -173,8 +185,8 @@ + (NSString*)applicationSupportPath;
*/
+ (BOOL) shouldLoadBundleAtPath:(NSString*)_bundlePath
{
NSBundle* appBundle = [NSBundle mainBundle];
return [SIMBL shouldApplication:appBundle loadBundleAtPath:_bundlePath];
NSRunningApplication *runningApp = [NSRunningApplication currentApplication];
return [SIMBL shouldApplication:runningApp loadBundleAtPath:_bundlePath];
}


Expand All @@ -183,7 +195,7 @@ + (BOOL) shouldLoadBundleAtPath:(NSString*)_bundlePath
* the special value * will cause any Cocoa app to load a bundle
* @return YES if this should be loaded
*/
+ (BOOL) shouldApplication:(NSBundle*)_appBundle loadBundleAtPath:(NSString*)_bundlePath
+ (BOOL) shouldApplication:(NSRunningApplication*)runningApp loadBundleAtPath:(NSString*)_bundlePath
{
SIMBLLogDebug(@"checking bundle %@", _bundlePath);
_bundlePath = [_bundlePath stringByStandardizingPath];
Expand All @@ -202,12 +214,12 @@ + (BOOL) shouldApplication:(NSBundle*)_appBundle loadBundleAtPath:(NSString*)_bu
// this is the new way of specifying when to load a bundle
NSArray* targetApplications = [pluginBundle SIMBL_objectForInfoDictionaryKey:SIMBLTargetApplications];
if (targetApplications)
return [self shouldApplication:_appBundle loadBundle:pluginBundle withTargetApplications:targetApplications];
return [self shouldApplication:runningApp loadBundle:pluginBundle withTargetApplications:targetApplications];

// fall back to the old method for older plugins - we should probably throw a depreaction warning
NSArray* applicationIdentifiers = [pluginBundle SIMBL_objectForInfoDictionaryKey:SIMBLApplicationIdentifier];
if (applicationIdentifiers)
return [self shouldApplication:_appBundle loadBundle:pluginBundle withApplicationIdentifiers:applicationIdentifiers];
return [self shouldApplication:runningApp loadBundle:pluginBundle withApplicationIdentifiers:applicationIdentifiers];

return NO;
}
Expand Down Expand Up @@ -241,15 +253,18 @@ + (BOOL) loadBundleAtPath:(NSString*)_bundlePath
* get this list of allowed application identifiers from the plugin's Info.plist
* the special value * will cause any Cocoa app to load a bundle
* if there is a match, this calls the main bundle's load method
* @return YES if this bundle was loaded
* @return YES if this bundle should be loaded
*/
+ (BOOL) shouldApplication:(NSBundle*)_appBundle loadBundle:(NSBundle*)_bundle withApplicationIdentifiers:(NSArray*)_applicationIdentifiers
+ (BOOL) shouldApplication:(NSRunningApplication*)runningApp loadBundle:(NSBundle*)_bundle withApplicationIdentifiers:(NSArray*)_applicationIdentifiers
{
NSString* appIdentifier = [_appBundle bundleIdentifier];
NSString* appIdentifier = [runningApp bundleIdentifier];
for (NSString* specifiedIdentifier in _applicationIdentifiers) {
SIMBLLogDebug(@"checking bundle %@ for identifier %@", [_bundle bundleIdentifier], specifiedIdentifier);
if ([specifiedIdentifier isEqualToString:appIdentifier] == YES ||
[specifiedIdentifier isEqualToString:@"*"] == YES) {
// wildcard targeting plugins should not be loaded into background apps or agent apps
([specifiedIdentifier isEqualToString:@"*"] == YES &&
runningApp.activationPolicy != NSApplicationActivationPolicyAccessory &&
runningApp.activationPolicy != NSApplicationActivationPolicyProhibited)) {
SIMBLLogDebug(@"load bundle %@", [_bundle bundleIdentifier]);
SIMBLLogNotice(@"The plugin %@ (%@) is using a deprecated interface to SIMBL. Please contact the appropriate developer (not the SIMBL author) and refer them to http://code.google.com/p/simbl/wiki/Tutorial", [_bundle bundlePath], [_bundle bundleIdentifier]);
return YES;
Expand All @@ -264,14 +279,23 @@ + (BOOL) shouldApplication:(NSBundle*)_appBundle loadBundle:(NSBundle*)_bundle w
* get this list of allowed target applications from the plugin's Info.plist
* the special value * will cause any Cocoa app to load a bundle
* if there is a match, this calls the main bundle's load method
* @return YES if this bundle was loaded
* @return YES if this bundle should be loaded
*/
+ (BOOL) shouldApplication:(NSBundle*)_appBundle loadBundle:(NSBundle*)_bundle withTargetApplications:(NSArray*)_targetApplications
+ (BOOL) shouldApplication:(NSRunningApplication*)runningApp loadBundle:(NSBundle*)_bundle withTargetApplications:(NSArray*)_targetApplications
{
NSString* appIdentifier = [_appBundle bundleIdentifier];
NSString* appIdentifier = [runningApp bundleIdentifier];
NSURL *bundleURL = runningApp.bundleURL;
NSBundle *_appBundle = bundleURL ? [NSBundle bundleWithURL:bundleURL] : nil;
for (NSDictionary* targetAppProperties in _targetApplications) {
NSString* targetAppIdentifier = [targetAppProperties objectForKey:SIMBLBundleIdentifier];
SIMBLLogDebug(@"checking target identifier %@", targetAppIdentifier);

// wildcard targeting plugins should not be loaded into background apps or agent apps
if ([targetAppIdentifier isEqualToString:@"*"] == YES &&
(runningApp.activationPolicy == NSApplicationActivationPolicyAccessory ||
runningApp.activationPolicy == NSApplicationActivationPolicyProhibited))
continue;

if ([targetAppIdentifier isEqualToString:appIdentifier] == NO &&
[targetAppIdentifier isEqualToString:@"*"] == NO)
continue;
Expand Down

0 comments on commit 83022d5

Please sign in to comment.