mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-23 07:36:12 +08:00
Summary: Fixes T3568 The composer windows had the wrong cache in their `ContactStore`s. Since it's VERY expensive to repopulate a ContactStore's cache, we now have a `WindowBridge` that allow you to, with a Promise, invoke methods on the main window instead. (Still need to fix some tests) Test Plan: Fixed tests Reviewers: dillon, bengotow Reviewed By: dillon, bengotow Maniphest Tasks: T3568 Differential Revision: https://phab.nylas.com/D2045
43 lines
1.4 KiB
CoffeeScript
43 lines
1.4 KiB
CoffeeScript
_ = require 'underscore'
|
|
ipc = require 'ipc'
|
|
Utils = require './flux/models/utils'
|
|
|
|
class WindowBridge
|
|
constructor: ->
|
|
@_tasks = {}
|
|
ipc.on("remote-run-results", @_onResults)
|
|
ipc.on("run-in-window", @_onRunInWindow)
|
|
|
|
runInWindow: (window, objectName, methodName, args) ->
|
|
taskId = Utils.generateTempId()
|
|
new Promise (resolve, reject) =>
|
|
@_tasks[taskId] = {resolve, reject}
|
|
args = Utils.serializeRegisteredObjects(args)
|
|
params = {window, objectName, methodName, args, taskId}
|
|
ipc.send("run-in-window", params)
|
|
|
|
runInMainWindow: (args...) ->
|
|
@runInWindow("main", args...)
|
|
|
|
runInWorkWindow: ->
|
|
@runInWindow("work", args...)
|
|
|
|
_onResults: ({returnValue, taskId}={}) =>
|
|
returnValue = Utils.deserializeRegisteredObjects(returnValue)
|
|
@_tasks[taskId].resolve(returnValue)
|
|
delete @_tasks[taskId]
|
|
|
|
_onRunInWindow: ({objectName, methodName, args, taskId}={}) =>
|
|
args = Utils.deserializeRegisteredObjects(args)
|
|
exports = require 'nylas-exports'
|
|
result = exports[objectName][methodName].apply(null, args)
|
|
if _.isFunction(result.then)
|
|
result.then (returnValue) ->
|
|
returnValue = Utils.serializeRegisteredObjects(returnValue)
|
|
ipc.send('remote-run-results', {returnValue, taskId})
|
|
else
|
|
returnValue = result
|
|
returnValue = Utils.serializeRegisteredObjects(returnValue)
|
|
ipc.send('remote-run-results', {returnValue, taskId})
|
|
|
|
module.exports = new WindowBridge
|