How to close a browser window after an exit event trigger in a unity webgl game (for accessibility sake)? - unity3d

I have to develop a browser based game with WebGL (for cross-platform support) using Unity that allows people with severe disabilities to take full control of their experience. This also includes opening and closing the application on their own. Opening the browser and game is pretty straightforward since these people can simply open them using a program provided by another company (like Tobii), but now I am facing an issue when trying to close the window again, since there doesn't seem to be a way to achieve this from within the browser/game.
My question is, is there a way to close the browser with JavaScript or maybe even in Unity itself? Or should I look towards creating an application outside of the browser with something like Java (for cross-platform support) that manages the browser window?
I already looked into ways of doing it via JavaScript or even from within unity, but I simply couldn't find a solution. I tried using JavaScript's windows.close() function, but that only works on windows opened from within JavaScript itself by the looks of it. Looking at a stand-alone application then leaves the question of how to detect an exit request from the user when they are done playing the game.
What I am looking for is a way for them to select an 'exit' button within the game which then closes the browser, so they can return to their assistance program, without the help from another person.
Currently, the user is only able to make use of a single button and can't control mouse or cursor themselves, meaning that they can't close the browser on their own.
tl;dr how can I close a browser window using an exit button in a WebGL Unity game for a person who isn't able to themselves due to a handicap?

Pretty sure you can't
And that goes back to window.close only working on windows opened with JS. Originally it could close any window, but people started abusing that fact (think about things like the self-retweeting tweet, except it also closes your browser tab!)
So the restriction got added.
This is why we can't have nice things.

Related

Generally what would cause Unity Editor freezes and not responding?

I have encountered a critical issue that Unity Editor freezes. I've spent many hours debugging step by step of my codes but still can't find where the problem is. So I think maybe I should try thinking from another angle, generally speaking what reasons would cause Unity Editor freezes and not responding?
I can't find a general case discussion about this topic.
From my experience, infinite loop is one reason for sure. Deadlock is critical issue, but not sure if it causes Unity Editor freezes. Unity Editor bug that I encountered only makes the whole editor crashes, instead of freezing. Any other experiences are welcomed. Thank you!
In such case, what kind of tools or methods could I use to debug it? Right now since the editor freezes I can't use "print" to find out what happens after it freezes. So I use Visual studio to debug the Editor thread, in this way I can see all the prints that I wrote. It appears the game is still running, only the editor not responding. And I can use VS click "attach to Unity and play" and put some debugging points, then debug step by step.
The first thing that I would check out is for an infinite loop. At the hang/freeze moment, you can attatch the debugger of your choice and pause the execution. In the case that it is an infinite loop that it is executing, at the exec time pause you might find the execution in a forever running while (true) {...}
Other thing that I would check is the plugins in use. Several Unity plugins like Parse, FMOD, UMP (Universal Media Player), ZFBrowser, or Embedded Browser are using native threads. It’s an issue when a plugin ends up attaching a native thread to the runtime, which then does blocking calls to the OS. This means Unity can't interrupt that thread for the debugger (or domain reload) and hang. Source
To check that you can check the active threads in the visual studio command window af the freeze is reproduced:
View->OtherWindows->CommandWindow and type in this command:
Debug.ListCallStack /AllThreads /ShowExternalCode
In the stack you can check if some thread is there with no need, or if its related with the plugins mentioned above.
Also an interesting point is to check in the windows task manager (in the case that you are using windows) if the CPU usage is to 0%. It can lead you to the type of hang that is taking place.
Good luck.
Edit: I forgot to mention, you need to check also the unity logfiles
I notice this all the time, and its super frustrating.
Unfortunately, this could be any number of issues. I notice this issue most often when working in projects that are made for the Universal Windows Platform.
Try using the Task manager to monitor specific processes / threads running.
Some follow up questions:
What platform is your project currently targeting?
What version of Unity are you running? Have you tried other versions?
What are your computers specs? Is the OS up to date? Graphics Drivers?
Does it happen (or happen more often) when an external code editor is open? Perhaps try going to Preferences>External Editor > Regenerate Project files.
Are you using Unity Collab by chance? I've had issues where collab is stuck trying to communicate with Unity Servers / looking for changes. Try logging out of your Unity account through the editor, and log back in.
Have you tried looking for a Unity editor crash dump, or error log files? I think they can be found here C:\Users\username\AppData\LocalLow\Unity by default. Those files may give you more specific data concerning your problem.
Unity's new versions are getting more slower and slower. From my experience 2019 versions are the best and more stable.
I solved my issue. It's fundamentally an infinite loop.
It's not a simple case such as "while(true)". I'll try to explain.
My game was a PvP game, and I'm making a local AI. Usually my design pattern works fine, however I just turned off the simulation of "AI thinking time", and since the AI codes and server codes all run in local mode, the transmitting of data between server and client are replaced by local method call(meaning instantly executed before everything else).
There is a loophole in my server code. I use "Update" and a flag on server to change a specific game state, however in this particular case, it got into an infinite loop because the local method call is executed before the "Update". And because my AI now doesn't need real time to "think", it "acts" and transmits the event data to server right away. And since the transmitting doesn't need time any more, it calls the server method instantly, hence forming the infinite loop.

Black windows issue

I develop a web browser based on gtk+ and webkit2gtk in Rust and sometimes, all GTK+ windows become black.
Even the gtk inspector window that we get with the environment variable GTK_DEBUG=interactive is black.
Even thought the windows are black, the UI is still responsive since I can navigate the web with the keyboard (I see the window title updating, showing the new page URL and load progress).
Here are two actions that triggers this issue everytime they happen:
Destroying the web view
When running the application a second time, it sends a message via Unix Domain Socket to the first process so that it creates a new web view.
I have unfortunately no small example to reproduce the issue. If you want, I can show you the code of the project, but it is big, non-trivial and uses many abstraction layers over gtk+.
I know I don't give you a lot to help me, but if you can give me some explanations about how the rendering works and how to debug that, it would be very appreciated.
Can you give me some hints on how to debug this issue?
Is there a global OpenGL (or whatever) context for the GTK+ windows?
Are there some debuging tools to help me? (Setting G_MESSAGES_DEBUG=all does not show anything relevant.)
With strace, I was able to debug this issue:
I found out the FD used for IPC communication was still polled after being closed, so it was returning POLLNVAL.
Removing the FD with g_source_remove_unix_fd() fixed this issue.

How to access electron app's current browserWindow?

I'm stuck on a particular point with my Electron app:
When I open the devTools, I call mainWindow.webContents.openDevTools() from the app's menu. It's working fine on mainWindow.
The problem appears on child windows, opened by window.open(): the app menu is still working on every window, but it always call mainWindow's devtools (which is normal, since I told it to do so), where I would like to get current window's ones.
So I wonder if there is a way to call something like currentWindow.webContents.openDevTools() ? I found nothing in the documentation nor on SO nor by googling, so I guess I might haev missed something.
Let me precise a few things:
I'm still a newbie with Electron
I have no control on the pages that are called in the app, I'm trying to use electron as a kind of "restricted browser" to ship with a PHP-based application
After a bit more reading, I just found out that BrowserWindow.getFocusedWindow() is exactly what I was looking for.
So in my app menu, I juste call BrowserWindow.getFocusedWindow().webContents.openDevTools(), and it works as I expected.

desktop icon functionality in a window

