code cleanup

This commit is contained in:
Michael Starke
2018-09-06 09:10:43 +02:00
parent f13cd4df35
commit 5589f5086b
4 changed files with 31 additions and 33 deletions

View File

@@ -798,7 +798,7 @@
<rect key="frame" x="1" y="1" width="259" height="268"/> <rect key="frame" x="1" y="1" width="259" height="268"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="54" rowSizeStyle="automatic" viewBased="YES" id="193"> <tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="54" viewBased="YES" id="193">
<rect key="frame" x="0.0" y="0.0" width="259" height="268"/> <rect key="frame" x="0.0" y="0.0" width="259" height="268"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/> <size key="intercellSpacing" width="3" height="2"/>
@@ -903,7 +903,7 @@
<connections> <connections>
<outlet property="nextKeyView" destination="G9J-nn-2bu" id="CZ9-f2-JDQ"/> <outlet property="nextKeyView" destination="G9J-nn-2bu" id="CZ9-f2-JDQ"/>
</connections> </connections>
<point key="canvasLocation" x="-1015" y="-1275"/> <point key="canvasLocation" x="-1317" y="-1440"/>
</scrollView> </scrollView>
</objects> </objects>
<resources> <resources>

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>
@@ -45,11 +45,11 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews> <prototypeCellViews>
<tableCellView identifier="StringCell" id="269"> <tableCellView identifier="StringCell" id="269">
<rect key="frame" x="1" y="1" width="104" height="17"/> <rect key="frame" x="1" y="1" width="105" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="270"> <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="270">
<rect key="frame" x="1" y="0.0" width="102" height="17"/> <rect key="frame" x="1" y="0.0" width="103" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="271"> <textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="271">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -131,11 +131,11 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews> <prototypeCellViews>
<tableCellView identifier="PasswordCell" id="428"> <tableCellView identifier="PasswordCell" id="428">
<rect key="frame" x="256" y="1" width="118" height="17"/> <rect key="frame" x="256" y="1" width="119" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="429" customClass="NSSecureTextField"> <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="429" customClass="NSSecureTextField">
<rect key="frame" x="1" y="0.0" width="116" height="17"/> <rect key="frame" x="1" y="0.0" width="117" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="430"> <textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="430">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -191,7 +191,7 @@
</tableCellView> </tableCellView>
</prototypeCellViews> </prototypeCellViews>
</tableColumn> </tableColumn>
<tableColumn width="199" minWidth="10" maxWidth="3.4028234663852886e+38" id="614"> <tableColumn identifier="" width="199" minWidth="10" maxWidth="3.4028234663852886e+38" id="614">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left"> <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>

View File

@@ -568,7 +568,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
- (void)setSelectedNodes:(NSArray<KPKNode *> *)selectedNodes { - (void)setSelectedNodes:(NSArray<KPKNode *> *)selectedNodes {
if(![_selectedNodes isEqualToArray:selectedNodes]) { if(![_selectedNodes isEqualToArray:selectedNodes]) {
_selectedNodes = [selectedNodes copy]; _selectedNodes = [selectedNodes copy];
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentCurrentItemChangedNotification object:self]; [NSNotificationCenter.defaultCenter postNotificationName:MPDocumentCurrentItemChangedNotification object:self];
} }
} }
@@ -773,7 +773,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
return; // sender cannot provide useful data return; // sender cannot provide useful data
} }
id obj = [sender representedObject]; id obj = [sender representedObject];
if(![obj isKindOfClass:[NSUUID class]]) { if(![obj isKindOfClass:NSUUID.class]) {
return; // sender cannot provide NSUUID return; // sender cannot provide NSUUID
} }
NSUUID *entryUUID = [sender representedObject]; NSUUID *entryUUID = [sender representedObject];
@@ -783,7 +783,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
if(templateEntry && group) { if(templateEntry && group) {
KPKEntry *copy = [templateEntry copyWithTitle:templateEntry.title options:kKPKCopyOptionNone]; KPKEntry *copy = [templateEntry copyWithTitle:templateEntry.title options:kKPKCopyOptionNone];
BOOL updatePassword = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyUpdatePasswordOnTemplateEntries]; BOOL updatePassword = [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyUpdatePasswordOnTemplateEntries];
if( updatePassword ) { if( updatePassword ) {
BOOL undoEnabled = self.undoManager.isUndoRegistrationEnabled; BOOL undoEnabled = self.undoManager.isUndoRegistrationEnabled;
[self.undoManager disableUndoRegistration]; [self.undoManager disableUndoRegistration];
@@ -915,7 +915,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
keysForFiles[self.fileURL.path.sha1HexDigest] = keyURL.path; keysForFiles[self.fileURL.path.sha1HexDigest] = keyURL.path;
} }
if(keysForFiles) { if(keysForFiles) {
[[NSUserDefaults standardUserDefaults] setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases]; [NSUserDefaults.standardUserDefaults setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases];
} }
} }

View File

