Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ygini committed Sep 27, 2017
2 parents c0be60c + 48ff26c commit fbbb997
Show file tree
Hide file tree
Showing 33 changed files with 826 additions and 147 deletions.
11 changes: 10 additions & 1 deletion src/HITDevKit/HITDevKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
E1B2C8C81B59351B005A9936 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0640;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = "Yoann Gini (Open Source Project)";
TargetAttributes = {
E1B2C8D01B59351B005A9936 = {
Expand Down Expand Up @@ -314,14 +314,17 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -359,8 +362,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -396,6 +401,7 @@
INFOPLIST_FILE = HITDevKit/Info.plist;
INSTALL_PATH = "@loader_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.ygini.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Expand All @@ -413,6 +419,7 @@
INFOPLIST_FILE = HITDevKit/Info.plist;
INSTALL_PATH = "@loader_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.ygini.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Expand All @@ -432,6 +439,7 @@
);
INFOPLIST_FILE = HITDevKitTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.ygini.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -446,6 +454,7 @@
);
INFOPLIST_FILE = HITDevKitTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.ygini.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions src/HITDevKit/HITDevKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.github.ygini.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>199</string>
<string>217</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Yoann Gini (Open Source Project). All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion src/HITDevKit/HITDevKitTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.github.ygini.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
43 changes: 43 additions & 0 deletions src/Hello IT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
E1D068081B51D08E00567172 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = E1D068061B51D08E00567172 /* MainMenu.xib */; };
E1D068141B51D08F00567172 /* Hello_ITTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E1D068131B51D08F00567172 /* Hello_ITTests.m */; };
E1D0681F1B51D4B500567172 /* HITPluginsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E1D0681E1B51D4B500567172 /* HITPluginsManager.m */; };
F83294DD1F7736B5009DA574 /* ADPass.hitp in Copy Default Plugins */ = {isa = PBXBuildFile; fileRef = F83294B31F773078009DA574 /* ADPass.hitp */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
F8340B8C1C96CF9000C820D7 /* statusbar-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = F8340B781C96CF9000C820D7 /* statusbar-dark.png */; };
F8340B8D1C96CF9000C820D7 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = F8340B791C96CF9000C820D7 /* [email protected] */; };
F8340B8E1C96CF9000C820D7 /* statusbar-error-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = F8340B7A1C96CF9000C820D7 /* statusbar-error-dark.png */; };
Expand Down Expand Up @@ -123,6 +124,20 @@
remoteGlobalIDString = E1D067F91B51D08E00567172;
remoteInfo = "Hello IT";
};
F83294B21F773078009DA574 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = F83294AE1F773076009DA574 /* ADPass.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = F83294A51F773076009DA574;
remoteInfo = ADPass;
};
F86CCC0A1F790D250043CF55 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = F83294AE1F773076009DA574 /* ADPass.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = F83294A41F773076009DA574;
remoteInfo = ADPass;
};
F8F4E5761F1A73CC004E8789 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E1B2C8ED1B59351B005A9936 /* HITDevKit.xcodeproj */;
Expand Down Expand Up @@ -195,6 +210,7 @@
dstPath = "";
dstSubfolderSpec = 13;
files = (
F83294DD1F7736B5009DA574 /* ADPass.hitp in Copy Default Plugins */,
E14B67DA1B59110D00941A27 /* ScriptedItem.hitp in Copy Default Plugins */,
E14B67BB1B57888700941A27 /* OpenApplication.hitp in Copy Default Plugins */,
E1AF407B1B52A6030017B4DD /* SubMenu.hitp in Copy Default Plugins */,
Expand Down Expand Up @@ -242,6 +258,7 @@
E1D068131B51D08F00567172 /* Hello_ITTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Hello_ITTests.m; sourceTree = "<group>"; };
E1D0681D1B51D4B500567172 /* HITPluginsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HITPluginsManager.h; sourceTree = "<group>"; };
E1D0681E1B51D4B500567172 /* HITPluginsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HITPluginsManager.m; sourceTree = "<group>"; };
F83294AE1F773076009DA574 /* ADPass.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ADPass.xcodeproj; path = ADPass/ADPass.xcodeproj; sourceTree = "<group>"; };
F8340B781C96CF9000C820D7 /* statusbar-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "statusbar-dark.png"; sourceTree = "<group>"; };
F8340B791C96CF9000C820D7 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
F8340B7A1C96CF9000C820D7 /* statusbar-error-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "statusbar-error-dark.png"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -311,6 +328,7 @@
E17743301B51E6E600A5B406 /* Plugins */ = {
isa = PBXGroup;
children = (
F83294AE1F773076009DA574 /* ADPass.xcodeproj */,
E17743591B51EA8500A5B406 /* OpenResource.xcodeproj */,
E17743751B51F19B00A5B406 /* Separator.xcodeproj */,
E17743941B51F2C900A5B406 /* Title.xcodeproj */,
Expand Down Expand Up @@ -435,6 +453,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
F83294AF1F773076009DA574 /* Products */ = {
isa = PBXGroup;
children = (
F83294B31F773078009DA574 /* ADPass.hitp */,
);
name = Products;
sourceTree = "<group>";
};
F86928FA1CA28B8800AB8E4C /* statusbar */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -480,6 +506,7 @@
);
dependencies = (
F8F4E5771F1A73CC004E8789 /* PBXTargetDependency */,
F86CCC0B1F790D250043CF55 /* PBXTargetDependency */,
F8F4E5791F1A73CC004E8789 /* PBXTargetDependency */,
F8F4E57B1F1A73CC004E8789 /* PBXTargetDependency */,
F8F4E57D1F1A73CC004E8789 /* PBXTargetDependency */,
Expand Down Expand Up @@ -542,6 +569,10 @@
productRefGroup = E1D067FB1B51D08E00567172 /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = F83294AF1F773076009DA574 /* Products */;
ProjectRef = F83294AE1F773076009DA574 /* ADPass.xcodeproj */;
},
{
ProductGroup = E1B2C8EE1B59351B005A9936 /* Products */;
ProjectRef = E1B2C8ED1B59351B005A9936 /* HITDevKit.xcodeproj */;
Expand Down Expand Up @@ -658,6 +689,13 @@
remoteRef = E1B2C8F41B59351C005A9936 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
F83294B31F773078009DA574 /* ADPass.hitp */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = ADPass.hitp;
remoteRef = F83294B21F773078009DA574 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
Expand Down Expand Up @@ -744,6 +782,11 @@
target = E1D067F91B51D08E00567172 /* Hello IT */;
targetProxy = E1D0680E1B51D08F00567172 /* PBXContainerItemProxy */;
};
F86CCC0B1F790D250043CF55 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = ADPass;
targetProxy = F86CCC0A1F790D250043CF55 /* PBXContainerItemProxy */;
};
F8F4E5771F1A73CC004E8789 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = HITDevKit;
Expand Down
81 changes: 45 additions & 36 deletions src/Hello IT/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ @interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@property (strong) NSStatusItem *statusItem;
@property (strong) IBOutlet NSMenu *statusMenu;
@property id<HITPluginProtocol> statusMenuManager;
@property NSMutableArray *pluginInstances;
@property Reachability *reachability;

@property (nonatomic) HITPluginTestState testState;

@property id notificationOjectForInterfaceTheme;
@property id notificationOjectForMDMUpdate;

Expand Down Expand Up @@ -96,12 +93,18 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
queue:nil
usingBlock:^(NSNotification * _Nonnull note) {
NSArray *domains = [note.userInfo objectForKey:@"com.apple.MCX.changedDomains"];
if ([domains containsObject:[[NSBundle mainBundle] bundleIdentifier]]) {
[self reloadHelloIT];

for (NSString *domain in domains) {
if ([[domain lowercaseString] rangeOfString:[[[NSBundle mainBundle] bundleIdentifier] lowercaseString]].location == 0) {
[self reloadHelloIT];
}
}

}];


self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];

