Capture When Session Has Loaded

I am working on a toast notification system via scripting and have a use case where I want to send a message to a component once the session has "loaded" (e.g. the first time the landing page loads).

I have a temporary workaround by utilizing the session startup script and sending the message after a hard coded delay, but this is not ideal as the load time is dependent on the connection speed. Is there any way to do this via scripting?

I know I could setup a custom session property and write to it from the on startup script on the home page, but this is an inherited project and I would prefer not to have to setup every project.

Session properties and session events are resource blobs, so will need to be set up on every leaf project anyways.

I'd highly recommend you check out @bmusson 's module which integrates toastify:

If it helps, I wrote this small libarary with a function to call the toast notification:

# LIBRARY: shared.fe.perspective.toast
class ToastType:
	INFO = 'info'
	SUCCESS = 'success'
	WARNING = 'warning'
	ERROR = 'error'


def showToast(content, toastType=ToastType.INFO, autoClose=5000):
	"""
	Shows a toast notification to the user.
	Required Modules:
		Embr-Periscope
	
	"""
	args = {
		'content': content,
		'options': {
			  "autoClose": 5000,
			  "closeButton": True,
			  "closeOnClick": False,
			  "draggable": True,
			  "hideProgressBar": False,
			  "icon": True,
			  "pauseOnFocusLoss": False,
			  "pauseOnHover": True,
			  "position": "bottom-center",
			  "theme": "colored",
			  "type": toastType
			}
		}
	system.perspective.runJavaScriptAsync('''(content, options) => {		
		periscope.toast(content, options)
	}''', args)

Call it like this:

shared.fe.perspective.toast.showToast('Hello!', shared.fe.perspective.toast.ToastType.SUCESS)

Note: "fe" stands for FrontEnd, if you are wondering

2 Likes

Well then... this looks exactly what I was looking for 12+ months ago when I started this side project :rofl:

Time to gut my library :upside_down_face:

Thanks!

2 Likes

No worries, always happy to help someone throw a year of their life's work away! :grimacing: (although I fully "blame" Ben for this one :grin:)

1 Like