Created
September 10, 2012 18:18
-
-
Save natesilva/3692687 to your computer and use it in GitHub Desktop.
Chocolat mixin onUnload does not fire when window is closed using the red "X"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// To test: | |
// | |
// (Use this in a Chocolat Mixin. Drop in any default.html file.) | |
// | |
// 1. Press Cmd-Opt-Ctrl-H and note the window appears. | |
// 2. Press "OK" and note that onUnload fires. | |
// 3. Repeat several times until you're convinced it works. | |
// | |
// Then: | |
// | |
// 4. Press Cmd-Opt-Ctrl-H. The window will appear. | |
// 5. Close the window using the red "X" in the corner. Note that | |
// onUnload does not fire. | |
// 6. Press Cmd-Opt-Ctrl-H. The window will *probably* appear. | |
// 7. Close it again using the red "X". | |
// 8. Open again and close using the red "X". After the second or | |
// third time it no longer works. | |
// | |
// Hypothesis: Closing the window with the red "X" deallocates it. | |
// When it's re-opened, we are seeing a window that has been or is | |
// about to be deallocated. It just happens to work--at first. | |
// | |
// Problem: Without a way to detect if the window exists or has been | |
// deallocated, it's hard to have a clean UI for mixins like JSHint. | |
// | |
// global, so we can try to re-use the window | |
var win; | |
Hooks.addMenuItem('Actions/JavaScript/Testing 1 2 3', 'cmd-opt-ctrl-h', function() { | |
if (win === undefined) { | |
win = new Window(); | |
win.htmlPath = 'default.html'; | |
win.onUnload = function() { | |
Alert.show('debug', 'onUnload', ['OK']); | |
win = undefined; | |
}; | |
win.buttons = ["OK"]; | |
win.onButtonClick = function() { | |
// Note: onUnload will be fired. | |
win.close(); | |
}; | |
win.run(); | |
} else { | |
// this may work one or two times, but then it will fail | |
win.show(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also,
win.isVisible()
will eventually returnfalse
but callingwin.show()
does not show it. Because the window has been deallocated?