asticode/go-astilectron

Conditional MessageBoxOnClose

Opened this issue · 3 comments

currently i am using the MessageBoxOnClose option to trigger a confirmation before closing the application but was wondering if there are a way to dynamically hide the MessageBoxOnClose depending on the state of the application?

FYI the implementation is located here and you can't disable/enable MessageBoxOnClose dynamically

I've ran into an instance where I need to change MessageBoxOnClose dynamically. I'm happy to try to implement this functionality, but I need a bit of guidance on the preferred solution.

One solution I see is to implement a Go based e.PreventDefault as mentioned in #48. Another solution could be to allow users to intercept a close event so they can run their own handler.

I'm not too sure what would be best, as I haven't dug into astilectron's architecture`, have you got any suggestions?

I would do it like this:

  1. Add func(w *Window) UpdateCustomOptions(o WindowCustomOptions) in GO that would send an event window.cmd.update.custom.options to JS with the new options
  2. In JS, store the content of json in a global variable here (same idea as elements variable)
  3. Stop relying on the json local variable here, but rely on the global variable created previously instead
  4. Listen to the new event in JS, and update the global variable accordingly. That way, when the close event is fired, it takes the last MessageBoxOnClose option