mirror of
https://github.com/munki/munki.git
synced 2026-01-08 23:50:18 -06:00
More IPC changes between munkilib.munkistatus and MunkiStatus and Managed Software Update
This commit is contained in:
@@ -110,7 +110,8 @@ class MSUAppDelegate(NSObject):
|
||||
def checkForUpdates(self, suppress_apple_update_check=False):
|
||||
# kick off an update check
|
||||
# attempt to start the update check
|
||||
result = munki.startUpdateCheck(suppress_apple_update_check)
|
||||
#result = munki.startUpdateCheck(suppress_apple_update_check)
|
||||
result = 0
|
||||
if result == 0:
|
||||
self.managedsoftwareupdate_task = "manualcheck"
|
||||
self.statusController.startMunkiStatusSession()
|
||||
|
||||
@@ -1219,8 +1219,16 @@ class MSUMainWindowController(NSWindowController):
|
||||
# clicks the Install All button in the Updates view
|
||||
if self._update_in_progress:
|
||||
# this is now a stop/cancel button
|
||||
self._status_stopBtnState = 1
|
||||
self.disableStopButton()
|
||||
self._status_stopBtnState = 1
|
||||
# send a notification that stop button was clicked
|
||||
notification_center = NSDistributedNotificationCenter.defaultCenter()
|
||||
notification_center.postNotificationName_object_userInfo_options_(
|
||||
'com.googlecode.munki.MunkiStatus.stopButtonClicked',
|
||||
None,
|
||||
None,
|
||||
NSNotificationDeliverImmediately + NSNotificationPostToAllSessions)
|
||||
|
||||
elif self.getUpdateCount() == 0:
|
||||
# no updates, this button must say "Check Again"
|
||||
self._update_in_progress = True
|
||||
@@ -1589,52 +1597,56 @@ class MSUMainWindowController(NSWindowController):
|
||||
return self._status_stopBtnState
|
||||
|
||||
def hideStopButton(self):
|
||||
self._status_stopBtnHidden = True
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if not 'hidden' in btn_classes:
|
||||
btn_classes.append('hidden')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
if not self._status_stopBtnState:
|
||||
self._status_stopBtnHidden = True
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if not 'hidden' in btn_classes:
|
||||
btn_classes.append('hidden')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
|
||||
def showStopButton(self):
|
||||
self._status_stopBtnHidden = False
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if 'hidden' in btn_classes:
|
||||
btn_classes.remove('hidden')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
if not self._status_stopBtnState:
|
||||
self._status_stopBtnHidden = False
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if 'hidden' in btn_classes:
|
||||
btn_classes.remove('hidden')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
|
||||
def enableStopButton(self):
|
||||
self._status_stopBtnDisabled = False
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if 'installed-not-removable' in btn_classes:
|
||||
btn_classes.remove('installed-not-removable')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
if not self._status_stopBtnState:
|
||||
self._status_stopBtnDisabled = False
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if 'installed-not-removable' in btn_classes:
|
||||
btn_classes.remove('installed-not-removable')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
|
||||
def disableStopButton(self):
|
||||
self._status_stopBtnDisabled = True
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if not 'installed-not-removable' in btn_classes:
|
||||
btn_classes.append('installed-not-removable')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
if not self._status_stopBtnState:
|
||||
self._status_stopBtnDisabled = True
|
||||
document = self.webView.mainFrameDocument()
|
||||
spinner = document.getElementById_('updates-progress-spinner')
|
||||
if spinner: # we are displaying the updates status page
|
||||
install_btn = document.getElementById_('install-all-button-text')
|
||||
if install_btn:
|
||||
btn_classes = install_btn.className().split(' ')
|
||||
if not 'installed-not-removable' in btn_classes:
|
||||
btn_classes.append('installed-not-removable')
|
||||
install_btn.setClassName_(' '.join(btn_classes))
|
||||
|
||||
def getRestartAlertDismissed(self):
|
||||
return self._status_restartAlertDismissed
|
||||
|
||||
@@ -79,18 +79,20 @@ class MSUStatusController(NSObject):
|
||||
self.statusWindowController.setDetail_(info['detail'])
|
||||
if 'percent' in info:
|
||||
self.statusWindowController.setPercentageDone_(info['percent'])
|
||||
if 'stop_button_visible' in info:
|
||||
if info['stop_button_visible']:
|
||||
self.statusWindowController.showStopButton()
|
||||
else:
|
||||
self.statusWindowController.hideStopButton()
|
||||
if 'stop_button_enabled' in info:
|
||||
if info['stop_button_enabled']:
|
||||
self.statusWindowController.enableStopButton()
|
||||
else:
|
||||
self.statusWindowController.disableStopButton()
|
||||
command = info.get('command')
|
||||
if command == 'activate':
|
||||
NSApp.activateIgnoringOtherApps_(YES) #? do we really want to do this?
|
||||
self.statusWindowController.window().orderFrontRegardless()
|
||||
elif command == 'hideStopButton':
|
||||
self.statusWindowController.hideStopButton()
|
||||
elif command == 'showStopButton':
|
||||
self.statusWindowController.showStopButton()
|
||||
elif command == 'disableStopButton':
|
||||
self.statusWindowController.disableStopButton()
|
||||
elif command == 'enableStopButton':
|
||||
self.statusWindowController.enableStopButton()
|
||||
elif command == 'showRestartAlert':
|
||||
self.statusWindowController.doRestartAlert()
|
||||
elif command == 'quit':
|
||||
|
||||
@@ -168,17 +168,20 @@ class MSUStatusWindowController(NSObject):
|
||||
self.setDetail_(info['detail'])
|
||||
if 'percent' in info:
|
||||
self.setPercentageDone_(info['percent'])
|
||||
if self.stopBtnState == 0 and 'stop_button_visible' in info:
|
||||
if info['stop_button_visible']:
|
||||
self.showStopButton()
|
||||
else:
|
||||
self.hideStopButton()
|
||||
if self.stopBtnState == 0 and 'stop_button_enabled' in info:
|
||||
if info['stop_button_enabled']:
|
||||
self.enableStopButton()
|
||||
else:
|
||||
self.disableStopButton()
|
||||
|
||||
command = info.get('command')
|
||||
if command == 'activate':
|
||||
self.window.orderFrontRegardless()
|
||||
elif command == 'hideStopButton':
|
||||
self.hideStopButton()
|
||||
elif command == 'showStopButton':
|
||||
self.showStopButton()
|
||||
elif command == 'disableStopButton':
|
||||
self.disableStopButton()
|
||||
elif command == 'enableStopButton':
|
||||
self.enableStopButton()
|
||||
elif command == 'showRestartAlert':
|
||||
self.doRestartAlert()
|
||||
elif command == 'quit':
|
||||
@@ -225,7 +228,7 @@ class MSUStatusWindowController(NSObject):
|
||||
return self.stopBtnState
|
||||
|
||||
def hideStopButton(self):
|
||||
self.stopBtn.setHidden_(True)
|
||||
self.stopBtn.setHidden_(True)
|
||||
|
||||
def showStopButton(self):
|
||||
self.stopBtn.setHidden_(False)
|
||||
|
||||
@@ -35,6 +35,19 @@ from Foundation import NSNotificationPostToAllSessions
|
||||
# our NSDistributedNotification identifier
|
||||
NOTIFICATION_ID = 'com.googlecode.munki.managedsoftwareupdate.statusUpdate'
|
||||
|
||||
# keep our current status. We keep this so that notification clients
|
||||
# that come "online" late can get current state
|
||||
_currentStatus = {}
|
||||
|
||||
def initStatusDict():
|
||||
_currentStatus = {
|
||||
'message': '',
|
||||
'detail': '',
|
||||
'percent': -1,
|
||||
'stop_button_visible': True,
|
||||
'stop_button_enabled': True,
|
||||
'command': ''
|
||||
}
|
||||
|
||||
def launchMunkiStatus():
|
||||
'''Uses launchd KeepAlive path so it launches from a launchd agent
|
||||
@@ -43,7 +56,7 @@ def launchMunkiStatus():
|
||||
happier.
|
||||
There needs to be a launch agent that is triggered when the launchfile
|
||||
is created; and that launch agent then runs MunkiStatus.app.'''
|
||||
|
||||
initStatusDict()
|
||||
# TESTING, TESTING
|
||||
return
|
||||
|
||||
@@ -55,63 +68,82 @@ def launchMunkiStatus():
|
||||
os.unlink(launchfile)
|
||||
|
||||
|
||||
def postNotificationWithUserDict(userInfoDict):
|
||||
def postStatusNotification():
|
||||
dnc = NSDistributedNotificationCenter.defaultCenter()
|
||||
dnc.postNotificationName_object_userInfo_options_(
|
||||
NOTIFICATION_ID,
|
||||
None,
|
||||
userInfoDict,
|
||||
_currentStatus,
|
||||
NSNotificationDeliverImmediately + NSNotificationPostToAllSessions)
|
||||
|
||||
|
||||
def activate():
|
||||
'''Brings MunkiStatus window to the front.'''
|
||||
postNotificationWithUserDict({'command': 'activate'})
|
||||
|
||||
|
||||
def message(messageText):
|
||||
'''Sets the status message.'''
|
||||
postNotificationWithUserDict({'message': messageText})
|
||||
_currentStatus['message'] = messageText
|
||||
postStatusNotification()
|
||||
|
||||
|
||||
def detail(detailsText):
|
||||
'''Sets the detail text.'''
|
||||
postNotificationWithUserDict({'detail': detailsText})
|
||||
_currentStatus['detail'] = detailsText
|
||||
postStatusNotification()
|
||||
|
||||
|
||||
def percent(percentage):
|
||||
'''Sets the progress indicator to 0-100 percent done.
|
||||
If you pass a negative number, the progress indicator
|
||||
is shown as an indeterminate indicator (barber pole).'''
|
||||
postNotificationWithUserDict({'percent': percentage})
|
||||
_currentStatus['percent'] = percentage
|
||||
postStatusNotification()
|
||||
|
||||
|
||||
def hideStopButton():
|
||||
'''Hides the stop button.'''
|
||||
postNotificationWithUserDict({'command': 'hideStopButton'})
|
||||
_currentStatus['stop_button_visible'] = False
|
||||
postStatusNotification()
|
||||
|
||||
|
||||
def showStopButton():
|
||||
'''Shows the stop button.'''
|
||||
postNotificationWithUserDict({'command': 'showStopButton'})
|
||||
_currentStatus['stop_button_visible'] = True
|
||||
postStatusNotification()
|
||||
|
||||
|
||||
def disableStopButton():
|
||||
'''Disables (grays out) the stop button.'''
|
||||
postNotificationWithUserDict({'command': 'disableStopButton'})
|
||||
_currentStatus['stop_button_enabled'] = False
|
||||
postStatusNotification()
|
||||
|
||||
|
||||
def enableStopButton():
|
||||
'''Enables the stop button.'''
|
||||
postNotificationWithUserDict({'command': 'enableStopButton'})
|
||||
_currentStatus['stop_button_enabled'] = True
|
||||
postStatusNotification()
|
||||
|
||||
|
||||
def activate():
|
||||
'''Brings MunkiStatus window to the front.'''
|
||||
_currentStatus['command'] = 'activate'
|
||||
postStatusNotification()
|
||||
# now clear the command; unlike the other fields, this
|
||||
# should not persist between notifications
|
||||
_currentStatus['command'] = ''
|
||||
|
||||
|
||||
def quit():
|
||||
'''Tells the status app that we're done.'''
|
||||
postNotificationWithUserDict({'command': 'quit'})
|
||||
_currentStatus['command'] = 'quit'
|
||||
postStatusNotification()
|
||||
# now clear the command; unlike the other fields, this
|
||||
# should not persist between notifications
|
||||
_currentStatus['command'] = ''
|
||||
|
||||
|
||||
def restartAlert():
|
||||
'''Tells MunkiStatus to display a restart alert.'''
|
||||
postNotificationWithUserDict({'command': 'showRestartAlert'})
|
||||
_currentStatus['command'] = 'showRestartAlert'
|
||||
postStatusNotification()
|
||||
# now clear the command; unlike the other fields, this
|
||||
# should not persist between notifications
|
||||
_currentStatus['command'] = ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user