Skip to content

[Windows] SetPreventClose Prevents close too much :) #356

Open
@GaelHuyghe

Description

@GaelHuyghe

Hi,

I have your plugin in my application.
I have windowManager.setPreventClose(true); in my main.dart

Then I have

@override
  Future<void> onWindowClose() async {
  
    if(await windowManager.isPreventClose())
    {
      logger.info("MainPage", "OnWindowClose called > Hiding...");
      windowManager.hide();
    }
    else
    {
      logger.info("MainPage", "OnWindowClose called > Destroying...");
      windowManager.destroy();
    }
  }

So when the user click on the close button, the ``windowManager.hide()` method is called

So far, so good.

This application is embedded within a .MSI and when I apply an upgrade, the OS can't kill the application.

I'm guessing that the MSI is issuing a WM_CLOSE command to the application, but is then re-routed as a 'Close' event within the WindowManager and I just "hide" the application.

Is there any way to intercept the User action only and let the System one go through ?
(Like having the CloseReason.UserClosing in Winform)

My needs :

  • When the user click the 'x' button > hide
  • When the user alt+f4 the app > hide
  • When the system tries to gracefully close the app > close

I tried fiddling with LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) in win32_window.cpp but to no avail. I don't have any skills in cpp :/

(I think it needs to hide only when message == WM_SYSCOMMAND && wparam == SC_CLOSE instead of WM_CLOSE but again, I'm far from my skills here)

Thanks in advance to whoever can guide me!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions