Skip to content

Commit 5f178b0

Browse files
committed
update dialog.showOpenDialog to promisified
1 parent 8b6460d commit 5f178b0

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

packages/server/lib/gui/dialog.coffee

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ module.exports = {
1515
properties: ["openDirectory"]
1616
}
1717

18-
new Promise (resolve, reject) ->
19-
dialog.showOpenDialog props, (paths = []) ->
20-
process.nextTick ->
21-
## return the first path since there can only ever
22-
## be a single directory selection
23-
resolve(paths[0])
18+
dialog.showOpenDialog(props)
19+
.then ({ filePaths }) ->
20+
return filePaths[0]
2421
}

packages/server/test/unit/gui/dialog_spec.coffee

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Windows = require("#{root}../lib/gui/windows")
77
describe "gui/dialog", ->
88
context ".show", ->
99
beforeEach ->
10-
@showOpenDialog = electron.dialog.showOpenDialog = sinon.stub()
10+
@showOpenDialog = electron.dialog.showOpenDialog = sinon.stub().resolves({
11+
filePaths: []
12+
})
1113

1214
it "calls dialog.showOpenDialog with args", ->
1315
dialog.show()
@@ -16,13 +18,13 @@ describe "gui/dialog", ->
1618
})
1719

1820
it "resolves with first path", ->
19-
@showOpenDialog.yields(["foo", "bar"])
21+
@showOpenDialog.resolves({
22+
filePaths: ["foo", "bar"]
23+
})
2024

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

2428
it "handles null paths", ->
25-
@showOpenDialog.yields(null)
26-
2729
dialog.show().then (ret) ->
2830
expect(ret).to.eq(undefined)

0 commit comments

Comments
 (0)