Leighm0/WebView

Why need to C4:SetTimer before calling firing URL_CHANGED in OnDriverLateInit?

darxis opened this issue · 3 comments

darxis commented

Why there is a need to wait 3 seconds before calling C4:SendToProxy(5001, "URL_CHANGED", ...)?

function OnDriverLateInit()
	...
	C4:SetTimer(3000, function(timer) 
		C4:SendToProxy(5001, "URL_CHANGED", {url = Properties["URL"]})
		setPresetIcon(Properties["Presets"])
		if (g_AutoRename) then setPresetName(Properties["Presets"]) end
	end)
end

If you remove the wait and call C4:SendToProxy(5001, "URL_CHANGED", ...) directly then somehow the URL for the UI button doesn't get set when the director reboots and the button doesn't work at all. Is there a more elegant way to wait until you can call C4:SendToProxy(5001, "URL_CHANGED", ...) instead of waiting 3 seconds?

Hey, is there any specific reason why we need to call C4:SendToProxy(5001, "URL_CHANGED", {url = Properties["URL"]}) within C4:SetTimer in OnDriverLateInit? If you remove C4:SetTimer and call C4:SendToProxy(5001, "URL_CHANGED", {url = Properties["URL"]}) directly then the URL doesn't get set. It seems that we need to wait before calling this but why? The driverworks docs don't mention this strange behavior...

Hey, is there any specific reason why we need to call C4:SendToProxy(5001, "URL_CHANGED", {url = Properties["URL"]}) within C4:SetTimer in OnDriverLateInit? If you remove C4:SetTimer and call C4:SendToProxy(5001, "URL_CHANGED", {url = Properties["URL"]}) directly then the URL doesn't get set. It seems that we need to wait before calling this but why? The driverworks docs don't mention this strange behavior...

Honestly I don't know why it's required, but in my initial testing it didn't work without waiting atleast 3 seconds before calling the SendToProxy for URL_CHANGED in the driver inits. If you want to query it further I suggest talking to Snap one Devs asking them why its not possible to work without the delay.

If you find a better method of doing this, please post a pull request with the updated code.

I've observed this strange behavior when developing my custom drivers and in my case waiting 1 second is sufficient. I also need to wait that 1 second before calling SendToProxy not only for URL_CHANGED but also for ICON_CHANGED event.