Show a progress spinner over the Updates button when an update (check or install) is in progress

This commit is contained in:
Greg Neagle
2014-04-01 18:09:56 -07:00
parent 41b5661d63
commit df0b986b34
3 changed files with 46 additions and 12 deletions
@@ -39,9 +39,12 @@ class MSUBadgedTemplateImage(NSImage):
if count == 0:
# no badge if there are no updates
return super(MSUBadgedTemplateImage, self).imageNamed_(name)
if count > 0:
count_str = str(count)
else:
count_str = str(0)
# build badge string and get its size
badgeString = NSString.stringWithString_(str(count))
badgeString = NSString.stringWithString_(count_str)
badgeFont = NSFontManager.sharedFontManager().fontWithFamily_traits_weight_size_(
badgeFontFamilyName, NSBoldFontMask, 0, badgeFontSize)
stringAttributes = { NSFontAttributeName: badgeFont }
@@ -97,11 +100,12 @@ class MSUBadgedTemplateImage(NSImage):
badgeEraseMask.fill()
NSGraphicsContext.restoreGraphicsState()
# draw badge outline
badgeOutline.stroke()
# draw count string
badgeString.drawWithRect_options_attributes_(badgeStringRect, 0, stringAttributes)
if count > 0:
# draw badge outline
badgeOutline.stroke()
# draw count string
badgeString.drawWithRect_options_attributes_(badgeStringRect, 0, stringAttributes)
# all done drawing!
compositeImage.unlockFocus()
@@ -62,6 +62,7 @@ class MSUMainWindowController(NSWindowController):
updateButtonCell = IBOutlet()
windowMenuSeperatorItem = IBOutlet()
fullScreenMenuItem = IBOutlet()
updateProgressSpinner = IBOutlet()
def appShouldTerminate(self):
'''called by app delegate when it receives applicationShouldTerminate:'''
@@ -444,9 +445,17 @@ class MSUMainWindowController(NSWindowController):
'''Display the update count as a badge in the window toolbar
and as an icon badge in the Dock'''
updateCount = self.getUpdateCount()
btn_image = MSUBadgedTemplateImage.imageNamed_withCount_(
'toolbarUpdatesTemplate.png', updateCount)
self.updateButtonCell.setImage_(btn_image)
if self._update_in_progress:
btn_image = MSUBadgedTemplateImage.imageNamed_withCount_(
'toolbarUpdatesTemplate.pdf', -1)
self.updateButtonCell.setImage_(btn_image)
self.updateProgressSpinner.startAnimation_(self)
else:
self.updateProgressSpinner.stopAnimation_(self)
btn_image = MSUBadgedTemplateImage.imageNamed_withCount_(
'toolbarUpdatesTemplate.pdf', updateCount)
self.updateButtonCell.setImage_(btn_image)
if updateCount:
NSApp.dockTile().setBadgeLabel_(str(updateCount))
else:
@@ -765,6 +774,21 @@ class MSUMainWindowController(NSWindowController):
NSLog('Unexpected error')
return
item.update_status()
if item.get('will_be_installed') or item.get('will_be_removed'):
# item was processed and cached for install or removal. Need to run
# an updatecheck session to possibly remove other items (dependencies
# or updates) from the pending list
if not self._update_in_progress:
self._update_in_progress = True
self.displayUpdateCount()
self.checkForUpdates(suppress_apple_update_check=True)
else:
# add to queue to check later
# TO-DO: fix this as this can trigger an install as well
#self._update_queue.add(item['name'])
pass
self.displayUpdateCount()
if item['status'] == 'not-installed':
# we removed item from list of things to install
@@ -832,8 +856,9 @@ class MSUMainWindowController(NSWindowController):
def setStatusViewTitle_(self, title_text):
'''When displaying status during a managedsoftwareupdate run, this method
is used to disply info where the update count message usually is'''
is used to display info where the update count message usually is'''
document = self.webView.mainFrameDocument()
self._status_title = title_text
# we re-purpose the update count message for this
update_count_element = document.getElementById_('update-count-string')
if update_count_element:
@@ -234,7 +234,7 @@
<action selector="searchFilterChanged:" target="KMl-S0-0FF" id="bfv-In-bkh"/>
</connections>
</searchField>
<customView autoresizesSubviews="NO" id="802">
<customView autoresizesSubviews="NO" wantsLayer="YES" id="802">
<rect key="frame" x="406" y="676" width="330" height="52"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
@@ -310,6 +310,10 @@
<action selector="tabControlClicked:" target="KMl-S0-0FF" id="pKT-yQ-fzz"/>
</connections>
</matrix>
<progressIndicator horizontalHuggingPriority="750" verticalHuggingPriority="750" alphaValue="0.80000000000000004" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" id="oix-r8-qeB">
<rect key="frame" x="279" y="35" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</progressIndicator>
</subviews>
</customView>
<progressIndicator horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" id="X8X-xa-e0T">
@@ -361,6 +365,7 @@
<outlet property="searchField" destination="557" id="HM7-VX-9cg"/>
<outlet property="tabControl" destination="796" id="AEs-wG-NLb"/>
<outlet property="updateButtonCell" destination="fG2-SY-8g2" id="92m-84-OS5"/>
<outlet property="updateProgressSpinner" destination="oix-r8-qeB" id="jaC-eu-JnL"/>
<outlet property="webView" destination="S5Y-lq-2nB" id="TPJ-jP-F85"/>
<outlet property="window" destination="371" id="JK3-nH-LOl"/>
<outlet property="windowMenuSeperatorItem" destination="92" id="eCt-83-MtH"/>