I found this post while searching through the past Forum and it solved this problem for me!
I inherited the juce::Timer class from PluginWindow and implemented timerCallback() as follows.
void timerCallback() override {
if (Process::isForegroundProcess()) {
if (!isAlwaysOnTop()) {
setAlwaysOnTop(true);
setVisible(true);
}
} else {
if (isAlwaysOnTop()) {
setAlwaysOnTop(false);
setVisible(false);
}
}
}