Skip to content
This repository has been archived by the owner on Nov 14, 2017. It is now read-only.

Commit

Permalink
Merge pull request #12 from macmule/issue#11_fix
Browse files Browse the repository at this point in the history
cleaned up the interval timer code
  • Loading branch information
pmbuko committed Sep 14, 2015
2 parents de7e6bf + 7e47a8c commit 86d10f1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion ADPassMon/ADPassMon-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>3</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
43 changes: 19 additions & 24 deletions ADPassMon/ADPassMonAppDelegate.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ If you do not know your keychain password, enter your new password in the New an
property daysUntilExpNice : ""
property expirationDate : ""
property mavAccStatus : ""
property passwordCheckInterval : 4 -- hours
property passwordCheckInterval : 4 -- hours
property enableKeychainLockCheck : ""
property selectedBehaviour : 1
property keychainPolicy : ""
Expand Down Expand Up @@ -319,7 +319,6 @@ Enable it now?" with icon 2 buttons {"No", "Yes"} default button 2)
pwPolicyURLButtonTitle:pwPolicyURLButtonTitle, ¬
pwPolicyURLButtonURL:pwPolicyURLButtonURL, ¬
pwPolicyURLButtonBrowser:pwPolicyURLButtonBrowser, ¬
passwordCheckInterval:passwordCheckInterval, ¬
allowPasswordChange:allowPasswordChange })
end regDefaults_

Expand Down Expand Up @@ -351,7 +350,6 @@ Enable it now?" with icon 2 buttons {"No", "Yes"} default button 2)
tell defaults to set my pwPolicyURLButtonURL to objectForKey_("pwPolicyURLButtonURL")
tell defaults to set my pwPolicyURLButtonBrowser to objectForKey_("pwPolicyURLButtonBrowser") as string
tell defaults to set my allowPasswordChange to objectForKey_("allowPasswordChange")
tell defaults to set my passwordCheckInterval to objectForKey_ ("passwordCheckInterval") as integer
end retrieveDefaults_

-- Disable notifications if running < 10.8
Expand Down Expand Up @@ -1308,29 +1306,26 @@ Enable it now?" with icon 2 buttons {"No", "Yes"} default button 2)
end setWarningDays_

-- Bound to passwordCheckInterval box in Prefs window
on passwordCheckIntervalCheck_(sender)
on setPasswordCheckInterval_(sender)
set my passwordCheckInterval to sender's intValue() as integer
-- If we have a value
if my passwordCheckInterval is not equal to missing value
-- Set to integer of value
set passwordCheckInterval to passwordCheckInterval as integer
-- Move to timer function
setpasswordCheckInterval_(me)
end if
end passwordCheckIntervalCheck_

-- Timer function
on setpasswordCheckInterval_(sender)
processTimer's invalidate() -- kills the existing timer
tell defaults to setObject_forKey_(passwordCheckInterval, "passwordCheckInterval")
-- start a timer with the new interval
set processTimer to current application's NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_((my passwordCheckInterval * 3600), me, "intervalDoProcess:", missing value, true)
set unit to " hours"
if passwordCheckInterval is equal to 1 then
set unit to " hour"
end if
if my passwordCheckInterval is equal to 1 then set unit to " hour"
log "Set check interval to " & passwordCheckInterval & unit
end setpasswordCheckInterval_
-- reset the timer
resetIntervalTimer_(me)
end setPasswordCheckInterval_

-- Timer function
on resetIntervalTimer_(sender)
my processTimer's invalidate() -- kills the existing timer
-- start a timer with the new interval
try
set my processTimer to current application's NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_((my passwordCheckInterval as integer * 3600), me, "intervalDoProcess:", missing value, true)
on error theError
log theError
end try
end resetIntervalTimer_

-- Bound to Notify items in menu and Prefs window
on toggleNotify_(sender)
Expand Down Expand Up @@ -1558,10 +1553,10 @@ Please choose your configuration options."
watchForWake_(me)

-- Set a timer to check for domain connectivity every five minutes. (300)
set domainTimer to NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(300, me, "intervalDomainTest:", missing value, true)
set my domainTimer to NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(300, me, "intervalDomainTest:", missing value, true)

-- Set a timer to trigger doProcess handler on an interval and spawn notifications (if enabled).
set processTimer to NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_((my passwordCheckInterval * 3600), me, "intervalDoProcess:", missing value, true)
set my processTimer to NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_((my passwordCheckInterval * 3600), me, "intervalDoProcess:", missing value, true)
else
log "Password does not expire. Stopping."
updateMenuTitle_("[--]", "Your password does not expire.")
Expand Down
14 changes: 4 additions & 10 deletions ADPassMon/en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,16 @@
<numberFormatter key="formatter" formatterBehavior="default10_4" numberStyle="decimal" minimumIntegerDigits="1" maximumIntegerDigits="2000000000" maximumFractionDigits="3" id="1ot-bq-FnG">
<real key="minimum" value="1"/>
<metadata>
<real key="inspectorSampleValue" value="0.5"/>
<real key="inspectorSampleValue" value="2"/>
</metadata>
</numberFormatter>
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="passwordCheckIntervalCheck:" target="494" id="Hp8-Ek-JAa"/>
<binding destination="494" name="value" keyPath="passwordCheckInterval" id="0YM-Ff-hD2">
<dictionary key="options">
<bool key="NSConditionallySetsEditable" value="NO"/>
<bool key="NSRaisesForNotApplicableKeys" value="NO"/>
<bool key="NSValidatesImmediately" value="YES"/>
</dictionary>
</binding>
<action selector="setPasswordCheckInterval:" target="494" id="4R0-8R-JJR"/>
<binding destination="494" name="value" keyPath="passwordCheckInterval" id="axh-Yp-3Hv"/>
</connections>
</textField>
<textField verticalHuggingPriority="750" id="LRy-g9-pwg">
Expand All @@ -248,7 +242,7 @@
<connections>
<action selector="setWarningDays:" target="494" id="7JE-DY-v74"/>
<binding destination="494" name="enabled" keyPath="enableNotifications" id="94g-Tn-9kn"/>
<binding destination="494" name="value" keyPath="warningDays" id="8Ar-rB-7MP"/>
<binding destination="494" name="value" keyPath="warningDays" id="19Y-Wl-1SA"/>
</connections>
</textField>
<matrix verticalHuggingPriority="750" tag="1" id="dP0-TO-Peb">
Expand Down

0 comments on commit 86d10f1

Please sign in to comment.