Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 8c07644

Browse files
authored
Merge pull request #2625 from atom/update-electron-apis
Update shell.openExternal to promise due to electron update on atom
2 parents 044931d + 4ab44f3 commit 8c07644

9 files changed

+31
-70
lines changed

lib/controllers/issueish-list-controller.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,9 @@ export class BareIssueishListController extends React.Component {
9090
return null;
9191
}
9292

93-
openOnGitHub = url => {
94-
return new Promise((resolve, reject) => {
95-
shell.openExternal(url, {}, err => {
96-
if (err) { reject(err); } else {
97-
resolve();
98-
addEvent('open-issueish-in-browser', {package: 'github', component: this.constructor.name});
99-
}
100-
});
101-
});
93+
openOnGitHub = async url => {
94+
await shell.openExternal(url);
95+
addEvent('open-issueish-in-browser', {package: 'github', component: this.constructor.name});
10296
}
10397

10498
showActionsMenu = /* istanbul ignore next */ issueish => {

lib/controllers/issueish-searches-controller.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,8 @@ export default class IssueishSearchesController extends React.Component {
113113
});
114114
}
115115

116-
onOpenSearch = search => {
116+
onOpenSearch = async search => {
117117
const searchURL = search.getWebURL(this.props.remote);
118-
119-
return new Promise((resolve, reject) => {
120-
shell.openExternal(searchURL, {}, err => {
121-
if (err) { reject(err); } else { resolve(); }
122-
});
123-
});
118+
await shell.openExternal(searchURL);
124119
}
125120
}

lib/controllers/remote-controller.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ export default class RemoteController extends React.Component {
6767
createPrUrl += '/compare/' + encodeURIComponent(currentBranch.getName());
6868
createPrUrl += '?expand=1';
6969

70-
return new Promise((resolve, reject) => {
71-
shell.openExternal(createPrUrl, {}, err => {
72-
if (err) {
73-
reject(err);
74-
} else {
75-
incrementCounter('create-pull-request');
76-
resolve();
77-
}
78-
});
79-
});
70+
await shell.openExternal(createPrUrl);
71+
incrementCounter('create-pull-request');
8072
}
8173
}

lib/views/actionable-review-view.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,17 @@ export default class ActionableReviewView extends React.Component {
124124
}
125125
}
126126

