Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ygini committed Apr 18, 2021
2 parents d36dfa3 + a2c181f commit e6a13cc
Show file tree
Hide file tree
Showing 78 changed files with 655 additions and 426 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ DerivedData
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#Pods/
.BuildVersion.xcconfig
24 changes: 13 additions & 11 deletions package/BuildAndPackage.command
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,25 @@ then
fi
fi

PKG_VERSION=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${PROJECT_DIR}/Hello IT/Info.plist")
MARKETING_VERSION=$(sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' "${PROJECT_DIR}/Hello-IT.xcconfig")

if [[ "$CURRENT_BRANCH" == release* ]]
then
CONFIGURATION="Release"
VERSION_FROM_BRANCH=$(echo "${CURRENT_BRANCH}" | awk -F'/' '{print $2}')
if [[ "$VERSION_FROM_BRANCH" =~ ^[0-9]+\.[0-9]+ ]]
then
PKG_VERSION=$VERSION_FROM_BRANCH
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $PKG_VERSION" "${PROJECT_DIR}/Hello IT/Info.plist"
git add "${PROJECT_DIR}/Hello IT/Info.plist"
git commit -m "Update app version number according to release branch"
MARKETING_VERSION=$VERSION_FROM_BRANCH
sed -i '' "/MARKETING_VERSION/c\\
MARKETING_VERSION = ${MARKETING_VERSION}
" "${PROJECT_DIR}/Hello-IT.xcconfig"
git add "${PROJECT_DIR}/Hello-IT.xcconfig"
git commit -m "Update marketing version number according to release branch"
fi
fi

BASE_RELEASE_LOCATION="${GIT_ROOT_DIR}/package/build"
RELEASE_LOCATION="${BASE_RELEASE_LOCATION}/${PKG_VERSION}-${CONFIGURATION}"
RELEASE_LOCATION="${BASE_RELEASE_LOCATION}/${MARKETING_VERSION}-${CONFIGURATION}"
RELEASE_PRODUCT_LOCATION="${RELEASE_LOCATION}/Products"
RELEASE_DSYM_LOCATION="${RELEASE_LOCATION}/dSYM"

Expand All @@ -206,7 +208,7 @@ echo "####### Build project"

echo "### Start building Hello IT"

xcodebuild -UseModernBuildSystem=NO -quiet -project "${PROJECT_DIR}/Hello IT.xcodeproj" -configuration ${CONFIGURATION} -target "Hello IT" CONFIGURATION_TEMP_DIR="${BUILT_PRODUCTS_DIR}/Intermediates" CONFIGURATION_BUILD_DIR="${BUILT_PRODUCTS_DIR}/Products" DWARF_DSYM_FOLDER_PATH="${BUILT_PRODUCTS_DIR}/dSYM" OTHER_CODE_SIGN_FLAGS="--timestamp"
xcodebuild -UseModernBuildSystem=NO -arch x86_64 -arch arm64 ONLY_ACTIVE_ARCH=NO -quiet -project "${PROJECT_DIR}/Hello IT.xcodeproj" -configuration ${CONFIGURATION} -target "Hello IT" CONFIGURATION_TEMP_DIR="${BUILT_PRODUCTS_DIR}/Intermediates" CONFIGURATION_BUILD_DIR="${BUILT_PRODUCTS_DIR}/Products" DWARF_DSYM_FOLDER_PATH="${BUILT_PRODUCTS_DIR}/dSYM" OTHER_CODE_SIGN_FLAGS="--timestamp"

if [[ $? != 0 ]]; then
echo "Building failed"
Expand Down Expand Up @@ -242,18 +244,18 @@ pkgbuild --analyze --root "${PKG_ROOT}" "${PBK_BUILD_COMPONENT}"

/usr/libexec/PlistBuddy -c "Set 0:BundleIsRelocatable bool false" "${PBK_BUILD_COMPONENT}"
#/usr/libexec/PlistBuddy -c "Print" "${PBK_BUILD_COMPONENT}"
pkgbuild --component-plist "${PBK_BUILD_COMPONENT}" --sign "${DEVELOPER_ID_INSTALLER}" --root "${PKG_ROOT}" --scripts "${GIT_ROOT_DIR}/package/pkg_scripts" --identifier "com.github.ygini.hello-it" --version "${PKG_VERSION}" "${RELEASE_LOCATION}/Hello-IT-${PKG_VERSION}-${CONFIGURATION}.pkg"
pkgbuild --component-plist "${PBK_BUILD_COMPONENT}" --sign "${DEVELOPER_ID_INSTALLER}" --root "${PKG_ROOT}" --scripts "${GIT_ROOT_DIR}/package/pkg_scripts" --identifier "com.github.ygini.hello-it" --version "${MARKETING_VERSION}" "${RELEASE_LOCATION}/Hello-IT-${MARKETING_VERSION}-${CONFIGURATION}.pkg"

productbuild --product "${GIT_ROOT_DIR}/package/requirements.plist" --sign "${DEVELOPER_ID_INSTALLER}" --version "${PKG_VERSION}" --package "${RELEASE_LOCATION}/Hello-IT-${PKG_VERSION}-${CONFIGURATION}.pkg" "${RELEASE_LOCATION}/Hello-IT-${PKG_VERSION}-${CONFIGURATION}-Distribution.pkg"
productbuild --product "${GIT_ROOT_DIR}/package/requirements.plist" --sign "${DEVELOPER_ID_INSTALLER}" --version "${MARKETING_VERSION}" --package "${RELEASE_LOCATION}/Hello-IT-${MARKETING_VERSION}-${CONFIGURATION}.pkg" "${RELEASE_LOCATION}/Hello-IT-${MARKETING_VERSION}-${CONFIGURATION}-Distribution.pkg"

if [[ $? != 0 ]]; then
echo "Package creation failed"
exit 1
fi

rm "${RELEASE_LOCATION}/Hello-IT-${PKG_VERSION}-${CONFIGURATION}.pkg"
rm "${RELEASE_LOCATION}/Hello-IT-${MARKETING_VERSION}-${CONFIGURATION}.pkg"

notarizePayloadWithBundleID "${RELEASE_LOCATION}/Hello-IT-${PKG_VERSION}-${CONFIGURATION}-Distribution.pkg" "com.github.ygini.hello-it"
notarizePayloadWithBundleID "${RELEASE_LOCATION}/Hello-IT-${MARKETING_VERSION}-${CONFIGURATION}-Distribution.pkg" "com.github.ygini.hello-it"

rm -rf "${PKG_ROOT}"

Expand Down
12 changes: 12 additions & 0 deletions src/HITDevKit/HITDevKit.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// HITDevKit.xcconfig
// HITDevKit
//
// Created by Yoann Gini on 18/04/2021.
// Copyright © 2021 Yoann Gini (Open Source Project). All rights reserved.
//

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

#include "../Hello-IT.xcconfig"
26 changes: 7 additions & 19 deletions src/HITDevKit/HITDevKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
E1B2C9061B593957005A9936 /* Warning.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Warning.tiff; sourceTree = "<group>"; };
E1B2C9141B5941AA005A9936 /* HITPeriodicPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HITPeriodicPlugin.h; sourceTree = "<group>"; };
E1B2C9151B5941AA005A9936 /* HITPeriodicPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HITPeriodicPlugin.m; sourceTree = "<group>"; };
F8886A0E262CC1F70039DE6C /* HITDevKit.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = HITDevKit.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -79,6 +80,7 @@
E1B2C8C71B59351B005A9936 = {
isa = PBXGroup;
children = (
F8886A0E262CC1F70039DE6C /* HITDevKit.xcconfig */,
E1B2C8D31B59351B005A9936 /* HITDevKit */,
E1B2C8E01B59351B005A9936 /* HITDevKitTests */,
E1B2C8D21B59351B005A9936 /* Products */,
Expand Down Expand Up @@ -164,7 +166,6 @@
isa = PBXNativeTarget;
buildConfigurationList = E1B2C8E71B59351B005A9936 /* Build configuration list for PBXNativeTarget "HITDevKit" */;
buildPhases = (
F8B50A231D1ECEF9003CD614 /* GitVersion */,
E1B2C8CC1B59351B005A9936 /* Sources */,
E1B2C8CD1B59351B005A9936 /* Frameworks */,
E1B2C8CE1B59351B005A9936 /* Headers */,
Expand Down Expand Up @@ -203,7 +204,7 @@
E1B2C8C81B59351B005A9936 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1140;
LastUpgradeCheck = 1240;
ORGANIZATIONNAME = "Yoann Gini (Open Source Project)";
TargetAttributes = {
E1B2C8D01B59351B005A9936 = {
Expand Down Expand Up @@ -258,23 +259,6 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
F8B50A231D1ECEF9003CD614 /* GitVersion */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = GitVersion;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -o errexit\nset -o nounset\n\nVERSION=$(git rev-list HEAD | wc -l)\n\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $VERSION\" \"${INFOPLIST_FILE}\"";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
E1B2C8CC1B59351B005A9936 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -308,6 +292,7 @@
/* Begin XCBuildConfiguration section */
E1B2C8E51B59351B005A9936 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = F8886A0E262CC1F70039DE6C /* HITDevKit.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
Expand All @@ -329,6 +314,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -365,6 +351,7 @@
};
E1B2C8E61B59351B005A9936 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = F8886A0E262CC1F70039DE6C /* HITDevKit.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
Expand All @@ -386,6 +373,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
2 changes: 1 addition & 1 deletion src/HITDevKit/HITDevKit/HITAdvancedPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2015 Yoann Gini (Open Source Project). All rights reserved.
//

#import "HITSimplePlugin.h"
#import <HITDevKit/HITSimplePlugin.h>

@interface HITAdvancedPlugin : HITSimplePlugin

Expand Down
2 changes: 1 addition & 1 deletion src/HITDevKit/HITDevKit/HITAdvancedPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (void)updateMenuItemState {
break;
case HITPluginTestStateNone:
default:
self.menuItem.image = nil;
self.menuItem.image = [self imageForMenuItem];
notificationMessage = [self localizedString:[self.settings objectForKey:kHITNotificationMessageForNoneKey]];
break;
}
Expand Down
5 changes: 3 additions & 2 deletions src/HITDevKit/HITDevKit/HITSimplePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#import <HITDevKit/HITBasicPlugin.h>

#define kHITSimplePluginTitleKey @"title"
#define kHITSimplePluginComputedTitleKey @"computedTitle"
#define kHITSimplePluginImagePathKey @"imagePath"
#define kHITSimplePluginImageBaseNameKey @"imageBaseName"

@interface HITSimplePlugin : HITBasicPlugin

@end

@interface HITSimplePlugin (MustBeDefinedInSubclass)
- (IBAction)mainAction:(id)sender;
@end
-(NSImage *)imageForMenuItem;
@end
122 changes: 108 additions & 14 deletions src/HITDevKit/HITDevKit/HITSimplePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,50 @@

#import <asl.h>

@interface HITSimplePlugin ()
@property NSString *script;
@property BOOL scriptChecked;
- (void)updateWithComputedTitle:(NSMenuItem *)menuItem;
@end

#define kHITPCustomScriptsPath @"/Library/Application Support/com.github.ygini.hello-it/CustomScripts"
#define kHITPDenyUserWritableScript @"denyUserWritableScript"

@implementation HITSimplePlugin

-(NSMenuItem *)prepareNewMenuItem {
NSString *title = [self localizedString:[self.settings objectForKey:kHITSimplePluginTitleKey]];
if (!title) {
title = @"";

- (instancetype)initWithSettings:(NSDictionary*)settings
{
self = [super initWithSettings:settings];
if (self) {

if ([[settings objectForKey:kHITSimplePluginComputedTitleKey] length] > 0) {
_script = [[NSString stringWithFormat:kHITPCustomScriptsPath] stringByAppendingPathComponent:[settings objectForKey:kHITSimplePluginComputedTitleKey]];

asl_log(NULL, NULL, ASL_LEVEL_INFO, "Loading script based plugin with script at path %s", [_script cStringUsingEncoding:NSUTF8StringEncoding]);

if ([[NSFileManager defaultManager] fileExistsAtPath:_script]) {
if ([[NSFileManager defaultManager] isWritableFileAtPath:_script] && [[NSUserDefaults standardUserDefaults] boolForKey:kHITPDenyUserWritableScript]) {
#ifdef DEBUG
_scriptChecked = YES;
#else
_scriptChecked = NO;
#endif
asl_log(NULL, NULL, ASL_LEVEL_ERR, "Target script is writable, security restriction deny such a scenario %s", [_script cStringUsingEncoding:NSUTF8StringEncoding]);
} else {
_scriptChecked = YES;
}
} else {
_scriptChecked = NO;
asl_log(NULL, NULL, ASL_LEVEL_ERR, "Target script not accessible %s", [_script cStringUsingEncoding:NSUTF8StringEncoding]);
}
}

}

NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:title
action:@selector(mainAction:)
keyEquivalent:@""];
menuItem.target = self;

return self;
}

-(NSImage *)imageForMenuItem {
NSString *imagePath = [self.settings objectForKey:kHITSimplePluginImagePathKey];
NSString *imageBaseName = [self.settings objectForKey:kHITSimplePluginImageBaseNameKey];

Expand Down Expand Up @@ -53,18 +84,81 @@ -(NSMenuItem *)prepareNewMenuItem {
}

if (imagePath) {
asl_log(NULL, NULL, ASL_LEVEL_INFO, "Menu item with title %s set with image at path %s.", [title cStringUsingEncoding:NSUTF8StringEncoding], [imagePath cStringUsingEncoding:NSUTF8StringEncoding]);
asl_log(NULL, NULL, ASL_LEVEL_INFO, "Menu item set with image at path %s.", [imagePath cStringUsingEncoding:NSUTF8StringEncoding]);
NSImage *accessoryImage = [[NSImage alloc] initWithContentsOfFile:imagePath];

if (accessoryImage) {
menuItem.image = accessoryImage;
} else {
if (!accessoryImage) {
asl_log(NULL, NULL, ASL_LEVEL_ERR, "Impossible to load image at path %s.", [imagePath cStringUsingEncoding:NSUTF8StringEncoding]);
}

return accessoryImage;
}

return nil;
}

-(NSMenuItem *)prepareNewMenuItem {
NSString *title = [self localizedString:[self.settings objectForKey:kHITSimplePluginTitleKey]];
if (!title) {
title = @"";
}


NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:title
action:@selector(mainAction:)
keyEquivalent:@""];

[self updateWithComputedTitle:menuItem];

menuItem.target = self;

menuItem.image = [self imageForMenuItem];

return menuItem;
}

- (void)updateWithComputedTitle:(NSMenuItem *)menuItem {
if (self.scriptChecked && self.allowedToRun) {
asl_log(NULL, NULL, ASL_LEVEL_INFO, "Get computed title with script %s", [self.script cStringUsingEncoding:NSUTF8StringEncoding]);

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:self.script];

[task setStandardOutput:[NSPipe pipe]];
NSFileHandle *fileToRead = [[task standardOutput] fileHandleForReading];

dispatch_io_t stdoutChannel = dispatch_io_create(DISPATCH_IO_STREAM, [fileToRead fileDescriptor], dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(int error) {

});

__block BOOL firstLine = YES;
dispatch_io_read(stdoutChannel, 0, SIZE_MAX, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(bool done, dispatch_data_t data, int error) {
if (firstLine) {
firstLine = NO;
} else {
return;
}

NSData *stdoutData = (NSData *)data;

NSString *stdoutString = [[NSString alloc] initWithData:stdoutData encoding:NSUTF8StringEncoding];

NSArray *stdoutLines = [stdoutString componentsSeparatedByString:@"\n"];
menuItem.title = [stdoutLines firstObject];
});

@try {
[task launch];

[task waitUntilExit];

asl_log(NULL, NULL, ASL_LEVEL_INFO, "Script exited with code %i", [task terminationStatus]);
} @catch (NSException *exception) {
asl_log(NULL, NULL, ASL_LEVEL_ERR, "Script failed to run: %s", [[exception reason] UTF8String]);
}
}];
}
}

@end
4 changes: 2 additions & 2 deletions src/HITDevKit/HITDevKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>367</string>
<string>$(BUILD_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Yoann Gini (Open Source Project). All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
4 changes: 2 additions & 2 deletions src/HITDevKit/HITDevKitTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(BUILD_VERSION)</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions src/HITPlugins/HITPlugins/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>$(BUILD_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Yoann Gini (Open Source Project). All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
Loading

0 comments on commit e6a13cc

Please sign in to comment.