Skip to content

Commit

Permalink
Merge pull request #156 from newmarcel/version-1.6.1
Browse files Browse the repository at this point in the history
Version 1.6.1
  • Loading branch information
newmarcel committed Apr 15, 2021
2 parents 2e69723 + 875b91a commit ab63a1f
Show file tree
Hide file tree
Showing 153 changed files with 2,542 additions and 1,124 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@

## Changelog ##

### v1.6.1 ###

- added support for notifications, use `System Preferences` to manage notification settings ([#164](https://github.com/newmarcel/KeepingYouAwake/pull/164))
- please note, this feature is only available on macOS 11 or newer; the previous experimental notifications support has been removed

### v1.6.0 ###

- raised minimum deployment target to macOS Sierra ([#142](https://github.com/newmarcel/KeepingYouAwake/pull/142))
Expand Down
4 changes: 2 additions & 2 deletions Configuration.xcconfig
Expand Up @@ -9,8 +9,8 @@
MACOSX_DEPLOYMENT_TARGET = 10.12
PRODUCT_BUNDLE_IDENTIFIER = info.marcel-dierkes.KeepingYouAwake

MARKETING_VERSION = 1.6.0
CURRENT_PROJECT_VERSION = 1060001
MARKETING_VERSION = 1.6.1beta1
CURRENT_PROJECT_VERSION = 1060100

KYA_COPYRIGHT_TEXT = Copyright © 2014 – 2021 Marcel Dierkes. All rights reserved.
KYA_APPCAST_FEED_URL = newmarcel.github.io/KeepingYouAwake/appcast.xml
9 changes: 0 additions & 9 deletions Gymfile

This file was deleted.

Expand Up @@ -17,7 +17,8 @@ @implementation NSApplication (KYALauncher)

- (BOOL)kya_isLaunchAtLoginEnabled
{
BOOL isEnabled = [NSUserDefaults.standardUserDefaults boolForKey:KYALauncherStateUserDefaultsKey];
Auto defaults = NSUserDefaults.standardUserDefaults;
BOOL isEnabled = [defaults boolForKey:KYALauncherStateUserDefaultsKey];
Boolean success = SMLoginItemSetEnabled((__bridge CFStringRef)KYALauncherBundleIdentifier, (Boolean)isEnabled);
if(success == false)
{
Expand All @@ -37,7 +38,8 @@ - (void)setKya_launchAtLoginEnabled:(BOOL)launchAtLoginEnabled
Boolean success = SMLoginItemSetEnabled((__bridge CFStringRef)KYALauncherBundleIdentifier, (Boolean)launchAtLoginEnabled);
if(success == true)
{
[NSUserDefaults.standardUserDefaults setBool:launchAtLoginEnabled forKey:KYALauncherStateUserDefaultsKey];
Auto defaults = NSUserDefaults.standardUserDefaults;
[defaults setBool:launchAtLoginEnabled forKey:KYALauncherStateUserDefaultsKey];
}
else
{
Expand Down
18 changes: 18 additions & 0 deletions KYAKit/Extensions/NSBundle+KYAUpdateFeed.h
@@ -0,0 +1,18 @@
//
// NSBundle+KYAUpdateFeed.h
// KYAKit
//
// Created by Marcel Dierkes on 26.02.21.
// Copyright © 2021 Marcel Dierkes. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSBundle (KYAUpdateFeed)
@property (nonatomic, readonly) NSString *kya_updateFeedURLString;
@property (nonatomic, readonly) NSString *kya_preReleaseUpdateFeedURLString;
@end

NS_ASSUME_NONNULL_END
33 changes: 33 additions & 0 deletions KYAKit/Extensions/NSBundle+KYAUpdateFeed.m
@@ -0,0 +1,33 @@
//
// NSBundle+KYAUpdateFeed.m
// KYAKit
//
// Created by Marcel Dierkes on 26.02.21.
// Copyright © 2021 Marcel Dierkes. All rights reserved.
//

#import "NSBundle+KYAUpdateFeed.h"
#import "KYADefines.h"

static NSString * const KYAUpdateFeedKey = @"SUFeedURL";

@implementation NSBundle (KYAUpdateFeed)

- (NSString *)kya_updateFeedURLString
{
Auto feedURLString = (NSString *)self.infoDictionary[KYAUpdateFeedKey];
NSAssert(feedURLString != nil, @"A feed URL should be set in Info.plist");

return feedURLString;
}

- (NSString *)kya_preReleaseUpdateFeedURLString
{
Auto feedURLString = self.kya_updateFeedURLString;
Auto lastComponent = feedURLString.lastPathComponent;
Auto baseURLString = feedURLString.stringByDeletingLastPathComponent;

return [NSString stringWithFormat:@"%@/prerelease-%@", baseURLString, lastComponent];
}

@end
@@ -1,16 +1,16 @@
//
// NSApplication+Versions.h
// KeepingYouAwake
// NSBundle+KYAVersion.h
// KYAKit
//
// Created by Marcel Dierkes on 18.12.15.
// Copyright © 2015 Marcel Dierkes. All rights reserved.
// Created by Marcel Dierkes on 30.03.21.
// Copyright © 2021 Marcel Dierkes. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSApplication (Versions)
@interface NSBundle (KYAVersion)
@property (copy, nonatomic, readonly) NSString *kya_shortVersionString;
@property (copy, nonatomic, readonly) NSString *kya_buildVersionString;
@property (copy, nonatomic, readonly) NSString *kya_localizedVersionString;
Expand Down
44 changes: 44 additions & 0 deletions KYAKit/Extensions/NSBundle+KYAVersion.m
@@ -0,0 +1,44 @@
//
// NSBundle+KYAVersion.m
// KYAKit
//
// Created by Marcel Dierkes on 30.03.21.
// Copyright © 2021 Marcel Dierkes. All rights reserved.
//

#import "NSBundle+KYAVersion.h"
#import "KYADefines.h"
#import "KYAKitLocalizedStrings.h"

static NSString * const KYAShortVersionKey = @"CFBundleShortVersionString";
static NSString * const KYABundleVersionKey = @"CFBundleVersion";
static NSString * const KYACopyrightKey = @"NSHumanReadableCopyright";

@implementation NSBundle (KYAVersion)

- (NSString *)kya_shortVersionString
{
return self.infoDictionary[KYAShortVersionKey];
}

- (NSString *)kya_buildVersionString
{
return self.infoDictionary[KYABundleVersionKey];
}

- (NSString *)kya_localizedVersionString
{
return [NSString stringWithFormat:@"%@ %@ (%@)",
KYA_L10N_VERSION,
self.kya_shortVersionString,
self.kya_buildVersionString];
}

#pragma mark - Copyright String

- (NSString *)kya_localizedCopyrightString
{
return self.infoDictionary[KYACopyrightKey];
}

@end
File renamed without changes.
Expand Up @@ -27,14 +27,16 @@ - (NSDateComponentsFormatter *)dateComponentsFormatter

- (NSString *)kya_localizedRemainingTime
{
return [[self dateComponentsFormatter] stringFromDate:[NSDate date] toDate:self];
Auto startDate = [NSDate dateWithTimeIntervalSinceNow:-1];
return [[self dateComponentsFormatter] stringFromDate:startDate toDate:self];
}

- (NSString *)kya_localizedRemainingTimeWithoutPhrase
{
KYA_AUTO formatter = [self dateComponentsFormatter];
Auto formatter = [self dateComponentsFormatter];
formatter.includesTimeRemainingPhrase = NO;
KYA_AUTO remainingTimeString = [formatter stringFromDate:[NSDate date] toDate:self];
Auto startDate = [NSDate dateWithTimeIntervalSinceNow:-1];
Auto remainingTimeString = [formatter stringFromDate:startDate toDate:self];
formatter.includesTimeRemainingPhrase = YES;

return remainingTimeString;
Expand Down
Expand Up @@ -12,7 +12,6 @@ NS_ASSUME_NONNULL_BEGIN

// User Default Keys
FOUNDATION_EXPORT NSString * const KYAUserDefaultsKeyActivateOnLaunch;
FOUNDATION_EXPORT NSString * const KYAUserDefaultsKeyNotificationsEnabled;
FOUNDATION_EXPORT NSString * const KYAUserDefaultsKeyDefaultTimeInterval;
FOUNDATION_EXPORT NSString * const KYAUserDefaultsKeyAllowDisplaySleep;
FOUNDATION_EXPORT NSString * const KYAUserDefaultsKeyMenuBarIconHighlightDisabled;
Expand All @@ -28,11 +27,6 @@ FOUNDATION_EXPORT NSString * const KYAUserDefaultsKeyPreReleaseUpdatesEnabled;
*/
@property (nonatomic, getter = kya_isActivatedOnLaunch) BOOL kya_activateOnLaunch;

/**
Returns YES if user notifications should be displayed.
*/
@property (nonatomic, getter = kya_areNotificationsEnabled) BOOL kya_notificationsEnabled;

/**
Returns the default time interval for the sleep wake timer.
*/
Expand Down
Expand Up @@ -7,10 +7,10 @@
//

#import "NSUserDefaults+Keys.h"
#import "KYADefines.h"

// User Default Keys
NSString * const KYAUserDefaultsKeyActivateOnLaunch = @"info.marcel-dierkes.KeepingYouAwake.ActivateOnLaunch";
NSString * const KYAUserDefaultsKeyNotificationsEnabled = @"info.marcel-dierkes.KeepingYouAwake.NotificationsEnabled";
NSString * const KYAUserDefaultsKeyDefaultTimeInterval = @"info.marcel-dierkes.KeepingYouAwake.TimeInterval";
NSString * const KYAUserDefaultsKeyAllowDisplaySleep = @"info.marcel-dierkes.KeepingYouAwake.AllowDisplaySleep";
NSString * const KYAUserDefaultsKeyMenuBarIconHighlightDisabled = @"info.marcel-dierkes.KeepingYouAwake.MenuBarIconHighlightDisabled";
Expand All @@ -21,7 +21,7 @@
NSString * const KYAUserDefaultsKeyPreReleaseUpdatesEnabled = @"info.marcel-dierkes.KeepingYouAwake.PreReleaseUpdatesEnabled";

@implementation NSUserDefaults (Keys)
@dynamic kya_activateOnLaunch, kya_defaultTimeInterval, kya_notificationsEnabled;
@dynamic kya_activateOnLaunch, kya_defaultTimeInterval;
@dynamic kya_allowDisplaySleep;
@dynamic kya_menuBarIconHighlightDisabled;
@dynamic kya_batteryCapacityThresholdEnabled, kya_batteryCapacityThreshold;
Expand All @@ -40,18 +40,6 @@ - (void)setKya_activateOnLaunch:(BOOL)activateOnLaunch
[self setBool:activateOnLaunch forKey:KYAUserDefaultsKeyActivateOnLaunch];
}

#pragma mark - Notifications Enabled

- (BOOL)kya_areNotificationsEnabled
{
return [self boolForKey:KYAUserDefaultsKeyNotificationsEnabled];
}

- (void)setKya_notificationsEnabled:(BOOL)notificationsEnabled
{
[self setBool:notificationsEnabled forKey:KYAUserDefaultsKeyNotificationsEnabled];
}

#pragma mark - Default Time Interval

- (NSTimeInterval)kya_defaultTimeInterval
Expand Down
22 changes: 22 additions & 0 deletions KYAKit/Info.plist
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
</plist>
Expand Up @@ -8,7 +8,7 @@

#import "KYAActivationDuration.h"
#import "KYADefines.h"
#import "KYALocalizedStrings.h"
#import "KYAKitLocalizedStrings.h"
#include <chrono>

NSTimeInterval const KYAActivationDurationIndefinite = 0.0f;
Expand Down
Expand Up @@ -7,7 +7,7 @@
//

#import <Foundation/Foundation.h>
#import "KYAActivationDuration.h"
#import <KYAKit/KYAKit.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down
Expand Up @@ -8,7 +8,6 @@

#import "KYAActivationDurationsController.h"
#import "KYADefines.h"
#include "NSUserDefaults+Keys.h"

#define KYA_USES_SIMPLE_USER_DEFAULTS_VALUES 1

Expand Down
File renamed without changes.
Expand Up @@ -27,27 +27,27 @@ - (void)dealloc

- (BOOL)isBatteryStatusAvailable
{
KYA_AUTO powerSourceInfos = [self powerSourceInfos];
Auto powerSourceInfos = [self powerSourceInfos];
if(powerSourceInfos == nil)
{
return NO;
}

KYA_AUTO key = [NSString stringWithUTF8String:kIOPSTypeKey];
KYA_AUTO internalBatteryTypeKey = [NSString stringWithUTF8String:kIOPSInternalBatteryType];
Auto key = [NSString stringWithUTF8String:kIOPSTypeKey];
Auto internalBatteryTypeKey = [NSString stringWithUTF8String:kIOPSInternalBatteryType];
NSString *batteryType = powerSourceInfos[key];
return [batteryType isEqualToString:internalBatteryTypeKey];
}

- (CGFloat)currentCapacity
{
KYA_AUTO powerSourceInfos = [self powerSourceInfos];
Auto powerSourceInfos = [self powerSourceInfos];
if(powerSourceInfos == nil)
{
return KYABatteryStatusUnavailable;
}

KYA_AUTO key = [NSString stringWithUTF8String:kIOPSCurrentCapacityKey];
Auto key = [NSString stringWithUTF8String:kIOPSCurrentCapacityKey];
NSNumber *capacity = powerSourceInfos[key];
if(capacity == nil)
{
Expand All @@ -59,16 +59,16 @@ - (CGFloat)currentCapacity

- (nullable NSDictionary *)powerSourceInfos
{
KYA_AUTO blob = IOPSCopyPowerSourcesInfo();
KYA_AUTO sourcesList = IOPSCopyPowerSourcesList(blob);
Auto blob = IOPSCopyPowerSourcesInfo();
Auto sourcesList = IOPSCopyPowerSourcesList(blob);
CFRelease(blob);

if(CFArrayGetCount(sourcesList) == 0) {
CFRelease(sourcesList);
return nil;
}

KYA_AUTO powerSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sourcesList, 0));
Auto powerSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sourcesList, 0));
CFRetain(powerSource);
CFRelease(sourcesList);

Expand All @@ -85,7 +85,7 @@ - (void)registerForCapacityChangesIfNeeded
return;
}

KYA_AUTO runLoopSource = IOPSNotificationCreateRunLoopSource(KYABatteryStatusChangeHandler, (__bridge void *)self);
Auto runLoopSource = IOPSNotificationCreateRunLoopSource(KYABatteryStatusChangeHandler, (__bridge void *)self);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);

self.runLoopSource = runLoopSource;
Expand All @@ -109,7 +109,7 @@ - (void)unregisterFromCapacityChanges

static void KYABatteryStatusChangeHandler(void *context)
{
KYA_AUTO batteryStatus = (__bridge KYABatteryStatus *)context;
Auto batteryStatus = (__bridge KYABatteryStatus *)context;
if(batteryStatus.capacityChangeHandler)
{
batteryStatus.capacityChangeHandler(batteryStatus.currentCapacity);
Expand Down
Expand Up @@ -33,7 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return A new instance.
*/
- (instancetype)initWithName:(NSString *)name arguments:(nullable NSDictionary<NSString *, id> *)arguments;
- (instancetype)initWithName:(NSString *)name
arguments:(nullable NSDictionary<NSString *, id> *)arguments;

- (BOOL)isEqualToEvent:(nullable KYAEvent *)event;

Expand Down

0 comments on commit ab63a1f

Please sign in to comment.