-
Notifications
You must be signed in to change notification settings - Fork 391
Update to promise api for some methods in the electron API #2626
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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:
- Using
async
/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 of
showOpenDialog
has changed.
lib/views/directory-select.js
Outdated
this.props.showOpenDialog(this.props.currentWindow, { | ||
defaultPath: this.props.buffer.getText(), | ||
properties: ['openDirectory', 'createDirectory', 'promptToCreate'], | ||
}, filePaths => { | ||
if (filePaths !== undefined) { | ||
}).then(({filePaths}) => { |
There was a problem hiding this comment.
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 the async
/await
style to call the Promise-based APIs here for consistency, if you don't mind 🙇🏻 .
Also, it looks like the return value of showOpenDialog
has changed, too; it now returns an Object
with certain properties:
So I think this call would be something like:
chooseDirectory = async () => {
const {canceled, filePaths} = await this.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 🤔
There was a problem hiding this comment.
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.
@@ -47,7 +47,7 @@ describe('DirectorySelect', function() { | |||
|
|||
describe('clicking the directory button', function() { | |||
it('populates the destination path buffer on accept', async function() { | |||
const showOpenDialog = sinon.stub().callsArgWith(2, ['/some/directory/path']); | |||
const showOpenDialog = sinon.stub().returns(Promise.resolve({filePaths: ['/some/directory/path']})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Perfect.
@@ -167,7 +167,7 @@ describe('WorkerManager', function() { | |||
}); | |||
`; | |||
|
|||
await new Promise(resolve => browserWindow.webContents.executeJavaScript(script, resolve)); | |||
await browserWindow.webContents.executeJavaScript(script); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇🏻
i ll get to requested changes soon |
@smashwilson if atom 1.55 is based on electron 6 those api change will work. |
Looks like Atom 1.55 uses Electron 6.1.12: https://github.com/atom/atom/blob/24274440ec3e9c296a20daa3ad72aa57c074024a/package.json#L15 And here are the So you're correct, looks like we're good 👍🏻 |
if (filePaths.length) { | ||
this.props.buffer.setText(filePaths[0]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Perfect!
lib/views/git-timings-view.js
Outdated
buffer.saveAs(filename); | ||
}).then(({filePath}) => { | ||
if (!filePath) { return; } | ||
buffer.saveAs(filePath); |
There was a problem hiding this comment.
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?
lib/views/git-timings-view.js
Outdated
}, async filenames => { | ||
if (!filenames) { return; } | ||
const filename = filenames[0]; | ||
}).then(async ({filePaths}) => { |
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
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.
There was a problem hiding this 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 🍏
Is it possible to get a new version published? what is your procedure around that? |
Ah, to make it easier to move forward the Electron upgrade work? Sure, I can do that:
|
thanks @smashwilson appreciated |
Please be sure to read the contributor's guide to the GitHub package before submitting any pull requests.
Requirements
Description of the Change
This PR aims at using the promise version of
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