127-
reportAbuse = (commentUrl, author) => {
128-
return new Promise((resolve, reject) => {
129-
const url = 'https://github.com/contact/report-content?report=' +
130-
`${encodeURIComponent(author)}&content_url=${encodeURIComponent(commentUrl)}`;
131-
shell.openExternal(url, {}, err => {
132-
if (err) { reject(err); } else {
133-
resolve();
134-
addEvent('report-abuse', {package: 'github', component: this.constructor.name});
135-
}
136-
});
137-
});
127+
reportAbuse = async (commentUrl, author) => {
128+
const url = 'https://github.com/contact/report-content?report=' +
129+
`${encodeURIComponent(author)}&content_url=${encodeURIComponent(commentUrl)}`;
130+
131+
await shell.openExternal(url);
132+
addEvent('report-abuse', {package: 'github', component: this.constructor.name});
138133
}
139134

140-
openOnGitHub = url => {
141-
return new Promise((resolve, reject) => {
142-
shell.openExternal(url, {}, err => {
143-
if (err) { reject(err); } else {
144-
resolve();
145-
addEvent('open-comment-in-browser', {package: 'github', component: this.constructor.name});
146-
}
147-
});
148-
});
135+
openOnGitHub = async url => {
136+
await shell.openExternal(url);
137+
addEvent('open-comment-in-browser', {package: 'github', component: this.constructor.name});
149138
}
150139

151140
showActionsMenu = (event, content, author) => {

lib/views/issueish-link.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,9 @@ export function openIssueishLinkInNewTab(url, options = {}) {
4444
}
4545
}
4646

47-
export function openLinkInBrowser(uri) {
48-
return new Promise((resolve, reject) => {
49-
shell.openExternal(uri, {}, err => {
50-
if (err) {
51-
reject(err);
52-
} else {
53-
addEvent('open-issueish-in-browser', {package: 'github', from: 'issueish-link'});
54-
resolve();
55-
}
56-
});
57-
});
47+
export async function openLinkInBrowser(uri) {
48+
await shell.openExternal(uri);
49+
addEvent('open-issueish-in-browser', {package: 'github', from: 'issueish-link'});
5850
}
5951

6052
function getAtomUriForGithubUrl(githubUrl) {

test/controllers/issueish-list-controller.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ describe('IssueishListController', function() {
9090

9191
it('calls shell.openExternal with specified url', async function() {
9292
const wrapper = shallow(buildApp());
93-
sinon.stub(shell, 'openExternal').callsArg(2);
93+
sinon.stub(shell, 'openExternal').callsFake(() => { });
9494

9595
await wrapper.instance().openOnGitHub(url);
9696
assert.isTrue(shell.openExternal.calledWith(url));
9797
});
9898

9999
it('fires `open-issueish-in-browser` event upon success', async function() {
100100
const wrapper = shallow(buildApp());
101-
sinon.stub(shell, 'openExternal').callsArg(2);
101+
sinon.stub(shell, 'openExternal').callsFake(() => {});
102102
sinon.stub(reporterProxy, 'addEvent');
103103

104104
await wrapper.instance().openOnGitHub(url);
@@ -109,7 +109,7 @@ describe('IssueishListController', function() {
109109

110110
it('handles error when openOnGitHub fails', async function() {
111111
const wrapper = shallow(buildApp());
112-
sinon.stub(shell, 'openExternal').callsArgWith(2, new Error('oh noes'));
112+
sinon.stub(shell, 'openExternal').throws(new Error('oh noes'));
113113
sinon.stub(reporterProxy, 'addEvent');
114114

115115
try {

test/controllers/remote-controller.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('RemoteController', function() {
5252

5353
it('increments a counter when onCreatePr is called', async function() {
5454
const wrapper = shallow(createApp());
55-
sinon.stub(shell, 'openExternal').callsArg(2);
55+
sinon.stub(shell, 'openExternal').callsFake(() => {});
5656
sinon.stub(reporterProxy, 'incrementCounter');
5757

5858
await wrapper.instance().onCreatePr();
@@ -62,7 +62,7 @@ describe('RemoteController', function() {
6262

6363
it('handles error when onCreatePr fails', async function() {
6464
const wrapper = shallow(createApp());
65-
sinon.stub(shell, 'openExternal').callsArgWith(2, new Error('oh noes'));
65+
sinon.stub(shell, 'openExternal').throws(new Error('oh noes'));
6666
sinon.stub(reporterProxy, 'incrementCounter');
6767

6868
try {

test/views/actionable-review-view.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,39 +69,38 @@ describe('ActionableReviewView', function() {
6969
}
7070

7171
it("opens the content object's URL with 'Open on GitHub'", async function() {
72-
sinon.stub(shell, 'openExternal').callsArg(2);
72+
sinon.stub(shell, 'openExternal').callsFake(() => {});
7373

7474
const item = triggerMenu({url: 'https://github.com'}, {}).items.find(i => i.label === 'Open on GitHub');
7575
await item.click();
7676

77-
assert.isTrue(shell.openExternal.calledWith('https://github.com', {}));
77+
assert.isTrue(shell.openExternal.calledWith('https://github.com'));
7878
assert.isTrue(reporterProxy.addEvent.calledWith('open-comment-in-browser'));
7979
});
8080

8181
it("rejects the promise when 'Open on GitHub' fails", async function() {
82-
sinon.stub(shell, 'openExternal').callsArgWith(2, new Error("I don't feel like it"));
82+
sinon.stub(shell, 'openExternal').throws(new Error("I don't feel like it"));
8383

8484
const item = triggerMenu({url: 'https://github.com'}, {}).items.find(i => i.label === 'Open on GitHub');
8585
await assert.isRejected(item.click());
8686
assert.isFalse(reporterProxy.addEvent.called);
8787
});
8888

8989
it('opens a prepopulated abuse-reporting link with "Report abuse"', async function() {
90-
sinon.stub(shell, 'openExternal').callsArg(2);
90+
sinon.stub(shell, 'openExternal').callsFake(() => {});
9191

9292
const item = triggerMenu({url: 'https://github.com/a/b'}, {login: 'tyrion'})
9393
.items.find(i => i.label === 'Report abuse');
9494
await item.click();
9595

9696
assert.isTrue(shell.openExternal.calledWith(
9797
'https://github.com/contact/report-content?report=tyrion&content_url=https%3A%2F%2Fgithub.com%2Fa%2Fb',
98-
{},
9998
));
10099
assert.isTrue(reporterProxy.addEvent.calledWith('report-abuse'));
101100
});
102101

103102
it("rejects the promise when 'Report abuse' fails", async function() {
104-
sinon.stub(shell, 'openExternal').callsArgWith(2, new Error('nah'));
103+
sinon.stub(shell, 'openExternal').throws(new Error('nah'));
105104

106105
const item = triggerMenu({url: 'https://github.com/a/b'}, {login: 'tyrion'})
107106
.items.find(i => i.label === 'Report abuse');

test/views/github-dotcom-markdown.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ describe('GithubDotcomMarkdown', function() {
213213
});
214214

215215
it('records event for opening issueish in browser', async function() {
216-
sinon.stub(shell, 'openExternal').callsArg(2);
216+
sinon.stub(shell, 'openExternal').callsFake(() => {});
217217
sinon.stub(reporterProxy, 'addEvent');
218218

219219
const issueishLink = wrapper.getDOMNode().querySelector('a.issue-link');
@@ -228,7 +228,7 @@ describe('GithubDotcomMarkdown', function() {
228228
});
229229

230230
it('does not record event if opening issueish in browser fails', function() {
231-
sinon.stub(shell, 'openExternal').callsArgWith(2, new Error('oh noes'));
231+
sinon.stub(shell, 'openExternal').throws(new Error('oh noes'));
232232
sinon.stub(reporterProxy, 'addEvent');
233233

234234
// calling `handleClick` directly rather than dispatching event so that we can catch the error thrown and prevent errors in the console

0 commit comments

Comments
 (0)