Is there a way to disable Maximize on an EditorWindow?

I have a main EditorWindow that can open other EditorWindows as tool windows. The main EditorWindow closes the tool windows in OnDestroy. So far so good.

The problem is OnDestroy is called on tabbed windows when another window in the tab group is maximized. So if the main window is in a tab group with a tool window, and you maximize the tool window (by hitting space, or selecting maximize in the tab menu), then the main window tries to close the tool window that is maximizing, and it crashes Unity!

I’m checking for null window references, but I think everything happening at once causes the crash…

So, my question is this: Is there a way to disable Maximize on an EditorWindow? Or is anyone aware of some clever workaround for this problem? I’ve tried maxSize to no avail.

you can limit max and min-width or height via Init method this will automatically disable maximizing button

 var window = GetWindow<awd>("Window");
        window.maxSize = new Vector2(279, 279);
        window.minSize = new Vector2(279, 219);