Fullscreen to Maximize on MacOS

I’m creating some custom MacOS ‘Traffic Lights’ for my React/Electron App. I’ve managed to get the Close and Minimize buttons to work perfectly fine, however, my Maximize (green) button will go fullscreen but when its clicked again it will not return to normal.

Here is my code for the functions that are called to the buttons: https://sourceb.in/8f930dc034.js

Any help or advice would be much appreciated.