@@ -29,7 +29,7 @@
@property (nonatomic,assign) BOOL lockOnSleep; @property (nonatomic,assign) BOOL lockOnSleep;
@property (nonatomic,assign) BOOL lockOnLogout; @property (nonatomic,assign) BOOL lockOnLogout;
@property (nonatomic,assign) NSUInteger idleLockTime; @property (nonatomic,assign) NSUInteger idleLockTime;
@property (nonatomic,strong) id eventHandler; @property (nonatomic,strong) id localEventHandler;
@property (nonatomic,strong) NSTimer *idleCheckTimer; @property (nonatomic,strong) NSTimer *idleCheckTimer;
@property (assign) NSTimeInterval lastLocalEventTime; @property (assign) NSTimeInterval lastLocalEventTime;
@@ -55,7 +55,7 @@ static MPLockDaemon *_sharedInstance;
NSAssert(_sharedInstance == nil, @"Multiple instances of MPLockDaemon not allowed!"); NSAssert(_sharedInstance == nil, @"Multiple instances of MPLockDaemon not allowed!");
self = [super init]; self = [super init];
if (self) { if (self) {
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; NSUserDefaultsController *defaultsController = NSUserDefaultsController.sharedUserDefaultsController;
[self bind:NSStringFromSelector(@selector(lockOnSleep)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyLockOnSleep] options:nil]; [self bind:NSStringFromSelector(@selector(lockOnSleep)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyLockOnSleep] options:nil];
[self bind:NSStringFromSelector(@selector(idleLockTime)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyIdleLockTimeOut] options:nil]; [self bind:NSStringFromSelector(@selector(idleLockTime)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyIdleLockTimeOut] options:nil];
[self bind:NSStringFromSelector(@selector(lockOnLogout)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingskeyLockOnLogout] options:nil]; [self bind:NSStringFromSelector(@selector(lockOnLogout)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingskeyLockOnLogout] options:nil];
@@ -65,10 +65,10 @@ static MPLockDaemon *_sharedInstance;
- (void)dealloc { - (void)dealloc {
/* Notifications */ /* Notifications */
[[NSWorkspace sharedWorkspace].notificationCenter removeObserver:self]; [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self];
/* Timer */ /* Timer */
[NSEvent removeMonitor:self.eventHandler]; [NSEvent removeMonitor:self.localEventHandler];
} }
- (void)setLockOnLogout:(BOOL)lockOnLogout { - (void)setLockOnLogout:(BOOL)lockOnLogout {
@@ -87,10 +87,10 @@ static MPLockDaemon *_sharedInstance;
if(_lockOnSleep != lockOnSleep) { if(_lockOnSleep != lockOnSleep) {
_lockOnSleep = lockOnSleep; _lockOnSleep = lockOnSleep;
if(_lockOnSleep) { if(_lockOnSleep) {
[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(_willSleepNotification:) name:NSWorkspaceWillSleepNotification object:nil]; [NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_willSleepNotification:) name:NSWorkspaceWillSleepNotification object:nil];
} }
else { else {
[[NSWorkspace sharedWorkspace].notificationCenter removeObserver:self name:NSWorkspaceWillSleepNotification object:nil]; [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceWillSleepNotification object:nil];
} }
} }
} }
@@ -118,22 +118,22 @@ static MPLockDaemon *_sharedInstance;
if(timer != self.idleCheckTimer) { if(timer != self.idleCheckTimer) {
return; // Wrong timer?! return; // Wrong timer?!
} }
NSTimeInterval currentInterval = ([NSDate timeIntervalSinceReferenceDate] - self.lastLocalEventTime); NSTimeInterval currentInterval = (NSDate.timeIntervalSinceReferenceDate - self.lastLocalEventTime);
if(self.idleLockTime < currentInterval) { if(self.idleLockTime < currentInterval) {
[((MPAppDelegate *)NSApp.delegate) lockAllDocuments]; [((MPAppDelegate *)NSApp.delegate) lockAllDocuments];
/* Reset the timer to full interval */ /* Reset the timer to full interval */
[self.idleCheckTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:_idleLockTime]]; self.idleCheckTimer.fireDate = [NSDate dateWithTimeIntervalSinceNow:_idleLockTime];
} }
else { else {
[self.idleCheckTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:(_idleLockTime - currentInterval)]]; self.idleCheckTimer.fireDate = [NSDate dateWithTimeIntervalSinceNow:(_idleLockTime - currentInterval)];
} }
} }
- (void)_stopIdleChecking { - (void)_stopIdleChecking {
[self.idleCheckTimer invalidate]; [self.idleCheckTimer invalidate];
self.idleCheckTimer = nil; self.idleCheckTimer = nil;
[NSEvent removeMonitor:self.eventHandler]; [NSEvent removeMonitor:self.localEventHandler];
self.eventHandler = nil; self.localEventHandler = nil;
} }
- (void)_updateOrStartIdleChecking { - (void)_updateOrStartIdleChecking {
@@ -144,17 +144,15 @@ static MPLockDaemon *_sharedInstance;
} }
else { else {
self.idleCheckTimer = [NSTimer timerWithTimeInterval:self.idleLockTime target:self selector:@selector(_checkIdleTime:) userInfo:nil repeats:YES]; self.idleCheckTimer = [NSTimer timerWithTimeInterval:self.idleLockTime target:self selector:@selector(_checkIdleTime:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.idleCheckTimer forMode:NSDefaultRunLoopMode]; [NSRunLoop.mainRunLoop addTimer:self.idleCheckTimer forMode:NSDefaultRunLoopMode];
} }
/* Create event handler if necessary */ /* Create event handler if necessary */
if(self.eventHandler) { if(!self.localEventHandler) {
return; self.localEventHandler = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask handler:^NSEvent *(NSEvent *theEvent) {
self.lastLocalEventTime = NSDate.timeIntervalSinceReferenceDate;
return theEvent;
}];
} }
MPLockDaemon __weak *welf = self;
self.eventHandler = [NSEvent addLocalMonitorForEventsMatchingMask:NSAnyEventMask handler:^NSEvent *(NSEvent *theEvent) {
welf.lastLocalEventTime = [NSDate timeIntervalSinceReferenceDate];
return theEvent;
}];
} }
@end @end