From 840559630c72228aa7e4fd689bcfccd224aeaaef Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 24 Feb 2016 14:20:45 +0100 Subject: [PATCH 1/3] using non deprecated NSCalendar and NSDate API --- MacPass/MPDatePickingViewController.m | 28 +++++++++++++-------------- MacPass/NSDate+Humanized.m | 19 +++++++++--------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/MacPass/MPDatePickingViewController.m b/MacPass/MPDatePickingViewController.m index 504e46d7..a33c9dcd 100644 --- a/MacPass/MPDatePickingViewController.m +++ b/MacPass/MPDatePickingViewController.m @@ -39,23 +39,23 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) { NSArray *dateItems = @[ NSLocalizedString(@"TOMORROW", ""), NSLocalizedString(@"ONE_WEEK", ""), NSLocalizedString(@"ONE_MONTH", ""), NSLocalizedString(@"90_DAYS", ""), NSLocalizedString(@"ONE_YEAR", "") ]; NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SELECT_DATE_PRESET", "") action:NULL keyEquivalent:@""]; - [item setTag:MPDatePresetNone]; + item.tag = MPDatePresetNone; [presetMenu addItem:item]; [presetMenu addItem:[NSMenuItem separatorItem]]; for(NSInteger iIndex = 0; iIndex < sizeof(tags)/sizeof(NSUInteger); iIndex++) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:dateItems[iIndex] action:NULL keyEquivalent:@""]; - [item setTag:tags[iIndex]]; + item.tag = tags[iIndex]; [presetMenu addItem:item]; } - [self.datePicker setDateValue:[NSDate date]]; - [self.presetPopupButton setMenu:presetMenu]; + self.datePicker.dateValue = [NSDate date]; + self.presetPopupButton.menu = presetMenu; } - (IBAction)useDate:(id)sender { self.didCancel = NO; - self.date = [self.datePicker dateValue]; + self.date = self.datePicker.dateValue; [self.popover performClose:self]; } @@ -65,32 +65,32 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) { } - (IBAction)setDatePreset:(id)sender { - NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSDateComponents *offsetComponents = [[NSDateComponents alloc] init]; - - MPDatePreset preset = [[sender selectedItem] tag]; + + MPDatePreset preset = ((NSPopUpButton *)sender).selectedTag; switch(preset) { case MPDatePresetTomorrow: - [offsetComponents setDay:1]; + offsetComponents.day = 1; break; case MPDatePresetOneWeek: - [offsetComponents setWeek:1]; + offsetComponents.weekOfMonth = 1; break; case MPDatePresetOneMonth: - [offsetComponents setMonth:1]; + offsetComponents.month = 1; break; case MPDatePreset90Days: - [offsetComponents setDay:90]; + offsetComponents.day = 90; break; case MPDatePresetOneYear: - [offsetComponents setYear:1]; + offsetComponents.year = 1; break; case MPDatePresetNone: default: return; // Nothing to do; } NSDate *newDate = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0]; - [self.datePicker setDateValue:newDate]; + self.datePicker.dateValue = newDate; } @end diff --git a/MacPass/NSDate+Humanized.m b/MacPass/NSDate+Humanized.m index 7f3db0fa..1c2fb362 100644 --- a/MacPass/NSDate+Humanized.m +++ b/MacPass/NSDate+Humanized.m @@ -15,15 +15,15 @@ } - (NSString *)humanized { - NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; - NSDateComponents *components = [calendar components:NSMinuteCalendarUnit|NSHourCalendarUnit|NSDayCalendarUnit|NSWeekCalendarUnit|NSMonthCalendarUnit fromDate:self toDate:[NSDate date] options:0]; + NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; + NSDateComponents *components = [calendar components:NSCalendarUnitMinute|NSCalendarUnitHour|NSCalendarUnitDay|NSCalendarUnitWeekOfMonth|NSCalendarUnitMonth fromDate:self toDate:[NSDate date] options:0]; /* More than one month in the past, give full date */ - if([components month] > 1) { + if(components.month > 1) { return [NSDateFormatter localizedStringFromDate:self dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]; } - NSUInteger weeks = [components week]; + NSUInteger weeks = components.weekOfMonth; /* More than one week, less than a month */ if(weeks > 1) { NSString *weekTemplate = NSLocalizedString(@"%ld_WEEKS_AGO", "% Weeks ago"); @@ -34,7 +34,7 @@ return NSLocalizedString(@"ONE_WEEK_AGO", "one week ago"); } /* Last week */ - NSUInteger days = [components day]; + NSUInteger days = components.day; if(days > 3) { return NSLocalizedString(@"LAST_WEEK", "last week"); } @@ -48,14 +48,13 @@ return NSLocalizedString(@"YESTERDAY", "Yesterday"); } /* Hours ago */ - if([components hour] > 1) { + if(components.hour > 1) { NSString *hourTemplate = NSLocalizedString(@"%ld_HOURS_AGO", "% Hours ago"); - return [NSString stringWithFormat:hourTemplate, [components hour]]; + return [NSString stringWithFormat:hourTemplate, components.hour]; } - NSInteger minutes = [components minute]; - if(minutes > 1) { + if(components.minute > 1) { NSString *minuteTemplate = NSLocalizedString(@"%ld_MINUTES_AGO", "% Minutes ago"); - return [NSString stringWithFormat:minuteTemplate, minutes]; + return [NSString stringWithFormat:minuteTemplate, components.minute]; } return NSLocalizedString(@"JUST_NOW", "Just now"); } From dc57628c81cc26fbee763a50d2b1b69add4db3d4 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 24 Feb 2016 15:17:37 +0100 Subject: [PATCH 2/3] SUUpdater now only gets created in release --- MacPass/Base.lproj/MainMenu.xib | 8 ++------ MacPass/Base.lproj/UpdateSettings.xib | 15 +++++---------- MacPass/MPAppDelegate.m | 6 ++++++ MacPass/MPUpdateSettingsController.m | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/MacPass/Base.lproj/MainMenu.xib b/MacPass/Base.lproj/MainMenu.xib index 1905c94f..05fa5a7a 100644 --- a/MacPass/Base.lproj/MainMenu.xib +++ b/MacPass/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -25,9 +25,6 @@ - - - @@ -320,6 +317,5 @@ - diff --git a/MacPass/Base.lproj/UpdateSettings.xib b/MacPass/Base.lproj/UpdateSettings.xib index 4446ce71..a77c535a 100644 --- a/MacPass/Base.lproj/UpdateSettings.xib +++ b/MacPass/Base.lproj/UpdateSettings.xib @@ -1,12 +1,14 @@ - + - + + + @@ -24,9 +26,6 @@ - - - @@ -44,10 +43,6 @@ - - - - @@ -69,7 +64,7 @@ + - diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index f0f6bc40..4567058a 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -38,6 +38,8 @@ #import "KeePassKit/KeePassKit.h" +#import + NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDidChangeStoredKeyFilesSettings"; @interface MPAppDelegate () { @@ -158,6 +160,10 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi [MPAutotypeDaemon defaultDaemon]; /* Create Plugin Manager */ [MPPluginManager sharedManager]; +#ifdef RELEASE + /* Only enabel updater in Release */ + [SUUpdater sharedUpdater]; +#endif } #pragma mark - diff --git a/MacPass/MPUpdateSettingsController.m b/MacPass/MPUpdateSettingsController.m index ac27aa36..f8bbf311 100644 --- a/MacPass/MPUpdateSettingsController.m +++ b/MacPass/MPUpdateSettingsController.m @@ -7,8 +7,11 @@ // #import "MPUpdateSettingsController.h" +#import @interface MPUpdateSettingsController () +@property (weak) IBOutlet NSButton *automaticallyCheckForUpdatesCheckButton; +@property (weak) IBOutlet NSPopUpButton *checkIntervallPopupButton; @end @@ -30,4 +33,16 @@ return NSLocalizedString(@"UPDATE_SETTINGS", @"Update Settings Label"); } +- (void)awakeFromNib { +#ifdef RELEASE + [self.checkIntervallPopupButton bind:NSSelectedTagBinding toObject:[SUUpdater sharedUpdater] withKeyPath:NSStringFromSelector(@selector(updateCheckInterval)) options:nil]; + [self.checkIntervallPopupButton bind:NSEnabledBinding toObject:[SUUpdater sharedUpdater] withKeyPath:NSStringFromSelector(@selector(automaticallyChecksForUpdates)) options:nil]; + [self.automaticallyCheckForUpdatesCheckButton bind:NSValueBinding toObject:[SUUpdater sharedUpdater] withKeyPath:NSStringFromSelector(@selector(automaticallyChecksForUpdates)) options:nil]; +#else + self.checkIntervallPopupButton.enabled = NO; + self.automaticallyCheckForUpdatesCheckButton.enabled = NO; +#endif + +} + @end From 2af98ef3d6f409657fbabdec1e56e5c7cffff520 Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 17 Mar 2016 17:37:40 +0100 Subject: [PATCH 3/3] Displaying dialog when Sparkle is disabled --- MacPass/Base.lproj/MainMenu.xib | 3 +++ MacPass/MPAppDelegate.h | 1 + MacPass/MPAppDelegate.m | 18 +++++++++++++++--- MacPass/MPUpdateSettingsController.m | 9 +++++---- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/MacPass/Base.lproj/MainMenu.xib b/MacPass/Base.lproj/MainMenu.xib index 05fa5a7a..b78d3df5 100644 --- a/MacPass/Base.lproj/MainMenu.xib +++ b/MacPass/Base.lproj/MainMenu.xib @@ -25,6 +25,9 @@ + + + diff --git a/MacPass/MPAppDelegate.h b/MacPass/MPAppDelegate.h index 53e3c108..800e84f3 100644 --- a/MacPass/MPAppDelegate.h +++ b/MacPass/MPAppDelegate.h @@ -34,6 +34,7 @@ APPKIT_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings; @property (nonatomic, assign) BOOL isAllowedToStoreKeyFile; +- (IBAction)checkForUpdates:(id)sender; - (IBAction)showPreferences:(id)sender; - (IBAction)showPasswordCreator:(id)sender; - (IBAction)createNewDatabase:(id)sender; diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index 4567058a..39a9a071 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -36,6 +36,8 @@ #import "MPTemporaryFileStorageCenter.h" #import "MPValueTransformerHelper.h" +#import "NSApplication+MPAdditions.h" + #import "KeePassKit/KeePassKit.h" #import @@ -95,7 +97,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi - (void)awakeFromNib { _isAllowedToStoreKeyFile = NO; /* Update the … at the save menu */ - [[self.saveMenuItem menu] setDelegate:self]; + self.saveMenuItem.menu.delegate = self; /* We want to inform anyone about the changes to keyFile remembering */ [self bind:NSStringFromSelector(@selector(isAllowedToStoreKeyFile)) @@ -160,8 +162,8 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi [MPAutotypeDaemon defaultDaemon]; /* Create Plugin Manager */ [MPPluginManager sharedManager]; -#ifdef RELEASE - /* Only enabel updater in Release */ +#ifndef DEBUG + /* Only enable updater in Release */ [SUUpdater sharedUpdater]; #endif } @@ -227,9 +229,19 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi } - (void)showHelp:(id)sender { + /* TODO: use Info.plist for URL */ [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://github.com/mstarke/MacPass"]]; } +- (void)checkForUpdates:(id)sender { +#ifdef DEBUG + NSAlert *alert = [NSAlert alertWithMessageText:@"Updates are disabled!" defaultButton:@"Ok" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Sparkle updates are only available in offical releases of %@!", NSApp.applicationName]; + [alert runModal]; +#else + [[SUUpdater sharedUpdater] checkForUpdates:sender]; +#endif +} + #pragma mark - #pragma mark Private Helper - (void)_applicationDidFinishRestoringWindows:(NSNotification *)notification { diff --git a/MacPass/MPUpdateSettingsController.m b/MacPass/MPUpdateSettingsController.m index f8bbf311..754ff71a 100644 --- a/MacPass/MPUpdateSettingsController.m +++ b/MacPass/MPUpdateSettingsController.m @@ -34,13 +34,14 @@ } - (void)awakeFromNib { -#ifdef RELEASE +/* only enable bindings to settings in release mode */ +#ifdef DEBUG + self.checkIntervallPopupButton.enabled = NO; + self.automaticallyCheckForUpdatesCheckButton.enabled = NO; +#else [self.checkIntervallPopupButton bind:NSSelectedTagBinding toObject:[SUUpdater sharedUpdater] withKeyPath:NSStringFromSelector(@selector(updateCheckInterval)) options:nil]; [self.checkIntervallPopupButton bind:NSEnabledBinding toObject:[SUUpdater sharedUpdater] withKeyPath:NSStringFromSelector(@selector(automaticallyChecksForUpdates)) options:nil]; [self.automaticallyCheckForUpdatesCheckButton bind:NSValueBinding toObject:[SUUpdater sharedUpdater] withKeyPath:NSStringFromSelector(@selector(automaticallyChecksForUpdates)) options:nil]; -#else - self.checkIntervallPopupButton.enabled = NO; - self.automaticallyCheckForUpdatesCheckButton.enabled = NO; #endif }