Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron file dialog calling convention changed? #149

Closed
scripting opened this issue Jan 31, 2020 · 3 comments
Closed

Electron file dialog calling convention changed? #149

scripting opened this issue Jan 31, 2020 · 3 comments

Comments

@scripting
Copy link
Owner

@scripting scripting commented Jan 31, 2020

Electron problem. It appears they changed how a core routine works, the one that opens a file dialog. I'm trying to figure out how the changed version works.

The routine is: electron.remote.dialog.showSaveDialog.

Here's how I currently call it in all my apps.

function shellNewFileDialog (callback) {
	var options = {
		title: "Name of the new file?",
		filters: [
			{name: 'text', extensions: config.acceptableFileExtensions}
			]
		};
	electron.remote.dialog.showSaveDialog (options, function (f) {
		if (f !== undefined) {
			console.log ("shellNewFileDialog: theFile == " + f);
			if (callback !== undefined) {
				callback (f);
				}
			}
		}); 
	}

What I expect to happen: The dialog opens, I navigate to or create a folder, enter a filename, click OK and the callback is called with the path to the file I chose.,

What happens: The callback is not called.

The theory -- they appear to have changed this to be a synchronous routine? Half the howtos on the web say do it this way, the other half say that dialog.showSaveDialog just returns the file path.

I recently upgraded the version of Electron I'm using, so am finding breakage scattered all over the place.

@tedchoward

This comment has been minimized.

Copy link

@tedchoward tedchoward commented Jan 31, 2020

It looks like they changed the API in version 6: https://www.electronjs.org/releases/stable?version=6&page=5#release-notes-for-600

It no longer takes a callback, instead it returns a promise.

@scripting

This comment has been minimized.

Copy link
Owner Author

@scripting scripting commented Jan 31, 2020

@tedchoward -- thanks.

I've been cleaning up stuff like this related to all the external toolkits I use.

@scripting

This comment has been minimized.

Copy link
Owner Author

@scripting scripting commented Jan 31, 2020

I made the changes, and they work.

This is what the routine above became.

function shellNewFileDialog (callback) {
	var options = {
		title: "Name of the new file?",
		filters: [
			{name: 'text', extensions: config.acceptableFileExtensions}
			]
		};
	var f = electron.remote.dialog.showSaveDialogSync (options); //1/31/20 by DW
	if (f !== undefined) {
		console.log ("shellNewFileDialogSync: f == " + f);
		if (callback !== undefined) {
			callback (f);
			}
		}
	}

@scripting scripting closed this Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.