fix(feedback): Move feedback window creation to app process

Prevents cross-window callbacks that are preventing the app from quitting
This commit is contained in:
Ben Gotow 2015-11-09 12:14:33 -08:00
parent 369c5049a7
commit 1b85eb55ef
4 changed files with 62 additions and 53 deletions

View file

@ -34,64 +34,32 @@ class FeedbackButton extends React.Component
_onSendFeedback: =>
return if atom.inSpecMode()
BrowserWindow = require('remote').require('browser-window')
Screen = require('remote').require('screen')
path = require 'path'
qs = require 'querystring'
@setState(newMessages: false)
account = AccountStore.current()
params = qs.stringify({
name: account.name
email: account.emailAddress
accountId: account.id
accountProvider: account.provider
platform: process.platform
provider: account.displayProvider()
organizational_unit: account.organizationUnit
version: atom.getVersion()
})
if window.feedbackWindow?
window.feedbackWindow.show()
else
parentBounds = atom.getCurrentWindow().getBounds()
parentScreen = Screen.getDisplayMatching(parentBounds)
account = AccountStore.current()
params = qs.stringify({
name: account.name
email: account.emailAddress
accountId: account.id
accountProvider: account.provider
platform: process.platform
provider: account.displayProvider()
organizational_unit: account.organizationUnit
version: atom.getVersion()
})
width = 376
height = Math.min(550, parentBounds.height)
x = Math.min(parentScreen.workAreaSize.width - width, Math.max(0, parentBounds.x + parentBounds.width - 36 - width / 2))
y = Math.max(0, (parentBounds.y + parentBounds.height) - height - 60)
parentBounds = atom.getCurrentWindow().getBounds()
parentScreen = Screen.getDisplayMatching(parentBounds)
width = 376
height = Math.min(550, parentBounds.height)
x = Math.min(parentScreen.workAreaSize.width - width, Math.max(0, parentBounds.x + parentBounds.width - 36 - width / 2))
y = Math.max(0, (parentBounds.y + parentBounds.height) - height - 60)
window.feedbackWindow = w = new BrowserWindow
'node-integration': false,
'web-preferences': {'web-security':false},
'x': x
'y': y
'width': width,
'height': height,
'title': 'Feedback'
onOpenURL = (event, href) ->
shell = require 'shell'
shell.openExternal(href)
event.preventDefault()
# Disable window close, hide instead
w.on 'close', (event) ->
# inside the window we prevent close - here we route close to hide
event.preventDefault() # this does nothing, contrary to the docs
w.hide()
w.on 'closed', (event) ->
# if the window does get closed, clear our ref to it
window.feedbackWindow = null
w.webContents.on('new-window', onOpenURL)
w.webContents.on('will-navigate', onOpenURL)
url = path.join __dirname, '..', 'feedback.html'
w.loadUrl("file://#{url}?#{params}")
w.show()
require('ipc').send('show-feedback-window', { x, y, width, height, params })
setTimeout =>
@setState(newMessages: false)
, 250
module.exports = FeedbackButton

View file

@ -313,6 +313,9 @@ class Application
ipc.on 'new-window', (event, options) =>
@windowManager.newWindow(options)
ipc.on 'show-feedback-window', (event, options) =>
@windowManager.showFeedbackWindow(options)
ipc.on 'register-hot-window', (event, options) =>
@windowManager.registerHotWindow(options)

View file

@ -153,6 +153,44 @@ class WindowManager
@newWindow(options)
###
Feedback window
###
showFeedbackWindow: ({x, y, width, height, params}) ->
if @feedbackWindow
@feedbackWindow.show()
else
@feedbackWindow = w = new BrowserWindow
'node-integration': false,
'web-preferences': {'web-security':false},
'x': x
'y': y
'width': width,
'height': height,
'title': 'Feedback'
onOpenURL = (event, href) ->
shell = require 'shell'
shell.openExternal(href)
event.preventDefault()
# Disable window close, hide instead
w.on 'close', (event) ->
unless global.application.quitting
event.preventDefault()
w.hide()
w.on 'closed', (event) ->
@feedbackWindow = null
w.webContents.on('new-window', onOpenURL)
w.webContents.on('will-navigate', onOpenURL)
url = require('path').join(@resourcePath, 'static', 'feedback.html')
w.loadUrl("file://#{url}?#{params}")
w.show()
# Makes a new window appear of a certain `windowType`.
#
# In almost all cases, instead of booting up a new window from scratch,