My wife complains that I have too many icons on the Windows XP-Pro desktop.
I like to be able to quickly drop a file onto the icon for application I want to have open it. And I like to follow a link to open often-used deeply nested folders rather than navigate there. Thus, I have over 100 icons on the desktop.
(We share the same user account because we switch back and forth so often and because we both need to access the same e-mail, so separate accounts isn't the answer.)
I'd like to write a program which would have similar functionality to the Windows desktop. Then I could open that window to do the drag and drop work, but, when minimized, would leave the desktop display sparsely populated for my wife. As an added bonus, I could implement better organization of the icons than the desktop allows.
This is similar to what an Explorer window does, with the key exception that the desktop allows you to do some arrangement of icons. (For instance, program icons on the left (with the most used ones near the top), folders at the top, data files on the right.)
How do I go about getting an icon to display in a Windows Form (or on an appropriate control on the form)? (For instance, if I drop in a link to Notepad or a link to a file folder.)
How do I take the same action that the desktop does if the icon is double clicked? (For instance, if a link to a folder is double clicked.)
How do I take the same action that the desktop does if the icon has something dragged onto it? (For instance, a text file is dragged onto the Notepad icon.)
I'm using Visual Studio and C#.NET for programming.
I know how to do basic drag and drop.
I do not know:
A. what controls to use on the form to display the icons
B. how to find the icon
C. what commands are built by the desktop under various situations (so I can emulate the functionality)
I apologize that this is a multi-part question, but it was hard to break apart without explaining the whole story again.
This is a big question, but I'll give you some quick thoughts to get things moving in the right direction. WinForms exposes the functionality needed to make this happen, it's just a matter of wiring everything up the way you want it.
The key piece that you will want to look into is Drag/Drop, which is very well supported by WinForms. If you implement your icons as ImageBoxes you can set the AllowDrop property on the program icons and then handle the DragDrop event and have it call an overload of System.Diagnostics.Process() to start the application with the dropped filename as an argument.
As far as finding icons, most programs have their icon included as a resource in their .EXE file or in a related .DLL.
Regarding question C, the underlying question is what behaviors of the desktop would you like to have in your program? Explorer.exe is a massive application that does far more than what you need or what you will need or want to implement. Once you decide what functionality you want, play around with the IntelliSense list of events for the form and imagebox controls. You'll find that a lot of behavior is given to you for free in the Windows common controls, and additional behavior is fairly easy to add by handling the appropriate events.
Why dont you just use a Virtual Desktop??
Try http://virtuawin.sourceforge.net/
You will skip a lot of coding.
Right from their page:
"VirtuaWin is a virtual desktop manager for the Windows operating system (Win9x/ME/NT/Win2K/XP/Win2003/Vista). A virtual desktop manager lets you organize applications over several virtual desktops (also called 'workspaces'). Virtual desktops are very common in Unix/Linux, and once you get accustomed to using them, they become an essential part of a productive workflow."

Embedded MSHTML: mouse wheel ignored

In my VC++ application I have an embedded browser (MSHTML). It works fine and handles the mouse properly (for instance, clicks and selects are processed OK). However, mouse wheel rotations over the embedded browser do not have any effect. This is my problem.
I am not very familiar with the internals of MSHTML embedding, and OLE in general. This is an wxWidgets application (wxWidgets is a C++ GUI library), and I am making use of its IEHTMLWin component (which hosts an MSHTML control and wraps it in the wxWindow interface). However, I do have the source and am willing to do some debugging.
Forgetting wxWidgets and speaking purely about OLE and MSHTML, what's the right place to start looking for the problem cause? I tried naive googling for variants of "mshtml mouse events" or "mshtml wheel", but didn't give any good pointers.
Should you want to take a look at the code of IEHTMLWin, it can be browsed here. The iehtmlwin.c file (1,5 k lines) has all the OLE-related code and implements all interfaces needed to host a web browser control. It's worth noting that mouse events don't proceed to the containing wxWindow at all (OnMouse is never called).
{UPD} mshtml version: 6.00.2900.3314. Other applications that host this control (including IE) support the wheel. {/UPD}
jdigital hint (regarding winspector) was very helpful. After some message sniffing, I realize that the problem is focus-related. A click on the browser control somehow does not set focus on the browser control (unlike, say, RichEdit), and WM_MOUSEWHEEL is not sent there. So the new problem is setting the focus.
Try Winspector (http://www.windows-spy.com/) which will allow you to see the windows messages. Make sure that the scroll wheel events are getting passed through.