Skip to content

Commit

Permalink
Add AtomEnvironment.prototype.resolveProxy(url)
Browse files Browse the repository at this point in the history
This new private API will allow settings-view to communicate
asynchronously with the main process to resolve proxies, instead of
using `remote` and blocking the renderer process during startup.
  • Loading branch information
Antonio Scandurra committed Mar 10, 2017
1 parent 11961b0 commit 1e040c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/application-delegate.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,14 @@ class ApplicationDelegate

emitDidSavePath: (path) ->
ipcRenderer.sendSync('did-save-path', path)

resolveProxy: (requestId, url) ->
ipcRenderer.send('resolve-proxy', requestId, url)

onDidResolveProxy: (callback) ->
outerCallback = (event, requestId, proxy) ->
callback(requestId, proxy)

ipcRenderer.on('did-resolve-proxy', outerCallback)
new Disposable ->
ipcRenderer.removeListener('did-resolve-proxy', outerCallback)
11 changes: 11 additions & 0 deletions src/atom-environment.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class AtomEnvironment extends Model
constructor: (params={}) ->
{@blobStore, @applicationDelegate, @window, @document, @clipboard, @configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params

@nextProxyRequestId = 0
@unloaded = false
@loadTime = null
{devMode, safeMode, resourcePath, clearWindowState} = @getLoadSettings()
Expand Down Expand Up @@ -993,6 +994,16 @@ class AtomEnvironment extends Model

return

resolveProxy: (url) ->
return new Promise (resolve, reject) =>
requestId = @nextProxyRequestId++
disposable = @applicationDelegate.onDidResolveProxy (id, proxy) =>
if id is requestId
disposable.dispose()
resolve(proxy)

@applicationDelegate.resolveProxy(requestId, url)

# Preserve this deprecation until 2.0. Sorry. Should have removed Q sooner.
Promise.prototype.done = (callback) ->
deprecate("Atom now uses ES6 Promises instead of Q. Call promise.then instead of promise.done")
Expand Down
3 changes: 3 additions & 0 deletions src/main-process/atom-application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ class AtomApplication
@disposable.add ipcHelpers.on ipcMain, 'restart-application', =>
@restart()

@disposable.add ipcHelpers.on ipcMain, 'resolve-proxy', (event, requestId, url) ->
event.sender.session.resolveProxy url, (proxy) -> event.sender.send('did-resolve-proxy', requestId, proxy)

@disposable.add ipcHelpers.on ipcMain, 'did-change-history-manager', (event) =>
for atomWindow in @windows
webContents = atomWindow.browserWindow.webContents
Expand Down

0 comments on commit 1e040c6

Please sign in to comment.