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

how to use dialog? #314

Open
cosse opened this issue Mar 24, 2021 · 7 comments
Open

how to use dialog? #314

cosse opened this issue Mar 24, 2021 · 7 comments
Assignees

Comments

@cosse
Copy link

cosse commented Mar 24, 2021

I see a lot of issues solved with Dialog,
But when I try const {dialog} = require('electron').remote; in main.js ,
It will prompt me TypeError: fs.existsSync is not a function,
Where is the correct quote.
Thanks.

@asticode
Copy link
Owner

It seems like remote module has been removed from newer version of Electron therefore it's not available anymore in JS scripts. And therefore dialog is not available using this method anymore.

I won't have time to work on this change anytime soon, so if somebody feels like contributing, I'm welcoming PRs.

@Yukaru-san
Copy link

Fixing this problem should be as easy as adding
require('@electron/remote/main').initialize()
to the underlying index.js from astilectron.

This is caused by a breaking change from electron.

By the way:
const { BrowserWindow } = require('electron').remote
became something like
const { BrowserWindow } = require('@electron/remote')

I did test this but since I don't know how you handle external libraries I didn't create a pull request. I hope this makes it easier to implement a fix for this problem though.

For future references:
Here you can find the The remote's Github repository which needs to be implemented and electron's list of breaking changes

@OneManMonkeySquad
Copy link

npm install --save @electron/remote

vendor/astilectron/index.js

// After the last require (line 10 or so):
const remoteMain = require('@electron/remote/main')
remoteMain.initialize();

...

// Need to change window creation (search for windowCreate):
function windowCreate(json) {
    if (!json.windowOptions.webPreferences) {
        json.windowOptions.webPreferences = {}
    }
    json.windowOptions.webPreferences.contextIsolation = false
    json.windowOptions.webPreferences.nodeIntegration = true
    let window = new BrowserWindow(json.windowOptions)
    elements[json.targetID] = window
    windowOptions[json.targetID] = json.windowOptions

    remoteMain.enable(window.webContents); // <------- this is the relevant change; note you need to change the let window = also

yourcode.js

const { dialog } = require('@electron/remote')

function PickInstallationFolder() {
            dialog.showOpenDialog({
                title: "Installation Path",
                properties: ['openDirectory']
            });
        }

@ThePutzy
Copy link

ThePutzy commented Jul 4, 2022

Hi,
i tried many ways, but it is not possible to get "dialog" running.

i'm using

VersionAstilectron = "0.56.0"
VersionElectron    = "11.4.3"

Is there currently a possibility to use dialog?

@thomas-lud
Copy link

Hi @ThePutzy
I currently use the file dialog with the following settings:

VersionElectron:    "11.1.0",
VersionAstilectron: "0.47.0",

and in the JS I have
const { dialog } = require('electron').remote

@wlwatkins
Copy link

@thomas-lud I tried with these versions declared in astilectron.Now but I still get
Cannot read property 'dialog' of undefined at index.dev.js:3 Has this been fixed?

@wlwatkins
Copy link

I think i have a fix for the current versions

Astilectron has already been provisioned to version 0.55.0
Electron has already been provisioned to version 11.4.3

as describe here https://stackoverflow.com/a/37893140/8571243 one must set enableRemoteModule: true in electronJS.
Thankfully, @asticode has implemented this possibility, hence

w, err = a.NewWindow("dist/index.html", &astilectron.WindowOptions{
                //......
		Width:          astikit.IntPtr(1500),
		Height:         astikit.IntPtr(800),
		WebPreferences: &astilectron.WebPreferences{EnableRemoteModule: astikit.BoolPtr(true)},
	})
```  and now this works for me

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

No branches or pull requests

7 participants