SwiftExpat / Deputy

Deputy - Delphi IDE Expert
GNU General Public License v3.0
13 stars 3 forks source link

OPTION to close window instead of killing the process #1

Closed PeterPanino closed 2 years ago

PeterPanino commented 2 years ago

Instead of killing the process, there should be an option to CLOSE ITS MAIN WINDOW.

SwiftExpat commented 2 years ago

Would closing its main window call free on some object (database connection)? What would be the minimal working sample?

@PeterPanino is there a api call that you would suggest?

PeterPanino commented 2 years ago

Well, there's the CloseWindow API call in Winapi.Windows.

AFAIK, CloseWindow indeed calls Free on all objects owned by the main window and thus by the process.

BTW, thanks for Deputy. I have long wished for such an expert.

PeterPanino commented 2 years ago

To get the main window handle, there are different solutions:

  1. The app could simply store the value of its Form.Handle in a public variable accessible by Deputy.
  2. A way that is more tricky: Get the window handle - look at OpenProcess
SwiftExpat commented 2 years ago

I will try to work up something using EnumWindows, QuickLib from Exilon has at least a starting point in QuickLib.Process, but on first try that did not work.

I modified my VCL demo output a debug string on datamodule destroy and form destroy. That should confirm that the destructors get called.

Do you have a splash screen that stays open or just a child form(s)?

SwiftExpat commented 2 years ago

@PeterPanino I believe the logic for identifying the main form is complete, can you give it a try against your application and verify that it closes correctly? There is a video and tool here: https://github.com/SwiftExpat/Deputy/releases/tag/2.4.5

Just run ProcTreeVCL and edit the text box to your app name. The code essentially finds the window and publishes wm_close but you can review it here: https://github.com/SwiftExpat/Deputy/tree/main/DevTools/ProcTreeVCL

SwiftExpat commented 2 years ago

On the terminate logic, how long should Deputy wait for the app to close? I am thinking wait a few seconds, configurable, then if the app does not close, terminate it. Or message with a notification and stop the build in the IDE.

SwiftExpat commented 2 years ago

If the app is running with report memory on shutdown, Deputy should watch for that window. Options could be:

  1. terminate on window showing (Sometimes the leak report is very slow, whats the best case to re-produce)
  2. cancel the build / run and let the user deal with the app.
SwiftExpat commented 2 years ago

Most of the close and poll for mem leak is done. The logic still needs a global timeout to ensure the IDE returns at some point.

SwiftExpat commented 2 years ago

2.5.1 addresses close functionality. Go to Tools, SE Deputy, Kill process settings. image

You can choose to terminate or close, and then choose your actions for the memory leak window, close and optionally copy the memory leak