Add Lock database on Screen Sleep (#998)

* added lock databse on Screen sleep

* remove unneeded change

* fix unregister screen sleep method

* fixed constraints and checkbox label
This commit is contained in:
georgesnow
2019-12-17 07:59:01 -05:00
committed by Michael Starke
parent b1568c5eef
commit 9ba902471c
6 changed files with 56 additions and 22 deletions

View File

@@ -14,6 +14,7 @@
<outlet property="fileChangeStrategyPopup" destination="wIu-Sh-2a2" id="oJo-dA-lEE"/>
<outlet property="idleTimeOutPopup" destination="584" id="809"/>
<outlet property="lockOnLogoutCheckButton" destination="5SP-Vi-1sn" id="yaI-LH-R5A"/>
<outlet property="lockOnScreenSleep" destination="nRe-7S-HwK" id="pl4-Aw-PVa"/>
<outlet property="lockOnSleepCheckButton" destination="630" id="810"/>
<outlet property="preventUniversalClipboardSupportCheckButton" destination="nqZ-rB-mFS" id="sbx-rl-reT"/>
<outlet property="rememberKeyFileCheckButton" destination="bSt-Wf-FNZ" id="aQm-EA-yAN"/>
@@ -24,16 +25,16 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="1">
<rect key="frame" x="0.0" y="0.0" width="411" height="524"/>
<rect key="frame" x="0.0" y="0.0" width="411" height="548"/>
<subviews>
<box autoresizesSubviews="NO" verticalHuggingPriority="500" borderType="line" title="Security" translatesAutoresizingMaskIntoConstraints="NO" id="465">
<rect key="frame" x="17" y="16" width="377" height="357"/>
<rect key="frame" x="17" y="16" width="377" height="381"/>
<view key="contentView" id="mNh-3L-Z6E">
<rect key="frame" x="3" y="3" width="371" height="339"/>
<rect key="frame" x="3" y="3" width="371" height="363"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="431">
<rect key="frame" x="14" y="311" width="120" height="17"/>
<rect key="frame" x="14" y="335" width="120" height="17"/>
<constraints>
<constraint firstAttribute="height" constant="17" id="803"/>
</constraints>
@@ -44,10 +45,10 @@
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="419">
<rect key="frame" x="138" y="308" width="143" height="21"/>
<rect key="frame" x="138" y="332" width="143" height="21"/>
<popUpButtonCell key="cell" type="push" title="Never" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="429" id="420">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="system"/>
<menu key="menu" title="ClipboardClearInterval" id="421">
<items>
<menuItem title="Never" state="on" id="429">
@@ -62,7 +63,7 @@
</popUpButtonCell>
</popUpButton>
<button verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="447">
<rect key="frame" x="29" y="287" width="164" height="18"/>
<rect key="frame" x="29" y="311" width="164" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="14" id="773"/>
</constraints>
@@ -72,10 +73,10 @@
</buttonCell>
</button>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="584">
<rect key="frame" x="111" y="168" width="125" height="25"/>
<rect key="frame" x="111" y="192" width="125" height="25"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="585">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="system"/>
<menu key="menu" title="LockTimes" id="586">
<items>
<menuItem title="Never" id="804"/>
@@ -89,14 +90,14 @@
</popUpButtonCell>
</popUpButton>
<button translatesAutoresizingMaskIntoConstraints="NO" id="630">
<rect key="frame" x="29" y="149" width="119" height="18"/>
<rect key="frame" x="29" y="173" width="119" height="18"/>
<buttonCell key="cell" type="check" title="Lock after sleep" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="631">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="805">
<rect key="frame" x="14" y="173" width="93" height="17"/>
<rect key="frame" x="14" y="197" width="93" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Lock while idle" id="806">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -113,7 +114,7 @@
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5cV-xX-SUU">
<rect key="frame" x="18" y="41" width="335" height="56"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" id="ACh-7H-42N">
<font key="font" metaFont="smallSystem"/>
<font key="font" metaFont="message" size="11"/>
<string key="title">Enabling this compromises security. If enabled, your preferences will contain mappings from database to keyfile. Key locations for databases without a password will not be saved.</string>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@@ -130,42 +131,53 @@
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="5SP-Vi-1sn">
<rect key="frame" x="29" y="129" width="129" height="18"/>
<rect key="frame" x="29" y="151" width="129" height="18"/>
<buttonCell key="cell" type="check" title="Lock after log out" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Dzn-9R-JjE">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="nqZ-rB-mFS">
<rect key="frame" x="14" y="262" width="242" height="18"/>
<rect key="frame" x="14" y="286" width="242" height="18"/>
<buttonCell key="cell" type="check" title="Prevent Universal Clipboard support" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="fNy-mS-phi">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hy4-RL-dAa">
<rect key="frame" x="18" y="200" width="335" height="56"/>
<rect key="frame" x="18" y="224" width="335" height="56"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" id="JGX-Tp-KJk">
<font key="font" metaFont="smallSystem"/>
<font key="font" metaFont="message" size="11"/>
<string key="title">Disabling this compromises security. If enabled, anything copied to the Clipboard in MacPass will be available on your connected iOS devices. You should clear the clipboard on those devices manually.</string>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="nRe-7S-HwK">
<rect key="frame" x="29" y="129" width="164" height="18"/>
<buttonCell key="cell" type="check" title="Lock after screen sleep" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="l3t-og-mJd">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstItem="5cV-xX-SUU" firstAttribute="leading" secondItem="mNh-3L-Z6E" secondAttribute="leading" constant="20" symbolic="YES" id="1jw-nb-bAB"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="630" secondAttribute="trailing" constant="20" symbolic="YES" id="7cd-1e-eRD"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="nqZ-rB-mFS" secondAttribute="trailing" constant="20" symbolic="YES" id="CL9-fA-GTJ"/>
<constraint firstItem="bSt-Wf-FNZ" firstAttribute="top" secondItem="nRe-7S-HwK" secondAttribute="bottom" constant="11" id="MkJ-O0-qYd"/>
<constraint firstItem="nRe-7S-HwK" firstAttribute="leading" secondItem="447" secondAttribute="leading" id="Mrg-k2-soG"/>
<constraint firstItem="584" firstAttribute="top" secondItem="hy4-RL-dAa" secondAttribute="bottom" constant="8" symbolic="YES" id="SV7-PD-nId"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="bSt-Wf-FNZ" secondAttribute="trailing" constant="20" symbolic="YES" id="VQY-eq-fCM"/>
<constraint firstItem="bSt-Wf-FNZ" firstAttribute="top" secondItem="5SP-Vi-1sn" secondAttribute="bottom" constant="11" id="WUG-Uf-FCO"/>
<constraint firstItem="bSt-Wf-FNZ" firstAttribute="top" secondItem="nRe-7S-HwK" secondAttribute="bottom" constant="-25" id="WUG-Uf-FCO"/>
<constraint firstItem="nRe-7S-HwK" firstAttribute="top" secondItem="5SP-Vi-1sn" secondAttribute="bottom" constant="8" id="YZv-Dp-CrZ"/>
<constraint firstItem="5SP-Vi-1sn" firstAttribute="leading" secondItem="447" secondAttribute="leading" id="Ylr-aA-jaD"/>
<constraint firstItem="hy4-RL-dAa" firstAttribute="top" secondItem="nqZ-rB-mFS" secondAttribute="bottom" constant="8" symbolic="YES" id="a3i-tc-gUU"/>
<constraint firstItem="5SP-Vi-1sn" firstAttribute="top" secondItem="630" secondAttribute="bottom" constant="6" symbolic="YES" id="acg-vp-LeB"/>
<constraint firstItem="5SP-Vi-1sn" firstAttribute="top" secondItem="630" secondAttribute="bottom" constant="8" id="acg-vp-LeB"/>
<constraint firstItem="584" firstAttribute="leading" secondItem="805" secondAttribute="trailing" constant="8" symbolic="YES" id="aoz-sS-O0n"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="447" secondAttribute="trailing" constant="20" symbolic="YES" id="i8H-ad-IKb"/>
<constraint firstItem="419" firstAttribute="leading" secondItem="431" secondAttribute="trailing" constant="8" symbolic="YES" id="pN3-pB-Z5I"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="nRe-7S-HwK" secondAttribute="trailing" constant="20" symbolic="YES" id="pgB-km-W16"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="5SP-Vi-1sn" secondAttribute="trailing" constant="20" symbolic="YES" id="q0v-Wo-mHx"/>
<constraint firstItem="nqZ-rB-mFS" firstAttribute="top" secondItem="447" secondAttribute="bottom" constant="11" id="qLm-ih-A04"/>
<constraint firstAttribute="trailing" secondItem="5cV-xX-SUU" secondAttribute="trailing" constant="20" symbolic="YES" id="qY0-io-RZ0"/>
@@ -197,7 +209,7 @@
</constraints>
</box>
<box autoresizesSubviews="NO" verticalHuggingPriority="500" borderType="line" title="File Handling" translatesAutoresizingMaskIntoConstraints="NO" id="888">
<rect key="frame" x="17" y="375" width="377" height="129"/>
<rect key="frame" x="17" y="399" width="377" height="129"/>
<view key="contentView" id="cpg-tt-SHE">
<rect key="frame" x="3" y="3" width="371" height="111"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -219,7 +231,7 @@
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3Bo-Ml-1KB">
<rect key="frame" x="18" y="45" width="335" height="14"/>
<textFieldCell key="cell" controlSize="small" title="Close and open all documents for changes to take effect" id="ya5-ps-c4W">
<font key="font" metaFont="smallSystem"/>
<font key="font" metaFont="message" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
@@ -236,7 +248,7 @@
<rect key="frame" x="111" y="14" width="38" height="25"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="1R2-5t-LWk">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="DQY-17-yKP"/>
</popUpButtonCell>
</popUpButton>
@@ -273,7 +285,7 @@
<constraint firstAttribute="bottom" secondItem="465" secondAttribute="bottom" constant="20" symbolic="YES" id="uwq-az-XwJ"/>
<constraint firstItem="465" firstAttribute="top" secondItem="cpg-tt-SHE" secondAttribute="bottom" constant="5" id="wyH-HB-i2U"/>
</constraints>
<point key="canvasLocation" x="-136.5" y="-93"/>
<point key="canvasLocation" x="-136.5" y="-93.5"/>
</customView>
</objects>
</document>

View File

@@ -32,6 +32,7 @@
@property (strong) IBOutlet NSPopUpButton *idleTimeOutPopup;
@property (strong) IBOutlet NSButton *lockOnSleepCheckButton;
@property (strong) IBOutlet NSButton *lockOnLogoutCheckButton;
@property (weak) IBOutlet NSButton *lockOnScreenSleepCheckButton;
@property (strong) IBOutlet NSButton *reopenLastDatabase;
@property (strong) IBOutlet NSButton *enableAutosaveCheckButton;
@property (strong) IBOutlet NSButton *rememberKeyFileCheckButton;

View File

@@ -50,6 +50,7 @@
[self.preventUniversalClipboardSupportCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPreventUniversalClipboard] options:nil];
[self.lockOnSleepCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyLockOnSleep] options:nil];
[self.lockOnLogoutCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingskeyLockOnLogout] options:nil];
[self.lockOnScreenSleepCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingskeyLockOnScreenSleep] options:nil];
[self.idleTimeOutPopup bind:NSSelectedTagBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyIdleLockTimeOut] options:nil];
[self.reopenLastDatabase bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch] options:nil];
[self.enableAutosaveCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableAutosave] options:nil];

