How to detect when my application is not visible?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dpensky

How do I detect when my html5 exported game is not visible?

  • when the user changes to another tab
  • when the user has minimized the browser
  • when the user alt+tab to another app

I already tried to print all events in _notification (what). however it appears that no notification is sent in these cases *sigh*

thanks in advance

:bust_in_silhouette: Reply From: djangocoyote

All those cases can be handled with MainLoop’s NOTIFICATION_WM_FOCUS_OUT.

func _notification(what):
    match what:
           #Pause however you want here

This works great in the editor, but nothing happens on the HTML5 exported version

my code:

func _notification(what):
	match what:
			if $background.playing:
				print('pausing background')
				$background.stream_paused = true
			if play_background and Settings.is_music_on():
				if $background.stream_paused:
					$background.stream_paused = false
					print('resuming background')

dpensky | 2021-04-20 11:56

Well… this sucks. I discovered that this notification is only emitted on the Release version and not in the Debug version of the HTML5 exported version for some obscure reason, which is a pain to test

dpensky | 2021-04-20 12:40

That’s not the case either. Something else is interfering with this notification.
Sometimes this works, sometimes don’t.

dpensky | 2021-04-20 13:13