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

Exposing Dialog #64

Closed
rkrasnan opened this issue Feb 22, 2023 · 7 comments
Closed

Exposing Dialog #64

rkrasnan opened this issue Feb 22, 2023 · 7 comments

Comments

@rkrasnan
Copy link

I have edited my vendor/astilectron/index.js code to expose the dialog via the astilectron object.

Starting on line 536

  `const {ipcRenderer} = require('electron');
  const {dialog} = require('electron').remote;
  var astilectron = {
    dialog: dialog,
    onMessageOnce: false,
    ...
  };
  ...

This made it so I could extend vue/src/plugins/astor.js and further expose the dialog to the rest of my app.

Is this a good way to get access to the dialog object?

@asticode
Copy link
Owner

That could be one way to do it. Are dialogs working properly?

@rkrasnan
Copy link
Author

Yes I am able to access the dialog inside of my vue app and it works properly.

I also have the EnabledRemoteModule flagged as true from here asticode/go-astilectron#314 (comment)

Adding const {dialog} = require('electron').remote; in my vue app wouldn't compile since electron isn't part of that project.

But index.js was created by the bundler, so this code change will be overwritten every time I build.
Should I open a PR for this change or am I way off base?

@rkrasnan
Copy link
Author

I was able to achieve this without needing to edit the index.js file using the custom.script

in main.go, in the astilectron.WindowOptions

...
Options: &astilectron.WindowOptions{
  ...
  WebPreferences: &astilectron.WebPreferences{EnableRemoteModule: astikit.BoolPtr(true)},
  Custom: &astilectron.WindowCustomOptions{Script: `const {dialog} = require("electron").remote; astilectron.dialog = dialog;`},
},
...

@asticode
Copy link
Owner

I was able to achieve this without needing to edit the index.js file using the custom.script

I love this idea!

Did you really need the astilectron.dialog = dialog; or could you remove it and call dialog.[...] in your javascript instead?

@rkrasnan
Copy link
Author

You are right, I didn't need that part and now I have access to dialog in my vue components.

eslint doesn't like it but the vue app compiles and the dialogs work properly.

@asticode
Copy link
Owner

Thanks a lot for sharing! ❤️

@rkrasnan
Copy link
Author

Thank you for the guidance!

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

No branches or pull requests

2 participants