View File

@@ -28,6 +28,7 @@
@property (nonatomic,assign) BOOL lockOnSleep;
@property (nonatomic,assign) BOOL lockOnLogout;
@property (nonatomic,assign) BOOL lockOnScreenSleep;
@property (nonatomic,assign) NSUInteger idleLockTime;
@property (nonatomic,strong) id localEventHandler;
@property (nonatomic,strong) NSTimer *idleCheckTimer;
@@ -59,6 +60,7 @@ static MPLockDaemon *_sharedInstance;
[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(lockOnLogout)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingskeyLockOnLogout] options:nil];
[self bind:NSStringFromSelector(@selector(lockOnScreenSleep)) toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingskeyLockOnScreenSleep] options:nil];
}
return self;
}
@@ -95,6 +97,18 @@ static MPLockDaemon *_sharedInstance;
}
}
- (void)setLockOnScreenSleep:(BOOL)lockOnScreenSleep {
if(_lockOnScreenSleep != lockOnScreenSleep) {
_lockOnScreenSleep = lockOnScreenSleep;
if(_lockOnScreenSleep) {
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(_willScreenSleepNotification:) name:NSWorkspaceScreensDidSleepNotification object:nil];
}
else {
[NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceScreensDidSleepNotification object:nil];
}
}
}
- (void)setIdleLockTime:(NSUInteger)idleLockTime {
if(_idleLockTime != idleLockTime) {
_idleLockTime = idleLockTime;
@@ -113,6 +127,9 @@ static MPLockDaemon *_sharedInstance;
- (void)_willSleepNotification:(NSNotification *)notification {
[((MPAppDelegate *)NSApp.delegate) lockAllDocuments];
}
- (void)_willScreenSleepNotification:(NSNotification *)notification {
[((MPAppDelegate *)NSApp.delegate) lockAllDocuments];
}
- (void)_checkIdleTime:(NSTimer *)timer {
if(timer != self.idleCheckTimer) {

View File

@@ -42,6 +42,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyBrowserBundleId;
APPKIT_EXTERN NSString *const kMPSettingsKeyLockOnSleep;
APPKIT_EXTERN NSString *const kMPSettingskeyLockOnLogout;
APPKIT_EXTERN NSString *const kMPSettingsKeyIdleLockTimeOut;
APPKIT_EXTERN NSString *const kMPSettingskeyLockOnScreenSleep;
/* Autosaving states */
APPKIT_EXTERN NSString *const kMPSettingsKeyShowInspector;

View File

@@ -37,6 +37,7 @@ NSString *const kMPSettingsKeyFileChangeStrategy = @"FileCh
NSString *const kMPSettingsKeyEnableAutosave = @"EnableAutosave";
NSString *const kMPSettingsKeyLockOnSleep = @"LockOnSleep";
NSString *const kMPSettingskeyLockOnLogout = @"LockOnLogout";
NSString *const kMPSettingskeyLockOnScreenSleep = @"LockOnScreenSleep";
NSString *const kMPSettingsKeyIdleLockTimeOut = @"IdleLockTimeOut";
NSString *const kMPSettingsKeyShowInspector = @"ShowInspector";
NSString *const kMPSettingsKeyEntryTableSortDescriptors = @"EntryTableSortDescriptors";
@@ -132,6 +133,7 @@ NSString *const kMPDepricatedSettingsKeyAutotypeHideAccessibiltyWarning = @"Au
kMPSettingsKeyFileChangeStrategy: @(MPFileChangeStrategyAsk), // Ask what to do on a file change!
kMPSettingsKeyLockOnSleep: @YES,
kMPSettingskeyLockOnLogout: @NO,
kMPSettingskeyLockOnScreenSleep: @NO,
kMPSettingsKeyIdleLockTimeOut: @0, // 5 minutes
kMPSettingsKeyLegacyHideNotes: @NO,
kMPSettingsKeyLegacyHidePassword: @YES,