Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Conditional MessageBoxOnClose #297

Open
bennetty opened this issue Dec 21, 2020 · 3 comments
Open

Conditional MessageBoxOnClose #297

bennetty opened this issue Dec 21, 2020 · 3 comments
Assignees
Labels

Comments

@bennetty
Copy link
Contributor

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?

@asticode asticode self-assigned this Dec 22, 2020
@asticode
Copy link
Owner

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

@Joe-Improbable
Copy link
Contributor

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?

@asticode
Copy link
Owner

asticode commented Jan 5, 2021

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

asticode pushed a commit that referenced this issue Jan 12, 2021
* Add UpdateCustomOptions Event

* Added test for custom option event

* Changed from synchronousEvent to write

* update comment

* Changed to synchronousEvent with new event

* changed update to updated
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants