Detect project update from client in notify mode

Works as desired; thanks! In case it helps someone else, the below updates on idle, re-opening all the windows that were open in the primary desktop after updating. It also prints a line to client console recording update.

Script in shared.gui (edit: improved with @cmaynes suggestion in following post):

from com.inductiveautomation.factorypmi.application.runtime import UpdateAvailableInfoBar

# Is an update available for client?
def getUpdateNotification(obj):
	result = False
	for sub in obj.getComponents():
		#print "*"*10, type(sub)
		if not result:
			if isinstance(sub,UpdateAvailableInfoBar):
				return True
			else:
				result = getUpdateNotification(sub)			
	return result

Script in client event timer script:

from javax.swing import SwingUtilities

# If client has been inactive for an hour, check for update.
if system.util.getInactivitySeconds() > 3600:
	# Get windows in main desktop where notification is shown.
	windows = system.gui.getOpenedWindows()
	# Get root of first window.
	root = SwingUtilities.getRoot(windows[0])
	# If there's an update notification, update client.
	if shared.gui.getUpdateNotification(root):
		# Get project name and opened windows.
		print "Found update notification info bar while idle. Updating client."
		projectName = system.tag.read('[System]Client/System/ProjectName').value
		openWindows = system.gui.getOpenedWindowNames()
		# Update by retargeting back to same project and open same windows.
		system.util.retarget(projectName, None, None, openWindows)
3 Likes