diff --git a/internal_packages/feedback/lib/feedback-button.cjsx b/internal_packages/feedback/lib/feedback-button.cjsx index 3a0faa4a5..0be1bee3a 100644 --- a/internal_packages/feedback/lib/feedback-button.cjsx +++ b/internal_packages/feedback/lib/feedback-button.cjsx @@ -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 diff --git a/src/browser/application.coffee b/src/browser/application.coffee index 650317ea1..831dbf83f 100644 --- a/src/browser/application.coffee +++ b/src/browser/application.coffee @@ -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) diff --git a/src/browser/window-manager.coffee b/src/browser/window-manager.coffee index 5f865a51c..f8b110219 100644 --- a/src/browser/window-manager.coffee +++ b/src/browser/window-manager.coffee @@ -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, diff --git a/internal_packages/feedback/feedback.html b/static/feedback.html similarity index 100% rename from internal_packages/feedback/feedback.html rename to static/feedback.html