!7

cmodule MinimizeToTray > DynPrintLogAndEnabled {
  transient bool activating;
  
  start {
    JFrame f = getFrame(dm_desktopPane());
    if (f == null) print("No frame found");
    else {
      var action = r {
        if (!activating)
          if (enabled)
            f.setVisible(false);
      };
      ownResource(tempOnFrameIconified(f, action));
      
      if (isInIconifiedFrame(f))
        if (enabled)
          f.setVisible(false);
        
      print("Minimize to tray installed");
    }

    Runnable rShow = r {
      activating = true;
      try {
        activateFrame(dm_desktopPane(), windowsHack := false);
      } finally {
        activating = false;
      }
    };
    S name = dm_osName();
    dm_systemTrayIcon(dm_osIconID(), name, rShow, "Show " + name, rShow);
  }
  
  bool warnOnDelete() { true; }
}