Skip to content

Commit

Permalink
update dialog.showOpenDialog to promisified
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Aug 2, 2019
1 parent 8b6460d commit 5f178b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 3 additions & 6 deletions packages/server/lib/gui/dialog.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ module.exports = {
properties: ["openDirectory"]
}

new Promise (resolve, reject) ->
dialog.showOpenDialog props, (paths = []) ->
process.nextTick ->
## return the first path since there can only ever
## be a single directory selection
resolve(paths[0])
dialog.showOpenDialog(props)
.then ({ filePaths }) ->
return filePaths[0]
}
10 changes: 6 additions & 4 deletions packages/server/test/unit/gui/dialog_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Windows = require("#{root}../lib/gui/windows")
describe "gui/dialog", ->
context ".show", ->
beforeEach ->
@showOpenDialog = electron.dialog.showOpenDialog = sinon.stub()
@showOpenDialog = electron.dialog.showOpenDialog = sinon.stub().resolves({
filePaths: []
})

it "calls dialog.showOpenDialog with args", ->
dialog.show()
Expand All @@ -16,13 +18,13 @@ describe "gui/dialog", ->
})

it "resolves with first path", ->
@showOpenDialog.yields(["foo", "bar"])
@showOpenDialog.resolves({
filePaths: ["foo", "bar"]
})

dialog.show().then (ret) ->
expect(ret).to.eq("foo")

it "handles null paths", ->
@showOpenDialog.yields(null)

dialog.show().then (ret) ->
expect(ret).to.eq(undefined)

0 comments on commit 5f178b0

Please sign in to comment.