Autohotkey won't restore/activate a minimized window

Which OS are you on? Your code works for me on Win10 if I add the ahk_class to the title:

If WinExist("Calculator ahk_class ApplicationFrameWindow") 
{
    ;MsgBox Calculator Exists.
    IfWinActive
        WinClose
    Else
    {
        WinGet, winState, MinMax
        If (winState = -1)
        {
            WinRestore
            WinActivate
        }
    }
}
Else 
{
    run calc
    WinWait, Calculator
    WinActivate
}

This is what I got to work for me.

;------hotkey to open/close explorer------
^LWin:: ;control and leftwindows
if WinExist("ahk_class ActualTools_TabbedExplorerContainerWindow"){ ; if the window exists
    if WinActive("ahk_class ActualTools_TabbedExplorerContainerWindow") or WinActive("ahk_exe Explorer.EXE")
        WinMinimize, ahk_class ActualTools_TabbedExplorerContainerWindow 
    else{
        WinActivate ; otherwise make it the active window
    }
}else
    run, explorer.exe ;otherwise not open, open explorer
return

I use to use:

;------hotkey to open/close explorer------
^LWin:: ;control and leftwindows
;WinGetClass, Clipboard, A ;Use this to get the name(class?) of the window you want the script to open. https://stackoverflow.com/questions/45642727/what-is-ahk-class-how-can-i-use-it-for-window-matching
if WinExist("ahk_class ActualTools_TabbedExplorerContainerWindow"){ ; if the window exists
        WinGet, state, MinMax ;get the state of the window. is it maximized or minimized. this could be part of the issue
        If state >= 0 ; if its not minimized, minimize it
            WinMinimize
        else
            WinActivate ; otherwise make it the active window
}else
    Run, Explorer.exe ;otherwise not open, open explorer
return

But this solution required for me to often have to hit the hotkey twice. Once to make it active(if it wasnt top most, even it is still seeable) and then again to minimize it. Hope this helps someone.