Add window close event handler