[self reloadHelloIT];

self.reachability = [Reachability reachabilityWithHostname:@"captive.apple.com"];
Expand Down Expand Up @@ -132,9 +135,6 @@ - (void)reloadHelloIT {
}


self.statusMenu = [[NSMenu alloc] init];
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];

[[HITPluginsManager sharedInstance] loadPluginsWithCompletionHandler:^(HITPluginsManager *pluginsManager) {
[self loadMenu];
}];
Expand All @@ -146,6 +146,13 @@ - (void)updateStatusItem {
return;
}

HITPluginTestState statusMenuState = HITPluginTestStateNone;

if ([self.statusMenuManager respondsToSelector:@selector(testState)]) {
statusMenuState |= [self.statusMenuManager testState];
asl_log(NULL, NULL, ASL_LEVEL_INFO, "General state has changed for %lu.", (unsigned long)statusMenuState);
}

NSString *iconTitle = [[NSUserDefaults standardUserDefaults] stringForKey:kMenuItemStatusBarTitle];

if ([iconTitle length] == 0) {
Expand All @@ -154,7 +161,7 @@ - (void)updateStatusItem {
BOOL tryDark = NO;
NSImage *icon;

switch (self.testState) {
switch (statusMenuState) {
case HITPluginTestStateError:
imageName = @"statusbar-error";
break;
Expand Down Expand Up @@ -213,7 +220,7 @@ - (void)updateStatusItem {
NSColor *textColor = nil;
NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];

switch (self.testState) {
switch (statusMenuState) {
case HITPluginTestStateError:
textColor = [NSColor redColor];
break;
Expand All @@ -240,12 +247,31 @@ - (void)updateStatusItem {
}

- (void)loadMenu {
NSMutableDictionary *compositeSettings = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] mutableCopy];
NSArray *relatedDomainNames = [[[[NSUserDefaults standardUserDefaults] persistentDomainNames] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF BEGINSWITH %@", @"com.github.ygini.Hello-IT."]] sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
NSMutableDictionary *compositeSettings = [NSMutableDictionary dictionaryWithCapacity:2];

NSArray *oldStyleRootContent = [[NSUserDefaults standardUserDefaults] arrayForKey:kMenuItemContent];

if (oldStyleRootContent) {
// We have pre 1.3 preferences, were root item is the settings for public.submenu instead of regular item settings
// We need to rebuild the settings to fill 1.3+ needs, with root item being exactly like another item

[compositeSettings setObject:@"public.submenu" forKey:kMenuItemFunctionIdentifier];
[compositeSettings setObject:@{kMenuItemContent: oldStyleRootContent} forKey:kMenuItemSettings];

} else {
// 1.3+ version support standard function and settings keys at root, allowing end IT to use custom functions more easily

[compositeSettings setObject:[[NSUserDefaults standardUserDefaults] stringForKey:kMenuItemFunctionIdentifier] forKey:kMenuItemFunctionIdentifier];
[compositeSettings setObject:[[NSUserDefaults standardUserDefaults] dictionaryForKey:kMenuItemSettings] forKey:kMenuItemSettings];

}

// HIT support composed menu item, all user's preferences starting with "bundleID." will be loaded as first item
NSArray *relatedDomainNames = [[[[NSUserDefaults standardUserDefaults] persistentDomainNames] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] %@", [[[NSBundle mainBundle] bundleIdentifier] stringByAppendingString:@"."]]] sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
return [obj2 compare:obj1];
}];

NSMutableArray *updatedContent = [[compositeSettings objectForKey:kMenuItemContent] mutableCopy];
NSMutableArray *updatedContent = [[[compositeSettings objectForKey:kMenuItemSettings] objectForKey:kMenuItemContent] mutableCopy];

for (NSString *domainName in relatedDomainNames) {
asl_log(NULL, NULL, ASL_LEVEL_INFO, "Adding nested preference domain %s as first item.", [domainName UTF8String]);
Expand All @@ -255,21 +281,18 @@ - (void)loadMenu {
atIndex:0];
}

[compositeSettings setObject:updatedContent forKey:kMenuItemContent];

NSString *menuBuilder = [compositeSettings objectForKey:kMenuItemFunctionIdentifier];

if ([menuBuilder length] == 0) {
menuBuilder = @"public.submenu";
}
NSMutableDictionary *rootItemSettings = [[compositeSettings objectForKey:kMenuItemSettings] mutableCopy];
[rootItemSettings setObject:updatedContent forKey:kMenuItemContent];
[compositeSettings setObject:rootItemSettings forKey:kMenuItemSettings];


if ([self.statusMenuManager respondsToSelector:@selector(testState)]) {
NSObject<HITPluginProtocol> *observablePluginInstance = self.statusMenuManager;
[observablePluginInstance removeObserver:self forKeyPath:@"testState" context:nil];
}

Class<HITPluginProtocol> SubMenuPlugin = [[HITPluginsManager sharedInstance] mainClassForPluginWithFunctionIdentifier:menuBuilder];
self.statusMenuManager = [SubMenuPlugin newPlugInInstanceWithSettings:compositeSettings];
Class<HITPluginProtocol> SubMenuPlugin = [[HITPluginsManager sharedInstance] mainClassForPluginWithFunctionIdentifier:[compositeSettings objectForKey:kMenuItemFunctionIdentifier]];
self.statusMenuManager = [SubMenuPlugin newPlugInInstanceWithSettings:[compositeSettings objectForKey:kMenuItemSettings]];
if (self.statusMenuManager) {
if ([self.statusMenuManager respondsToSelector:@selector(setPluginsManager:)]) {
[self.statusMenuManager setPluginsManager:[HITPluginsManager sharedInstance]];
Expand All @@ -293,20 +316,6 @@ - (void)loadMenu {

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"testState"]) {
int substate = HITPluginTestStateNone;

if ([self.statusMenuManager respondsToSelector:@selector(testState)]) {
substate |= [self.statusMenuManager testState];
}

if (substate&HITPluginTestStateError) self.testState = HITPluginTestStateError;
else if (substate&HITPluginTestStateWarning) self.testState = HITPluginTestStateWarning;
else if (substate&HITPluginTestStateUnavailable) self.testState = HITPluginTestStateUnavailable;
else if (substate&HITPluginTestStateOK) self.testState = HITPluginTestStateOK;
else self.testState = HITPluginTestStateNone;

asl_log(NULL, NULL, ASL_LEVEL_INFO, "General state has changed for %lu.", (unsigned long)self.testState);

[self updateStatusItem];
}
}
Expand Down
Loading

0 comments on commit fbbb997

Please sign in to comment.