Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ygini committed Dec 12, 2017
2 parents d6638f9 + b9fb8b2 commit 6be3008
Show file tree
Hide file tree
Showing 25 changed files with 217 additions and 170 deletions.
2 changes: 2 additions & 0 deletions package/BuildAndPackage.command
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ DEVELOPER_ID_INSTALLER=${CUSTOM_DEVELOPER_ID_INSTALLER:-${DEFAULT_DEVELOPER_ID_I

echo "Packaging will use ${DEVELOPER_ID_INSTALLER}"

cd "$(dirname "${BASH_SOURCE[0]}")"

GIT_ROOT_DIR="$(git rev-parse --show-toplevel)"
PROJECT_DIR="${GIT_ROOT_DIR}/src"
BUILT_PRODUCTS_DIR="$(mktemp -d)"
Expand Down
6 changes: 6 additions & 0 deletions src/HITDevKit/HITDevKit/HITBasicPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

#import "HITBasicPlugin.h"

#define kHITPPptionalDisplay @"optionalDisplay"

@interface HITBasicPlugin () {
NSMenuItem *_menuItem;
}

@property BOOL allowedToRun;
@property BOOL optionalDisplay;

@end

Expand All @@ -29,13 +32,16 @@ - (instancetype)initWithSettings:(NSDictionary*)settings
if (self) {
_allowedToRun = YES;
_settings = settings;

_optionalDisplay = [[settings objectForKey:kHITPPptionalDisplay] boolValue];
}
return self;
}

-(NSMenuItem *)menuItem {
if (!_menuItem) {
_menuItem = [self prepareNewMenuItem];
_menuItem.representedObject = self;
}

return _menuItem;
Expand Down
2 changes: 1 addition & 1 deletion src/HITDevKit/HITDevKit/HITPluginProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ typedef NS_ENUM(NSUInteger, HITPluginTestState) {
@required
+ (id<HITPluginProtocol>)newPlugInInstanceWithSettings:(NSDictionary*)settings;
- (NSMenuItem*)menuItem;

@property (readonly) BOOL allowedToRun;
- (void)stopAndPrepareForRelease;

@optional
@property (readonly) BOOL optionalDisplay;
- (HITPluginTestState)testState;
- (BOOL)skipForGlobalState;

Expand Down
2 changes: 1 addition & 1 deletion src/HITDevKit/HITDevKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>235</string>
<string>270</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Yoann Gini (Open Source Project). All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
56 changes: 29 additions & 27 deletions src/Hello IT/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define kMenuItemStatusBarTitle @"title"
#define kMenuItemContent @"content"
#define kMenuItemSettings @"settings"
#define kMenuItemAllowSubdomains @"allowSubdomains"

@interface AppDelegate ()

Expand All @@ -28,8 +29,8 @@ @interface AppDelegate ()
@property NSMutableArray *pluginInstances;
@property Reachability *reachability;

@property id notificationOjectForInterfaceTheme;
@property id notificationOjectForMDMUpdate;
@property id notificationObjectForInterfaceTheme;
@property id notificationObjectForMDMUpdate;

@property BOOL menuOK;

Expand Down Expand Up @@ -91,7 +92,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
asl_set_filter(NULL, ASL_FILTER_MASK_UPTO([[NSUserDefaults standardUserDefaults] integerForKey:@"loglevel"]));
}

self.notificationOjectForMDMUpdate = [[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"com.apple.MCX._managementStatusChangedForDomains"
self.notificationObjectForMDMUpdate = [[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"com.apple.MCX._managementStatusChangedForDomains"
object:nil
queue:nil
usingBlock:^(NSNotification * _Nonnull note) {
Expand All @@ -113,7 +114,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.reachability = [Reachability reachabilityWithHostname:@"captive.apple.com"];
[self.reachability startNotifier];

self.notificationOjectForInterfaceTheme = [[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"AppleInterfaceThemeChangedNotification"
self.notificationObjectForInterfaceTheme = [[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"AppleInterfaceThemeChangedNotification"
object:nil
queue:nil
usingBlock:^(NSNotification * _Nonnull note) {
Expand All @@ -125,8 +126,8 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application

[self.reachability stopNotifier];
[[NSNotificationCenter defaultCenter] removeObserver:self.notificationOjectForMDMUpdate];
[[NSNotificationCenter defaultCenter] removeObserver:self.notificationOjectForInterfaceTheme];
[[NSNotificationCenter defaultCenter] removeObserver:self.notificationObjectForMDMUpdate];
[[NSNotificationCenter defaultCenter] removeObserver:self.notificationObjectForInterfaceTheme];
}

- (void)reloadHelloIT {
Expand All @@ -144,7 +145,6 @@ - (void)reloadHelloIT {
}

- (void)updateStatusItem {

if (!self.menuOK) {
return;
}
Expand Down Expand Up @@ -187,17 +187,16 @@ - (void)updateStatusItem {
imageNameForDark = [imageName stringByAppendingString:@"-dark"];
}


NSString *customStatusBarIconBaseFolder = [NSString stringWithFormat:@"/Library/Application Support/com.github.ygini.hello-it/CustomStatusBarIcon"];


NSString *finalPath = [[customStatusBarIconBaseFolder stringByAppendingPathComponent:imageName] stringByAppendingPathExtension:@"png"];
NSString *finalPath = [[customStatusBarIconBaseFolder stringByAppendingPathComponent:imageName] stringByAppendingPathExtension:@"tiff"];

NSString *finalPathForDark = nil;
if (tryDark) {
finalPathForDark = [[customStatusBarIconBaseFolder stringByAppendingPathComponent:imageNameForDark] stringByAppendingPathExtension:@"png"];
finalPathForDark = [[customStatusBarIconBaseFolder stringByAppendingPathComponent:imageNameForDark] stringByAppendingPathExtension:@"tiff"];
asl_log(NULL, NULL, ASL_LEVEL_INFO, "We will look for menu item icon at path %s.", [finalPathForDark cStringUsingEncoding:NSUTF8StringEncoding]);
}

asl_log(NULL, NULL, ASL_LEVEL_INFO, "We will look for menu item icon at path %s.", [finalPath cStringUsingEncoding:NSUTF8StringEncoding]);

if ([[NSFileManager defaultManager] fileExistsAtPath:finalPathForDark]) {
Expand Down Expand Up @@ -272,26 +271,29 @@ - (void)loadMenu {

}

// 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:kMenuItemSettings] objectForKey:kMenuItemContent] mutableCopy];
BOOL allowSubdomains = [[NSUserDefaults standardUserDefaults] boolForKey:kMenuItemAllowSubdomains];

for (NSString *domainName in relatedDomainNames) {
asl_log(NULL, NULL, ASL_LEVEL_INFO, "Adding nested preference domain %s as first item.", [domainName UTF8String]);
NSMutableDictionary *subDomain = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:domainName] mutableCopy];
if (allowSubdomains) {
// 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];
}];

[updatedContent insertObject:subDomain
atIndex:0];
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]);
NSMutableDictionary *subDomain = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:domainName] mutableCopy];

[updatedContent insertObject:subDomain
atIndex:0];
}

NSMutableDictionary *rootItemSettings = [[compositeSettings objectForKey:kMenuItemSettings] mutableCopy];
[rootItemSettings setObject:updatedContent forKey:kMenuItemContent];
[compositeSettings setObject:rootItemSettings forKey:kMenuItemSettings];
}

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];
Expand Down
4 changes: 2 additions & 2 deletions src/Hello IT/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.2</string>
<string>1.4.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>235</string>
<string>270</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/OpenApplication/OpenApplication/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>235</string>
<string>270</string>
<key>HITPFunctionIdentifier</key>
<string>public.open.application</string>
<key>NSHumanReadableCopyright</key>
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/OpenResource/OpenResource/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>235</string>
<string>270</string>
<key>HITPFunctionIdentifier</key>
<string>public.open.resource</string>
<key>NSHumanReadableCopyright</key>
Expand Down
8 changes: 7 additions & 1 deletion src/Plugins/Quit/Quit/HITPQuit.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
@implementation HITPQuit

-(NSMenuItem *)prepareNewMenuItem {
NSMenuItem *exitItem = [[NSMenuItem alloc] initWithTitle:[[NSBundle bundleForClass:[self class]] localizedStringForKey:@"QUIT_SERVICE" value:@"" table:nil]
NSString *title = [self localizedString:[self.settings objectForKey:kHITSimplePluginTitleKey]];

if ([title length] == 0) {
title = [[NSBundle bundleForClass:[self class]] localizedStringForKey:@"QUIT_SERVICE" value:@"" table:nil];
}

NSMenuItem *exitItem = [[NSMenuItem alloc] initWithTitle:title
action:@selector(terminate:)
keyEquivalent:@""];
exitItem.target = NSApp;
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Quit/Quit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>235</string>
<string>270</string>
<key>HITPFunctionIdentifier</key>
<string>public.quit</string>
<key>NSHumanReadableCopyright</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# At each click, the script change the current controlstip
# state (full or mixed).

. "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh"
. "$HELLO_IT_SCRIPT_SH_LIBRARY/com.github.ygini.hello-it.scriptlib.sh"

function doesControlStripIsCurrentlyFull {
returnCode=$(defaults read com.apple.touchbar.agent PresentationModeGlobal 2>/dev/null | grep fullControlStrip | wc -l | bc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# to set something coherent for your main language.
# Something like "Presenter Mode" or "Hide Desktop".

. "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh"
. "$HELLO_IT_SCRIPT_SH_LIBRARY/com.github.ygini.hello-it.scriptlib.sh"

function doesDesktopIsCurrentlyHidden {
returnCode=$(defaults read com.apple.finder CreateDesktop | grep -i false | wc -l | bc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# script make usage of Base64 encoded plist
# to get the requested format

. "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh"
. "$HELLO_IT_SCRIPT_SH_LIBRARY/com.github.ygini.hello-it.scriptlib.sh"

function getHostname {
hostname=$(scutil --get HostName)
Expand Down Expand Up @@ -47,6 +47,10 @@ function setTitleAction {
updateTitleWithArgs "$@"
}

function onNetworkAction {
updateTitleWithArgs "$@"
}

main "$@"

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 1: show IP if available, specify if not, no $STATE
# 2: show IP if available, specify if not, use $STATE

. "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh"
. "$HELLO_IT_SCRIPT_SH_LIBRARY/com.github.ygini.hello-it.scriptlib.sh"

mode=0
mainBSDInterface=$(route -n get 8.8.8.8 | grep "interface: " | awk -F ": " '{print $2}')
Expand Down Expand Up @@ -92,6 +92,10 @@ function setTitleAction {
updateTitleWithArgs "$@"
}

function onNetworkAction {
updateTitleWithArgs "$@"
}

main "$@"

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 1: show IP if available, specify if not, no $STATE
# 2: show IP if available, specify if not, use $STATE

. "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh"
. "$HELLO_IT_SCRIPT_SH_LIBRARY/com.github.ygini.hello-it.scriptlib.sh"

mode=0
public_ip_url="https://ip.abelionni.com/script/"
Expand Down Expand Up @@ -92,6 +92,10 @@ function setTitleAction {
updateTitleWithArgs "$@"
}

function onNetworkAction {
updateTitleWithArgs "$@"
}

main "$@"

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To perform a sleep action
# Requires "password after sleep or screen saver begins" to be set in Security preferences

. "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh"
. "$HELLO_IT_SCRIPT_SH_LIBRARY/com.github.ygini.hello-it.scriptlib.sh"

function goToSleep {
osascript -e 'tell application "Finder" to sleep'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
E14B67D91B5905B900941A27 /* HITPScriptedItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E14B67D81B5905B900941A27 /* HITPScriptedItem.m */; };
E1B2C91F1B594C69005A9936 /* HITDevKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E1B2C91E1B594C69005A9936 /* HITDevKit.framework */; };
F84606021FCAC1FC0021DD89 /* scriptLibraries in Resources */ = {isa = PBXBuildFile; fileRef = F84606011FCAC1FC0021DD89 /* scriptLibraries */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -17,6 +18,7 @@
E14B67D71B5905B900941A27 /* HITPScriptedItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HITPScriptedItem.h; sourceTree = "<group>"; };
E14B67D81B5905B900941A27 /* HITPScriptedItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HITPScriptedItem.m; sourceTree = "<group>"; };
E1B2C91E1B594C69005A9936 /* HITDevKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HITDevKit.framework; path = "../../../../../Library/Developer/Xcode/DerivedData/Hello_IT-dblktlmawojysuccadblmqsuewcj/Build/Products/Debug/HITDevKit.framework"; sourceTree = "<group>"; };
F84606011FCAC1FC0021DD89 /* scriptLibraries */ = {isa = PBXFileReference; lastKnownFileType = folder; path = scriptLibraries; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -34,6 +36,7 @@
E14B67BC1B59059000941A27 = {
isa = PBXGroup;
children = (
F84606011FCAC1FC0021DD89 /* scriptLibraries */,
E1B2C91E1B594C69005A9936 /* HITDevKit.framework */,
E14B67C71B59059000941A27 /* ScriptedItem */,
E14B67C61B59059000941A27 /* Products */,
Expand Down Expand Up @@ -125,6 +128,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F84606021FCAC1FC0021DD89 /* scriptLibraries in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading

0 comments on commit 6be3008

Please sign in to comment.