Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
/githubPublic archive

Update to promise api for some methods in the electron API#2626

Merged
smashwilson merged 6 commits intoatom:masterfromasturur:promisification
Feb 14, 2021

Conversation

asturur
Copy link
Contributor

Please be sure to read thecontributor's guide to the GitHub package before submitting any pull requests.

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.

Description of the Change

This PR aims at using the promise version of

  • showSaveDialog,
  • showOpenDialog,
  • executeJavascript

electron API

In order to ease the upgrade path to newer versions of electron where the callback is no more supported.

Screenshot or Gif

Applicable Issues

@codecov
Copy link

codecovbot commentedFeb 13, 2021
edited
Loading

Codecov Report

Merging#2626 (44d5d86) intomaster (8c07644) willdecrease coverage by0.00%.
The diff coverage is100.00%.

Impacted file tree graph

@@            Coverage Diff             @@##           master    #2626      +/-   ##==========================================- Coverage   93.46%   93.46%   -0.01%==========================================  Files         237      237                Lines       13215    13213       -2       Branches     1900     1900              ==========================================- Hits        12352    12349       -3- Misses        863      864       +1
Impacted FilesCoverage Δ
lib/views/directory-select.js100.00% <100.00%> (ø)
lib/atom/gutter.js90.47% <0.00%> (-2.39%)⬇️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update8c07644...44d5d86. Read thecomment docs.

Copy link
Contributor

@smashwilsonsmashwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for tackling this! I'll be happy to merge if we can resolve:

  • Usingasync/await instead of.then (which is just a style/consistency thing), and
  • Confirming that this will still work against Atom 1.55, or finding a way to bridge the Electron API gap, since the return value ofshowOpenDialog has changed.

properties:['openDirectory','createDirectory','promptToCreate'],
},filePaths=>{
if(filePaths!==undefined){
}).then(({filePaths})=>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think I'd prefer to use theasync/await style to call the Promise-based APIs here for consistency, if you don't mind 🙇🏻 .

Also, it looks like the return value ofshowOpenDialog has changed, too; it now returns anObject with certain properties:

https://github.com/electron/electron/blob/v9.4.3/docs/api/dialog.md#dialogshowopendialogbrowserwindow-options

So I think this call would be something like:

chooseDirectory=async()=>{const{canceled, filePaths}=awaitthis.props.showOpenDialog(this.props.currentWindow,{defaultPath:this.props.buffer.getText(),properties:['openDirectory','createDirectory','promptToCreate'],};if(!canceled&&filePaths.length>0){this.props.buffer.setText(filePaths[0]);}}

But, we have to make sure that the different return value is compatible with the call signature on the Electron versions back to Atom 1.55 (the current beta), too, so we don't break our ability to backport 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hah! I totally missed at first read that you'd already added the{filePaths} destructuring in your.then callback argument.

describe('clicking the directory button',function(){
it('populates the destination path buffer on accept',asyncfunction(){
constshowOpenDialog=sinon.stub().callsArgWith(2,['/some/directory/path']);
constshowOpenDialog=sinon.stub().returns(Promise.resolve({filePaths:['/some/directory/path']}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍 Perfect.

`;

awaitnewPromise(resolve=>browserWindow.webContents.executeJavaScript(script,resolve));
awaitbrowserWindow.webContents.executeJavaScript(script);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🙇🏻

@asturur
Copy link
ContributorAuthor

i ll get to requested changes soon

smashwilson reacted with thumbs up emoji

@asturur
Copy link
ContributorAuthor

@smashwilson if atom 1.55 is based on electron 6 those api change will work.
The callback was removed from documentation on electron 6 and still supported, but this promise API has been introduced in 6.0

@smashwilson
Copy link
Contributor

Looks like Atom 1.55 uses Electron 6.1.12:

https://github.com/atom/atom/blob/24274440ec3e9c296a20daa3ad72aa57c074024a/package.json#L15

And here are theshowOpenDialog docs for that version:

https://github.com/electron/electron/blob/v6.1.12/docs/api/dialog.md#dialogshowopendialogbrowserwindow-options

So you're correct, looks like we're good 👍🏻

if(filePaths.length){
this.props.buffer.setText(filePaths[0]);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍 Perfect!

buffer.saveAs(filename);
}).then(({filePath})=>{
if(!filePath){return;}
buffer.saveAs(filePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can we use async/await here too?

},asyncfilenames=>{
if(!filenames){return;}
constfilename=filenames[0];
}).then(async({filePaths})=>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

And here ☝🏻

Sorry, should have clarified that I meant at all three callsites on the first review 👀

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

oh ok no issue, i can convert them, i m still here.

Copy link
Contributor

@smashwilsonsmashwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Excellent, thank you. Will merge when builds are green 🍏

@smashwilsonsmashwilson merged commitb4896c9 intoatom:masterFeb 14, 2021
@asturur
Copy link
ContributorAuthor

Is it possible to get a new version published? what is your procedure around that?

@smashwilson
Copy link
Contributor

Ah, to make it easier to move forward the Electron upgrade work? Sure, I can do that:

atom-github ➤ apm publish patchPreparing and tagging a new version ✓Pushing v0.36.8 tag ✓Publishing github@v0.36.8 ✓
DeeDeeG reacted with hooray emoji

@asturur
Copy link
ContributorAuthor

thanks@smashwilson appreciated

DeeDeeG reacted with hooray emoji

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
1 more reviewer

@smashwilsonsmashwilsonsmashwilson approved these changes

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@asturur@smashwilson

[8]ページ先頭

©2009-2025 Movatter.jp