diff --git a/examples/N1-Message-View-on-Github/lib/view-on-github-button.cjsx b/examples/N1-Message-View-on-Github/lib/view-on-github-button.cjsx index 694921260..074b6bbb5 100644 --- a/examples/N1-Message-View-on-Github/lib/view-on-github-button.cjsx +++ b/examples/N1-Message-View-on-Github/lib/view-on-github-button.cjsx @@ -1,4 +1,4 @@ -shell = require 'shell' +{shell} = require 'electron' GithubStore = require './github-store' {React} = require 'nylas-exports' {RetinaImg, KeyCommandsRegion} = require 'nylas-component-kit' diff --git a/examples/N1-Send-Availability/docs/calendar-button.coffee b/examples/N1-Send-Availability/docs/calendar-button.coffee index 44ed89f98..c8dc5f853 100644 --- a/examples/N1-Send-Availability/docs/calendar-button.coffee +++ b/examples/N1-Send-Availability/docs/calendar-button.coffee @@ -12,15 +12,16 @@ class CalendarButton extends React.Component _onClick: => BrowserWindow = require('remote').require('browser-window') w = new BrowserWindow - 'node-integration': false, - 'web-preferences': {'web-security':false}, - 'width': 700, - 'height': 600 + nodeIntegration: false + webPreferences: + webSecurity:false + width: 700 + height: 600 # Here, we load an arbitrary html file into the Composer! path = require 'path' url = path.join __dirname, '..', 'calendar.html' - w.loadUrl "file://#{url}?draftClientId=#{@props.draftClientId}" + w.loadURL "file://#{url}?draftClientId=#{@props.draftClientId}" _getDialog: => diff --git a/examples/N1-Send-Availability/docs/calendar-button.html b/examples/N1-Send-Availability/docs/calendar-button.html index 6d6b53c46..ff15bc76d 100644 --- a/examples/N1-Send-Availability/docs/calendar-button.html +++ b/examples/N1-Send-Availability/docs/calendar-button.html @@ -10,7 +10,7 @@
- + - +
diff --git a/examples/N1-Send-Availability/lib/calendar-button.cjsx b/examples/N1-Send-Availability/lib/calendar-button.cjsx index 3e085ab78..1760bea95 100644 --- a/examples/N1-Send-Availability/lib/calendar-button.cjsx +++ b/examples/N1-Send-Availability/lib/calendar-button.cjsx @@ -12,15 +12,16 @@ class CalendarButton extends React.Component _onClick: => BrowserWindow = require('remote').require('browser-window') w = new BrowserWindow - 'node-integration': false, - 'web-preferences': {'web-security':false}, - 'width': 700, - 'height': 600 + nodeIntegration: false + webPreferences: + webSecurity:false + width: 700 + height: 600 # Here, we load an arbitrary html file into the Composer! path = require 'path' url = path.join __dirname, '..', 'calendar.html' - w.loadUrl "file://#{url}?draftClientId=#{@props.draftClientId}" + w.loadURL "file://#{url}?draftClientId=#{@props.draftClientId}" _getDialog: => diff --git a/internal_packages/account-sidebar/lib/account-sidebar-item.cjsx b/internal_packages/account-sidebar/lib/account-sidebar-item.cjsx index dd61bbb86..aec662b12 100644 --- a/internal_packages/account-sidebar/lib/account-sidebar-item.cjsx +++ b/internal_packages/account-sidebar/lib/account-sidebar-item.cjsx @@ -56,9 +56,8 @@ class AccountSidebarItem extends React.Component _onShowContextMenu: => item = @props.item label = item.name - remote = require 'remote' - Menu = remote.require 'menu' - MenuItem = remote.require 'menu-item' + {remote} = require 'electron' + {Menu, MenuItem} = remote.require 'electron' menu = new Menu() menu.append(new MenuItem({ diff --git a/internal_packages/attachments/lib/image-attachment-component.cjsx b/internal_packages/attachments/lib/image-attachment-component.cjsx index c80e53f06..8e0274a08 100644 --- a/internal_packages/attachments/lib/image-attachment-component.cjsx +++ b/internal_packages/attachments/lib/image-attachment-component.cjsx @@ -26,10 +26,10 @@ class ImageAttachmentComponent extends AttachmentComponent _canAbortDownload: -> false _renderRemoveIcon: -> - + _renderDownloadButton: -> - + _imgOrLoader: -> if @props.download diff --git a/internal_packages/composer/lib/composer-view.cjsx b/internal_packages/composer/lib/composer-view.cjsx index 84f01b5bb..4d5c5e633 100644 --- a/internal_packages/composer/lib/composer-view.cjsx +++ b/internal_packages/composer/lib/composer-view.cjsx @@ -40,7 +40,7 @@ class ComposerView extends React.Component @containerRequired: false @propTypes: - draftClientId: React.PropTypes.string.isRequired + draftClientId: React.PropTypes.string # Either "inline" or "fullwindow" mode: React.PropTypes.string diff --git a/internal_packages/composer/lib/file-upload.cjsx b/internal_packages/composer/lib/file-upload.cjsx index 7e1589056..ecbd213e2 100644 --- a/internal_packages/composer/lib/file-upload.cjsx +++ b/internal_packages/composer/lib/file-upload.cjsx @@ -19,12 +19,13 @@ class FileUpload extends React.Component Uploading: {@_basename()}
- +
diff --git a/internal_packages/feedback/lib/feedback-button.cjsx b/internal_packages/feedback/lib/feedback-button.cjsx index f0b53ab8b..c51029ec3 100644 --- a/internal_packages/feedback/lib/feedback-button.cjsx +++ b/internal_packages/feedback/lib/feedback-button.cjsx @@ -57,7 +57,7 @@ class FeedbackButton extends React.Component 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) - require('ipc').send('show-feedback-window', { x, y, width, height, params }) + require('electron').ipcRenderer.send('show-feedback-window', { x, y, width, height, params }) setTimeout => @setState(newMessages: false) , 250 diff --git a/internal_packages/message-list/lib/message-controls.cjsx b/internal_packages/message-list/lib/message-controls.cjsx index 641376bb9..ceedf9164 100644 --- a/internal_packages/message-list/lib/message-controls.cjsx +++ b/internal_packages/message-list/lib/message-controls.cjsx @@ -1,5 +1,5 @@ -remote = require 'remote' React = require 'react' +{remote} = require 'electron' {Actions, NylasAPI, AccountStore} = require 'nylas-exports' {RetinaImg, ButtonDropdown, Menu} = require 'nylas-component-kit' @@ -131,7 +131,7 @@ class MessageControls extends React.Component success: (body) => fs.writeFile tmpfile, body, => window = new BrowserWindow(width: 800, height: 600, title: "#{@props.message.subject} - RFC822") - window.loadUrl('file://'+tmpfile) + window.loadURL('file://'+tmpfile) _onLogData: => console.log @props.message diff --git a/internal_packages/notification-update-available/lib/main.cjsx b/internal_packages/notification-update-available/lib/main.cjsx index 74b536579..4ff44b93f 100644 --- a/internal_packages/notification-update-available/lib/main.cjsx +++ b/internal_packages/notification-update-available/lib/main.cjsx @@ -1,6 +1,5 @@ -remote = require 'remote' {Actions} = require 'nylas-exports' -ipc = require('ipc') +{ipcRenderer, remote} = require('electron') module.exports = @@ -62,7 +61,7 @@ module.exports = _onNotificationActionTaken: ({notification, action}) -> if action.id is 'release-bar:install-update' - ipc.send 'command', 'application:install-update' + ipcRenderer.send 'command', 'application:install-update' true if action.id is 'release-bar:view-changelog' require('shell').openExternal('https://github.com/nylas/N1/blob/master/CHANGELOG.md') diff --git a/internal_packages/notification-update-available/spec/main-spec.coffee b/internal_packages/notification-update-available/spec/main-spec.coffee index 570d86634..445b407d3 100644 --- a/internal_packages/notification-update-available/spec/main-spec.coffee +++ b/internal_packages/notification-update-available/spec/main-spec.coffee @@ -8,14 +8,15 @@ stubUpdaterReleaseVersion = null ipcSendArgs = null PackageMain = proxyquire "../lib/main", - "ipc": - send: -> - ipcSendArgs = arguments - "remote": - getGlobal: (global) -> - autoUpdateManager: - releaseVersion: stubUpdaterReleaseVersion - getState: -> stubUpdaterState + "electron": + "ipcRenderer": + send: -> + ipcSendArgs = arguments + "remote": + getGlobal: (global) -> + autoUpdateManager: + releaseVersion: stubUpdaterReleaseVersion + getState: -> stubUpdaterState describe "NotificationUpdateAvailable", -> beforeEach -> @@ -33,7 +34,7 @@ describe "NotificationUpdateAvailable", -> stubUpdaterState = 'update-available' @package.activate() expect(@package.displayNotification).toHaveBeenCalled() - + it "should not display a notification if no update is avialable", -> spyOn(@package, 'displayNotification') stubUpdaterState = 'no-update-available' @@ -63,9 +64,8 @@ describe "NotificationUpdateAvailable", -> notifOptions = Actions.postNotification.mostRecentCall.args[0] expect(notifOptions.message.indexOf(version) > 0).toBe(true) - + describe "when the action is taken", -> it "should fire the `application:install-update` IPC event", -> Actions.notificationActionTaken({notification: {}, action: {id: 'release-bar:install-update'}}) expect(Array.prototype.slice.call(ipcSendArgs)).toEqual(['command', 'application:install-update']) - diff --git a/internal_packages/onboarding/lib/account-choose-page.cjsx b/internal_packages/onboarding/lib/account-choose-page.cjsx index 299bc6023..e0b29da81 100644 --- a/internal_packages/onboarding/lib/account-choose-page.cjsx +++ b/internal_packages/onboarding/lib/account-choose-page.cjsx @@ -98,7 +98,7 @@ class AccountChoosePage extends React.Component https://www.googleapis.com/auth/calendar' approval_prompt: 'force' }) - shell = require 'shell' + {shell} = require 'electron' shell.openExternal(googleUrl) module.exports = AccountChoosePage diff --git a/internal_packages/onboarding/lib/account-settings-page.cjsx b/internal_packages/onboarding/lib/account-settings-page.cjsx index affc35edd..75baac785 100644 --- a/internal_packages/onboarding/lib/account-settings-page.cjsx +++ b/internal_packages/onboarding/lib/account-settings-page.cjsx @@ -1,9 +1,6 @@ React = require 'react' -remote = require 'remote' -dialog = remote.require 'dialog' Crypto = require 'crypto' -ipc = require 'ipc' - +{ipcRenderer, dialog, remote} = require 'electron' {RetinaImg} = require 'nylas-component-kit' {EdgehillAPI, NylasAPI, APIError} = require 'nylas-exports' @@ -52,7 +49,7 @@ class AccountSettingsPage extends React.Component ) setTimeout(_retry,initial_delay) - ipc.on('browser-window-focus', -> + ipcRenderer.on('browser-window-focus', -> if not done # hack to deactivate this listener when done pollAttemptId++ poll(pollAttemptId,0) diff --git a/internal_packages/onboarding/lib/initial-packages-page.cjsx b/internal_packages/onboarding/lib/initial-packages-page.cjsx index d78930e7c..4723095a2 100644 --- a/internal_packages/onboarding/lib/initial-packages-page.cjsx +++ b/internal_packages/onboarding/lib/initial-packages-page.cjsx @@ -102,6 +102,6 @@ class InitialPackagesPage extends React.Component if RunningPackageInstalls > 0 @setState(waitingToGetStarted: true) else - require('ipc').send('account-setup-successful') + require('electron').ipcRenderer.send('account-setup-successful') module.exports = InitialPackagesPage diff --git a/internal_packages/onboarding/lib/page-router-store.coffee b/internal_packages/onboarding/lib/page-router-store.coffee index 549fd304a..e9ee14a7a 100644 --- a/internal_packages/onboarding/lib/page-router-store.coffee +++ b/internal_packages/onboarding/lib/page-router-store.coffee @@ -2,8 +2,8 @@ Reflux = require 'reflux' OnboardingActions = require './onboarding-actions' TokenAuthAPI = require './token-auth-api' {AccountStore} = require 'nylas-exports' +{ipcRenderer} = require 'electron' NylasStore = require 'nylas-store' -ipc = require 'ipc' url = require 'url' return unless NylasEnv.getWindowType() is "onboarding" @@ -26,12 +26,12 @@ class PageRouterStore extends NylasStore _onAccountJSONReceived: (json) => isFirstAccount = AccountStore.items().length is 0 AccountStore.addAccountFromJSON(json) - ipc.send('new-account-added') + ipcRenderer.send('new-account-added') NylasEnv.displayWindow() if isFirstAccount @_onMoveToPage('initial-preferences', {account: json}) else - ipc.send('account-setup-successful') + ipcRenderer.send('account-setup-successful') _onWindowPropsChanged: ({page, pageData}={}) => @_onMoveToPage(page, pageData) diff --git a/internal_packages/onboarding/lib/welcome-page.cjsx b/internal_packages/onboarding/lib/welcome-page.cjsx index 959e5c199..7677fb5f7 100644 --- a/internal_packages/onboarding/lib/welcome-page.cjsx +++ b/internal_packages/onboarding/lib/welcome-page.cjsx @@ -1,5 +1,5 @@ React = require 'react' -shell = require 'shell' +{shell} = require 'electron' classnames = require 'classnames' {RetinaImg} = require 'nylas-component-kit' PageRouterStore = require './page-router-store' diff --git a/internal_packages/plugins/lib/packages-store.coffee b/internal_packages/plugins/lib/packages-store.coffee index b688bae60..b4f3d1a2d 100644 --- a/internal_packages/plugins/lib/packages-store.coffee +++ b/internal_packages/plugins/lib/packages-store.coffee @@ -1,12 +1,12 @@ _ = require 'underscore' -ipc = require 'ipc' Reflux = require 'reflux' path = require 'path' fs = require 'fs-plus' -shell = require 'shell' PluginsActions = require './plugins-actions' {APMWrapper} = require 'nylas-exports' -dialog = require('remote').require('dialog') + +{ipcRenderer, shell, remote} = require 'electron' +dialog = remote.require('dialog') module.exports = PackagesStore = Reflux.createStore @@ -168,7 +168,7 @@ PackagesStore = Reflux.createStore else starterPackagesPath = path.join(resourcePath, "examples") - dialog.showOpenDialog + NylasEnv.showOpenDialog title: "Choose a Package Directory" defaultPath: starterPackagesPath properties: ['openDirectory'] @@ -195,13 +195,13 @@ PackagesStore = Reflux.createStore Developer menu." buttons: ["OK", "Cancel"] if btn is 0 - ipc.send('command', 'application:toggle-dev') + ipcRenderer.send('command', 'application:toggle-dev') return packagesDir = path.join(NylasEnv.getConfigDirPath(), 'dev', 'packages') fs.makeTreeSync(packagesDir) - dialog.showSaveDialog + NylasEnv.showSaveDialog title: "Save New Package" defaultPath: packagesDir properties: ['createDirectory'] diff --git a/internal_packages/plugins/lib/tab-installed.cjsx b/internal_packages/plugins/lib/tab-installed.cjsx index 11368be51..2689da877 100644 --- a/internal_packages/plugins/lib/tab-installed.cjsx +++ b/internal_packages/plugins/lib/tab-installed.cjsx @@ -56,7 +56,7 @@ class TabInstalled extends React.Component _onEnableDevMode: => - require('ipc').send('command', 'application:toggle-dev') + require('electron').ipcRenderer.send('command', 'application:toggle-dev') componentDidMount: => @_unsubscribers = [] diff --git a/internal_packages/plugins/lib/tabs-store.coffee b/internal_packages/plugins/lib/tabs-store.coffee index 78f754673..17df58c33 100644 --- a/internal_packages/plugins/lib/tabs-store.coffee +++ b/internal_packages/plugins/lib/tabs-store.coffee @@ -1,5 +1,4 @@ _ = require 'underscore' -ipc = require 'ipc' Reflux = require 'reflux' PluginsActions = require './plugins-actions' diff --git a/internal_packages/preferences/lib/main.cjsx b/internal_packages/preferences/lib/main.cjsx index 9d7c5fe37..b0b9c9521 100644 --- a/internal_packages/preferences/lib/main.cjsx +++ b/internal_packages/preferences/lib/main.cjsx @@ -6,7 +6,7 @@ module.exports = activate: -> - ipc = require 'ipc' + {ipcRenderer} = require 'electron' React = require 'react' Cfg = PreferencesSectionStore.SectionConfig @@ -42,7 +42,7 @@ module.exports = location: WorkspaceStore.Location.Preferences Actions.openPreferences.listen(@_openPreferences) - ipc.on 'open-preferences', => @_openPreferences() + ipcRenderer.on 'open-preferences', => @_openPreferences() _openPreferences: -> Actions.pushSheet(WorkspaceStore.Sheet.Preferences) diff --git a/internal_packages/preferences/lib/tabs/preferences-accounts.cjsx b/internal_packages/preferences/lib/tabs/preferences-accounts.cjsx index 5854e4bb7..d8fa01481 100644 --- a/internal_packages/preferences/lib/tabs/preferences-accounts.cjsx +++ b/internal_packages/preferences/lib/tabs/preferences-accounts.cjsx @@ -87,7 +87,7 @@ class PreferencesAccounts extends React.Component tokens _onAddAccount: => - ipc = require('ipc') + ipc = require('electron').ipcRenderer ipc.send('command', 'application:add-account') _onAccountChange: => diff --git a/internal_packages/system-tray/lib/system-tray.es6 b/internal_packages/system-tray/lib/system-tray.es6 index b56dbdbc2..9bafd7e32 100644 --- a/internal_packages/system-tray/lib/system-tray.es6 +++ b/internal_packages/system-tray/lib/system-tray.es6 @@ -18,8 +18,8 @@ class SystemTray { } _addEventListeners() { - this._tray.addListener('clicked', this._onClicked.bind(this)); - const unsubClicked = ()=> this._tray.removeListener('clicked', this._onClicked); + this._tray.addListener('click', this._onClicked.bind(this)); + const unsubClicked = ()=> this._tray.removeListener('click', this._onClicked); const unsubStore = this._store.listen(this._onChange.bind(this)); return ()=> { unsubClicked(); diff --git a/internal_packages/system-tray/lib/tray-store.es6 b/internal_packages/system-tray/lib/tray-store.es6 index cf6d838d5..3505f6a31 100644 --- a/internal_packages/system-tray/lib/tray-store.es6 +++ b/internal_packages/system-tray/lib/tray-store.es6 @@ -1,7 +1,6 @@ import path from 'path'; -import remote from 'remote'; -import ipc from 'ipc'; import NylasStore from 'nylas-store'; +import {remote, ipcRenderer} from 'electron'; import {UnreadBadgeStore, CanvasUtils} from 'nylas-exports'; const NativeImage = remote.require('native-image'); const Menu = remote.require('menu'); @@ -15,25 +14,25 @@ const UNREAD_ICON_PATH = path.join(__dirname, '..', 'assets', process.platform, const menuTemplate = [ { label: 'New Message', - click: ()=> ipc.send('command', 'application:new-message'), + click: ()=> ipcRenderer.send('command', 'application:new-message'), }, { label: 'Preferences', - click: ()=> ipc.send('command', 'application:open-preferences'), + click: ()=> ipcRenderer.send('command', 'application:open-preferences'), }, { type: 'separator', }, { label: 'Quit N1', - click: ()=> ipc.send('command', 'application:quit'), + click: ()=> ipcRenderer.send('command', 'application:quit'), }, ]; if (process.platform === 'darwin') { menuTemplate.unshift({ label: 'Open Inbox', - click: ()=> ipc.send('command', 'application:show-main-window'), + click: ()=> ipcRenderer.send('command', 'application:show-main-window'), }); } @@ -77,10 +76,10 @@ class TrayStore extends NylasStore { const img = new Image(); // toDataUrl always returns the @1x image data, so the assets/darwin/ // contains an "@2x" image /without/ the @2x extension - img.src = this._baseIcon.toDataUrl(); + img.src = this._baseIcon.toDataURL(); const count = this._unreadCount || ''; const canvas = canvasWithSystemTrayIconAndText(img, count.toString()); - const pngData = NativeImage.createFromDataUrl(canvas.toDataURL()).toPng(); + const pngData = NativeImage.createFromDataURL(canvas.toDataURL()).toPng(); // creating from a buffer allows us to specify that the image is @2x const out2x = NativeImage.createFromBuffer(pngData, 2); diff --git a/internal_packages/worker-ui/lib/developer-bar-curl-item.cjsx b/internal_packages/worker-ui/lib/developer-bar-curl-item.cjsx index 8b7ef5bf3..f875c5cf3 100644 --- a/internal_packages/worker-ui/lib/developer-bar-curl-item.cjsx +++ b/internal_packages/worker-ui/lib/developer-bar-curl-item.cjsx @@ -40,7 +40,7 @@ class DeveloperBarCurlItem extends React.Component fs.unlinkSync(curlFile) fs.writeFileSync(curlFile, @props.item.command) fs.chmodSync(curlFile, '777') - shell = require 'shell' + {shell} = require 'electron' shell.openItem(curlFile) diff --git a/package.json b/package.json index 33a2d17ae..818b45da0 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/nylas/N1/issues" }, - "electronVersion": "0.34.3", + "electronVersion": "0.35.1", "dependencies": { "async": "^0.9", "atom-keymap": "^6.1.1", diff --git a/spec/auto-update-manager-spec.coffee b/spec/auto-update-manager-spec.coffee index 756b1a033..ec2163d55 100644 --- a/spec/auto-update-manager-spec.coffee +++ b/spec/auto-update-manager-spec.coffee @@ -18,7 +18,7 @@ describe "AutoUpdateManager", -> m = new AutoUpdateManager("3.222.1-abc", @config, @specMode) spyOn(m, "setupAutoUpdater") - {query} = url.parse(m.feedUrl, true) + {query} = url.parse(m.feedURL, true) expect(query.arch).toBe process.arch expect(query.platform).toBe process.platform expect(query.version).toBe "3.222.1-abc" @@ -27,7 +27,7 @@ describe "AutoUpdateManager", -> it "correctly sets the feedURL", -> m = new AutoUpdateManager("3.222.1", @config, @specMode) spyOn(m, "setupAutoUpdater") - {query} = url.parse(m.feedUrl, true) + {query} = url.parse(m.feedURL, true) expect(query.arch).toBe process.arch expect(query.platform).toBe process.platform expect(query.version).toBe "3.222.1" @@ -36,7 +36,7 @@ describe "AutoUpdateManager", -> it "should save one to @config and send it", -> m = new AutoUpdateManager("3.222.1", @config, @specMode) spyOn(m, "setupAutoUpdater") - {query} = url.parse(m.feedUrl, true) + {query} = url.parse(m.feedURL, true) expect(query.id).toBeDefined() expect(@config.set).toHaveBeenCalledWith('updateIdentity', query.id) @@ -46,7 +46,7 @@ describe "AutoUpdateManager", -> @updateIdentity = "test-identity" m = new AutoUpdateManager("3.222.1", @config, @specMode) spyOn(m, "setupAutoUpdater") - {query} = url.parse(m.feedUrl, true) + {query} = url.parse(m.feedURL, true) expect(query.id).toEqual(@updateIdentity) expect(@config.set).not.toHaveBeenCalled() diff --git a/spec/jasmine-helper.coffee b/spec/jasmine-helper.coffee index 599339a48..dc26db729 100644 --- a/spec/jasmine-helper.coffee +++ b/spec/jasmine-helper.coffee @@ -1,5 +1,5 @@ fs = require 'fs' -remote = require 'remote' +{remote} = require 'electron' module.exports.runSpecSuite = (specSuite, logFile, logErrors=true) -> {$, $$} = require '../src/space-pen-extensions' diff --git a/spec/n1-spec-reporter.coffee b/spec/n1-spec-reporter.coffee index bc7393d20..d06ca72ad 100644 --- a/spec/n1-spec-reporter.coffee +++ b/spec/n1-spec-reporter.coffee @@ -82,7 +82,7 @@ class N1SpecReporter extends View @on 'click', '.stack-trace', -> $(this).toggleClass('expanded') - @reloadButton.on 'click', -> require('ipc').send('call-window-method', 'restart') + @reloadButton.on 'click', -> require('electron').ipcRenderer.send('call-window-method', 'restart') reportRunnerResults: (runner) -> @updateSpecCounts() diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 3cd823e99..81574c617 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -17,7 +17,7 @@ KeymapManager = require '../src/keymap-manager' Config = require '../src/config' ServiceHub = require 'service-hub' pathwatcher = require 'pathwatcher' -clipboard = require 'clipboard' +{clipboard} = require 'electron' Account = require "../src/flux/models/account" AccountStore = require "../src/flux/stores/account-store" diff --git a/spec/stores/database-setup-query-builder-spec.coffee b/spec/stores/database-setup-query-builder-spec.coffee index da2adbe74..e1c57a2fb 100644 --- a/spec/stores/database-setup-query-builder-spec.coffee +++ b/spec/stores/database-setup-query-builder-spec.coffee @@ -1,4 +1,3 @@ -ipc = require 'ipc' TestModel = require '../fixtures/db-test-model' Attributes = require '../../src/flux/attributes' DatabaseSetupQueryBuilder = require '../../src/flux/stores/database-setup-query-builder' diff --git a/spec/stores/database-store-spec.coffee b/spec/stores/database-store-spec.coffee index b9bdc1d32..e08683bb8 100644 --- a/spec/stores/database-store-spec.coffee +++ b/spec/stores/database-store-spec.coffee @@ -1,5 +1,4 @@ _ = require 'underscore' -ipc = require 'ipc' Label = require '../../src/flux/models/label' Thread = require '../../src/flux/models/thread' diff --git a/spec/stores/draft-store-spec.coffee b/spec/stores/draft-store-spec.coffee index 77dee968b..0d3d422bf 100644 --- a/spec/stores/draft-store-spec.coffee +++ b/spec/stores/draft-store-spec.coffee @@ -12,7 +12,8 @@ DestroyDraftTask = require '../../src/flux/tasks/destroy-draft' SoundRegistry = require '../../src/sound-registry' Actions = require '../../src/flux/actions' Utils = require '../../src/flux/models/utils' -ipc = require 'ipc' + +{ipcRenderer} = require 'electron' _ = require 'underscore' fakeThread = null @@ -42,14 +43,14 @@ describe "DraftStore", -> spyOn(DraftStore, "_sanitizeBody").andCallThrough() spyOn(DraftStore, "_onInlineStylesResult").andCallThrough() spyOn(DraftStore, "_convertToInlineStyles").andCallThrough() - spyOn(ipc, "send").andCallFake (message, body) -> + spyOn(ipcRenderer, "send").andCallFake (message, body) -> if message is "inline-style-parse" # There needs to be a defer block in here so the promise # responsible for handling the `inline-style-parse` can be # properly set. If the whole path is synchronous instead of # asynchrounous, the promise is not cleared properly. Doing this # requires us to add `advanceClock` blocks. - _.defer -> DraftStore._onInlineStylesResult(body) + _.defer -> DraftStore._onInlineStylesResult({}, body) fakeThread = new Thread id: 'fake-thread-id' @@ -863,7 +864,7 @@ describe "DraftStore", -> received = draft Promise.resolve() waitsForPromise -> - DraftStore._onHandleMailtoLink('mailto:bengotow@gmail.com').then -> + DraftStore._onHandleMailtoLink({}, 'mailto:bengotow@gmail.com').then -> expect(received.body.indexOf("Edited by TestExtension!")).toBe(0) describe "when testing subject keys", -> @@ -875,19 +876,19 @@ describe "DraftStore", -> it "works for lowercase", -> waitsForPromise => - DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?subject=' + @expected).then => + DraftStore._onHandleMailtoLink({}, 'mailto:asdf@asdf.com?subject=' + @expected).then => received = DraftStore._finalizeAndPersistNewMessage.mostRecentCall.args[0] expect(received.subject).toBe(@expected) it "works for title case", -> waitsForPromise => - DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?Subject=' + @expected).then => + DraftStore._onHandleMailtoLink({}, 'mailto:asdf@asdf.com?Subject=' + @expected).then => received = DraftStore._finalizeAndPersistNewMessage.mostRecentCall.args[0] expect(received.subject).toBe(@expected) it "works for uppercase", -> waitsForPromise => - DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?SUBJECT=' + @expected).then => + DraftStore._onHandleMailtoLink({}, 'mailto:asdf@asdf.com?SUBJECT=' + @expected).then => received = DraftStore._finalizeAndPersistNewMessage.mostRecentCall.args[0] expect(received.subject).toBe(@expected) @@ -977,7 +978,7 @@ describe "DraftStore", -> links.forEach (link, idx) -> it "works for #{link}", -> waitsForPromise -> - DraftStore._onHandleMailtoLink(link).then -> + DraftStore._onHandleMailtoLink({}, link).then -> expectedDraft = expected[idx] received = DatabaseStore.persistModel.mostRecentCall.args[0] expect(received['subject']).toEqual(expectedDraft['subject']) diff --git a/spec/stores/file-download-store-spec.coffee b/spec/stores/file-download-store-spec.coffee index 931286d60..f2812daf9 100644 --- a/spec/stores/file-download-store-spec.coffee +++ b/spec/stores/file-download-store-spec.coffee @@ -1,5 +1,5 @@ fs = require 'fs' -shell = require 'shell' +{shell} = require 'electron' NylasAPI = require '../../src/flux/nylas-api' File = require '../../src/flux/models/file' FileDownloadStore = require '../../src/flux/stores/file-download-store' diff --git a/src/browser/application-menu.coffee b/src/browser/application-menu.coffee index dee754eba..e6d744241 100644 --- a/src/browser/application-menu.coffee +++ b/src/browser/application-menu.coffee @@ -1,9 +1,6 @@ -app = require 'app' -ipc = require 'ipc' -Menu = require 'menu' +{BrowserWindow, Menu, app} = require 'electron' _ = require 'underscore' Utils = require '../flux/models/utils' -BrowserWindow = require 'browser-window' # Used to manage the global application menu. # diff --git a/src/browser/application.coffee b/src/browser/application.coffee index 333483ad5..9472a6053 100644 --- a/src/browser/application.coffee +++ b/src/browser/application.coffee @@ -1,22 +1,19 @@ NylasWindow = require './nylas-window' -BrowserWindow = require 'browser-window' WindowManager = require './window-manager' ApplicationMenu = require './application-menu' AutoUpdateManager = require './auto-update-manager' NylasProtocolHandler = require './nylas-protocol-handler' SharedFileManager = require './shared-file-manager' +{BrowserWindow, Menu, app, ipcMain, dialog} = require 'electron' + _ = require 'underscore' fs = require 'fs-plus' os = require 'os' -app = require 'app' -ipc = require 'ipc' net = require 'net' url = require 'url' exec = require('child_process').exec -Menu = require 'menu' path = require 'path' -dialog = require 'dialog' querystring = require 'querystring' {EventEmitter} = require 'events' @@ -310,28 +307,28 @@ class Application @openUrl(urlToOpen) event.preventDefault() - ipc.on 'set-badge-value', (event, value) => + ipcMain.on 'set-badge-value', (event, value) => app.dock?.setBadge?(value) - ipc.on 'new-window', (event, options) => + ipcMain.on 'new-window', (event, options) => @windowManager.newWindow(options) - ipc.on 'show-feedback-window', (event, options) => + ipcMain.on 'show-feedback-window', (event, options) => @windowManager.showFeedbackWindow(options) - ipc.on 'register-hot-window', (event, options) => + ipcMain.on 'register-hot-window', (event, options) => @windowManager.registerHotWindow(options) - ipc.on 'unregister-hot-window', (event, windowType) => + ipcMain.on 'unregister-hot-window', (event, windowType) => @windowManager.unregisterHotWindow(windowType) - ipc.on 'from-react-remote-window', (event, json) => + ipcMain.on 'from-react-remote-window', (event, json) => @windowManager.sendToMainWindow('from-react-remote-window', json) - ipc.on 'from-react-remote-window-selection', (event, json) => + ipcMain.on 'from-react-remote-window-selection', (event, json) => @windowManager.sendToMainWindow('from-react-remote-window-selection', json) - ipc.on 'inline-style-parse', (event, {body, clientId}) => + ipcMain.on 'inline-style-parse', (event, {body, clientId}) => juice = require 'juice' try body = juice(body) @@ -348,48 +345,51 @@ class Application @openWindowsForTokenState() event.preventDefault() - ipc.on 'update-application-menu', (event, template, keystrokesByCommand) => + ipcMain.on 'update-application-menu', (event, template, keystrokesByCommand) => win = BrowserWindow.fromWebContents(event.sender) @applicationMenu.update(win, template, keystrokesByCommand) - ipc.on 'command', (event, command) => + ipcMain.on 'command', (event, command) => @emit(command) - ipc.on 'window-command', (event, command, args...) -> + ipcMain.on 'window-command', (event, command, args...) -> win = BrowserWindow.fromWebContents(event.sender) win.emit(command, args...) - ipc.on 'call-window-method', (event, method, args...) -> + ipcMain.on 'call-window-method', (event, method, args...) -> win = BrowserWindow.fromWebContents(event.sender) win[method](args...) - ipc.on 'action-bridge-rebroadcast-to-all', (event, args...) => + ipcMain.on 'call-webcontents-method', (event, method, args...) -> + event.sender[method](args...) + + ipcMain.on 'action-bridge-rebroadcast-to-all', (event, args...) => win = BrowserWindow.fromWebContents(event.sender) @windowManager.windows().forEach (nylasWindow) -> return if nylasWindow.browserWindow == win return unless nylasWindow.browserWindow.webContents nylasWindow.browserWindow.webContents.send('action-bridge-message', args...) - ipc.on 'action-bridge-rebroadcast-to-work', (event, args...) => + ipcMain.on 'action-bridge-rebroadcast-to-work', (event, args...) => workWindow = @windowManager.workWindow() return if not workWindow or not workWindow.browserWindow.webContents return if BrowserWindow.fromWebContents(event.sender) is workWindow workWindow.browserWindow.webContents.send('action-bridge-message', args...) clipboard = null - ipc.on 'write-text-to-selection-clipboard', (event, selectedText) -> - clipboard ?= require 'clipboard' + ipcMain.on 'write-text-to-selection-clipboard', (event, selectedText) -> + clipboard ?= require('electron').clipboard clipboard.writeText(selectedText, 'selection') - ipc.on 'account-setup-successful', (event) => + ipcMain.on 'account-setup-successful', (event) => @windowManager.showMainWindow() @windowManager.ensureWorkWindow() @windowManager.onboardingWindow()?.close() - ipc.on 'new-account-added', (event) => + ipcMain.on 'new-account-added', (event) => @windowManager.ensureWorkWindow() - ipc.on 'run-in-window', (event, params) => + ipcMain.on 'run-in-window', (event, params) => @_sourceWindows ?= {} sourceWindow = BrowserWindow.fromWebContents(event.sender) @_sourceWindows[params.taskId] = sourceWindow @@ -401,7 +401,7 @@ class Application return if not targetWindow or not targetWindow.browserWindow.webContents targetWindow.browserWindow.webContents.send('run-in-window', params) - ipc.on 'remote-run-results', (event, params) => + ipcMain.on 'remote-run-results', (event, params) => sourceWindow = @_sourceWindows[params.taskId] sourceWindow.webContents.send('remote-run-results', params) delete @_sourceWindows[params.taskId] diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index efb3637af..948645778 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -35,9 +35,9 @@ class AutoUpdateManager if process.platform is 'win32' # Squirrel for Windows can't handle query params # https://github.com/Squirrel/Squirrel.Windows/issues/132 - @feedUrl = "https://edgehill.nylas.com/update-check/win32/#{process.arch}/#{@version}/#{updaterId}/#{updaterEmails}" + @feedURL = "https://edgehill.nylas.com/update-check/win32/#{process.arch}/#{@version}/#{updaterId}/#{updaterEmails}" else - @feedUrl = "https://edgehill.nylas.com/update-check?platform=#{process.platform}&arch=#{process.arch}&version=#{@version}&id=#{updaterId}&emails=#{updaterEmails}" + @feedURL = "https://edgehill.nylas.com/update-check?platform=#{process.platform}&arch=#{process.arch}&version=#{@version}&id=#{updaterId}&emails=#{updaterEmails}" if not @specMode process.nextTick => @setupAutoUpdater() @@ -46,13 +46,13 @@ class AutoUpdateManager if process.platform is 'win32' autoUpdater = require './auto-updater-win32' else - autoUpdater = require 'auto-updater' + autoUpdater = require('electron').autoUpdater autoUpdater.on 'error', (event, message) => console.error "Error Downloading Update: #{message}" @setState(ErrorState) - autoUpdater.setFeedUrl(@feedUrl) + autoUpdater.setFeedURL(@feedURL) autoUpdater.on 'checking-for-update', => @setState(CheckingState) @@ -110,7 +110,7 @@ class AutoUpdateManager onUpdateNotAvailable: => autoUpdater.removeListener 'error', @onUpdateError - dialog = require 'dialog' + {dialog} = require 'electron' dialog.showMessageBox type: 'info' buttons: ['OK'] @@ -121,7 +121,7 @@ class AutoUpdateManager onUpdateError: (event, message) => autoUpdater.removeListener 'update-not-available', @onUpdateNotAvailable - dialog = require 'dialog' + {dialog} = require 'electron' dialog.showMessageBox type: 'warning' buttons: ['OK'] diff --git a/src/browser/auto-updater-win32.coffee b/src/browser/auto-updater-win32.coffee index 4332ad39d..08b1f35b1 100644 --- a/src/browser/auto-updater-win32.coffee +++ b/src/browser/auto-updater-win32.coffee @@ -5,7 +5,7 @@ SquirrelUpdate = require './squirrel-update' class AutoUpdater _.extend @prototype, EventEmitter.prototype - setFeedUrl: (@updateUrl) -> + setFeedURL: (@updateUrl) -> quitAndInstall: -> if SquirrelUpdate.existsSync() diff --git a/src/browser/context-menu.coffee b/src/browser/context-menu.coffee index b477f623c..8ddc79a7a 100644 --- a/src/browser/context-menu.coffee +++ b/src/browser/context-menu.coffee @@ -1,4 +1,4 @@ -Menu = require 'menu' +{Menu} = require 'electron' module.exports = class ContextMenu diff --git a/src/browser/main.coffee b/src/browser/main.coffee index b6395f120..580ec815c 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -4,7 +4,7 @@ process.on 'uncaughtException', (error={}) -> console.log(error.message) if error.message? console.log(error.stack) if error.stack? -app = require 'app' +{app} = require 'electron' fs = require 'fs-plus' path = require 'path' optimist = require 'optimist' @@ -44,7 +44,7 @@ start = -> setupNylasHome = -> return if process.env.NYLAS_HOME - atomHome = path.join(app.getHomeDir(), '.nylas') + atomHome = path.join(app.getPath('home'), '.nylas') process.env.NYLAS_HOME = atomHome normalizeDriveLetterName = (filePath) -> diff --git a/src/browser/main.js b/src/browser/main.js index 88831310d..0b958f348 100644 --- a/src/browser/main.js +++ b/src/browser/main.js @@ -64,7 +64,7 @@ if (process.env.NYLAS_HOME) { return; } - atomHome = path.join(app.getHomeDir(), '.nylas'); + atomHome = path.join(app.getPath('home'), '.nylas'); return process.env.NYLAS_HOME = atomHome; }; diff --git a/src/browser/native-notification-manager.coffee b/src/browser/native-notification-manager.coffee index 7995e0a9f..b208b40da 100644 --- a/src/browser/native-notification-manager.coffee +++ b/src/browser/native-notification-manager.coffee @@ -1,4 +1,4 @@ -# ipc = require 'ipc' +# ipcMain = require 'ipcMain' # BrowserWindow = require 'browser-window' # # class NativeNotificationManagerUnavailable @@ -27,7 +27,7 @@ # global.__nativeNotificationManagerMacOSXDelegate = Delegate # global.__nativeNotificationManagerMacOSX = @ # -# ipc.on('fire-native-notification', @onFireNotification) +# ipcMain.on('fire-native-notification', @onFireNotification) # # shouldPresentNotification: (self, _cmd, center, notif) => # return true diff --git a/src/browser/nylas-protocol-handler.coffee b/src/browser/nylas-protocol-handler.coffee index 5fcda935c..b4330ec55 100644 --- a/src/browser/nylas-protocol-handler.coffee +++ b/src/browser/nylas-protocol-handler.coffee @@ -1,7 +1,6 @@ -app = require 'app' +{app, protocol} = require 'electron' fs = require 'fs' path = require 'path' -protocol = require 'protocol' # Handles requests with 'nylas' protocol. # @@ -18,7 +17,7 @@ module.exports = class NylasProtocolHandler constructor: (resourcePath, safeMode) -> @loadPaths = [] - @dotNylasDirectory = path.join(app.getHomeDir(), '.nylas') + @dotNylasDirectory = path.join(app.getPath('home'), '.nylas') unless safeMode @loadPaths.push(path.join(@dotNylasDirectory, 'dev', 'packages')) diff --git a/src/browser/nylas-window.coffee b/src/browser/nylas-window.coffee index a66325016..ac27824c8 100644 --- a/src/browser/nylas-window.coffee +++ b/src/browser/nylas-window.coffee @@ -1,5 +1,4 @@ -BrowserWindow = require 'browser-window' -app = require 'app' +{BrowserWindow, app} = require 'electron' path = require 'path' fs = require 'fs' url = require 'url' @@ -55,26 +54,24 @@ class NylasWindow show: false title: title ? 'Nylas' frame: frame - 'standard-window': frame width: width height: height resizable: resizable ? true icon: @constructor.iconPath - 'web-preferences': - 'direct-write': true - 'subpixel-font-scaling': true + webPreferences: + directWrite: true if @mainWindow # Prevents DOM timers from being suspended when the main window is hidden. # Means there's not an awkward catch-up when you re-show the main window. - options['web-preferences']['page-visibility'] = true + options.webPreferences.pageVisibility = true # Don't set icon on Windows so the exe's ico will be used as window and # taskbar's icon. See https://github.com/atom/atom/issues/4811 for more. if process.platform is 'linux' options.icon = @constructor.iconPath - @browserWindow = new BrowserWindow options + @browserWindow = new BrowserWindow(options) global.application.windowManager.addWindow(this) @handleEvents() @@ -108,7 +105,7 @@ class NylasWindow if @browserWindow.loadSettingsChangedSinceGetURL @browserWindow.webContents.send('load-settings-changed', @browserWindow.loadSettings) - @browserWindow.loadUrl(@getUrl(loadSettings)) + @browserWindow.loadURL(@getURL(loadSettings)) @browserWindow.focusOnWebView() if @isSpec loadSettings: -> @@ -120,7 +117,7 @@ class NylasWindow if @loaded @browserWindow.webContents.send('load-settings-changed', loadSettings) - getUrl: (loadSettingsObj) -> + getURL: (loadSettingsObj) -> # Ignore the windowState when passing loadSettings via URL, since it could # be quite large. loadSettings = _.clone(loadSettingsObj) @@ -172,7 +169,7 @@ class NylasWindow return if @isSpec return if not @loaded - dialog = require 'dialog' + {dialog} = require 'electron' chosen = dialog.showMessageBox @browserWindow, type: 'warning' buttons: ['Close', 'Keep Waiting'] @@ -184,9 +181,9 @@ class NylasWindow global.application.exit(100) if @exitWhenDone if @neverClose - @browserWindow.restart() + @browserWindow.reload() else - dialog = require 'dialog' + {dialog} = require 'electron' chosen = dialog.showMessageBox @browserWindow, type: 'warning' buttons: ['Close Window', 'Reload', 'Keep It Open'] @@ -194,7 +191,7 @@ class NylasWindow detail: 'Please report this issue to us at support@nylas.com.' switch chosen when 0 then @browserWindow.destroy() - when 1 then @browserWindow.restart() + when 1 then @browserWindow.reload() @setupContextMenu() @@ -271,6 +268,6 @@ class NylasWindow isSpecWindow: -> @isSpec - reload: -> @browserWindow.restart() + reload: -> @browserWindow.reload() toggleDevTools: -> @browserWindow.toggleDevTools() diff --git a/src/browser/window-manager.coffee b/src/browser/window-manager.coffee index 8c5b90dbb..e2f02eb53 100644 --- a/src/browser/window-manager.coffee +++ b/src/browser/window-manager.coffee @@ -1,8 +1,8 @@ _ = require 'underscore' fs = require 'fs-plus' NylasWindow = require './nylas-window' -BrowserWindow = require 'browser-window' -app = require 'app' + +{BrowserWindow, app} = require 'electron' class WindowManager @@ -164,16 +164,17 @@ class WindowManager @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' + nodeIntegration: false + webPreferences: + webSecurity:false + x: x + y: y + width: width, + height: height, + title: 'Feedback' onOpenURL = (event, href) -> - shell = require 'shell' + {shell} = require 'electron' shell.openExternal(href) event.preventDefault() @@ -190,7 +191,7 @@ class WindowManager w.webContents.on('will-navigate', onOpenURL) url = require('path').join(@resourcePath, 'static', 'feedback.html') - w.loadUrl("file://#{url}?#{params}") + w.loadURL("file://#{url}?#{params}") w.show() # Makes a new window appear of a certain `windowType`. diff --git a/src/clipboard.coffee b/src/clipboard.coffee index 934f3b4be..2145a0396 100644 --- a/src/clipboard.coffee +++ b/src/clipboard.coffee @@ -1,4 +1,4 @@ -clipboard = require 'clipboard' +{clipboard} = require 'electron' crypto = require 'crypto' # Extended: Represents the clipboard used for copying and pasting in Nylas N1. diff --git a/src/components/evented-iframe.cjsx b/src/components/evented-iframe.cjsx index fc25dcbe0..5b3b64e89 100644 --- a/src/components/evented-iframe.cjsx +++ b/src/components/evented-iframe.cjsx @@ -169,7 +169,7 @@ class EventedIFrame extends React.Component menu.append(new MenuItem({ label: "Save Image...", click: -> - NylasEnv.showSaveDialog srcFilename, (path) -> + NylasEnv.showSaveDialog {defaultPath: srcFilename}, (path) -> return unless path oReq = new XMLHttpRequest() oReq.open("GET", src, true) @@ -190,7 +190,7 @@ class EventedIFrame extends React.Component canvas.height = img.height canvas.getContext("2d").drawImage(imageTarget, 0, 0) imageDataURL = canvas.toDataURL("image/png") - img = NativeImage.createFromDataUrl(imageDataURL) + img = NativeImage.createFromDataURL(imageDataURL) clipboard.writeImage(img) , false) img.src = src diff --git a/src/database-object-registry.coffee b/src/database-object-registry.coffee index 5a1fe041d..0647483ea 100644 --- a/src/database-object-registry.coffee +++ b/src/database-object-registry.coffee @@ -1,5 +1,4 @@ _ = require 'underscore' -ipc = require 'ipc' Model = null SerializableRegistry = require './serializable-registry' diff --git a/src/flux/action-bridge.coffee b/src/flux/action-bridge.coffee index 5fbde835c..7855d1f9c 100644 --- a/src/flux/action-bridge.coffee +++ b/src/flux/action-bridge.coffee @@ -65,7 +65,7 @@ class ActionBridge callback = => @onRebroadcast(TargetWindows.WORK, name, arguments) Actions[name].listen(callback, @) - onIPCMessage: (initiatorId, name, json) => + onIPCMessage: (event, initiatorId, name, json) => # There's something very strange about IPC event handlers. The ReactRemoteParent # threw React exceptions when calling setState from an IPC callback, and the debugger # often refuses to stop at breakpoints immediately inside IPC callbacks. diff --git a/src/flux/nylas-api.coffee b/src/flux/nylas-api.coffee index fac5efa33..3784a4147 100644 --- a/src/flux/nylas-api.coffee +++ b/src/flux/nylas-api.coffee @@ -241,8 +241,8 @@ class NylasAPI unless @_notificationUnlisten handler = ({notification, action}) -> if action.id is '401:unlink' - ipc = require 'ipc' - ipc.send('command', 'application:reset-config-and-relaunch') + {ipcRenderer} = require 'electron' + ipcRenderer.send('command', 'application:reset-config-and-relaunch') @_notificationUnlisten = Actions.notificationActionTaken.listen(handler, @) return Promise.resolve() diff --git a/src/flux/stores/account-store.coffee b/src/flux/stores/account-store.coffee index 3ea099541..18b4614db 100644 --- a/src/flux/stores/account-store.coffee +++ b/src/flux/stores/account-store.coffee @@ -63,7 +63,7 @@ class AccountStore NylasEnv.menu.update() _selectAccountByIndex: (index) => - require('ipc').send('command', 'application:show-main-window') + require('electron').ipcRenderer.send('command', 'application:show-main-window') index = Math.min(@_accounts.length - 1, Math.max(0, index)) Actions.selectAccountId(@_accounts[index].id) @@ -103,7 +103,7 @@ class AccountStore @_save() if @_accounts.length is 0 - ipc = require('ipc') + ipc = require('electron').ipcRenderer ipc.send('command', 'application:reset-config-and-relaunch') else if @_index is idx diff --git a/src/flux/stores/database-store.coffee b/src/flux/stores/database-store.coffee index 3d6ed9ffb..d1e71c0c4 100644 --- a/src/flux/stores/database-store.coffee +++ b/src/flux/stores/database-store.coffee @@ -1,5 +1,4 @@ _ = require 'underscore' -ipc = require 'ipc' async = require 'async' path = require 'path' sqlite3 = require 'sqlite3' @@ -13,6 +12,8 @@ DatabaseSetupQueryBuilder = require './database-setup-query-builder' DatabaseChangeRecord = require './database-change-record' PriorityUICoordinator = require '../../priority-ui-coordinator' +{ipcRenderer} = require 'electron' + {AttributeCollection, AttributeJoinedData} = require '../attributes' {tableNameForJoin, @@ -94,7 +95,7 @@ class DatabaseStore extends NylasStore # Listen to events from the application telling us when the database is ready, # should be closed so it can be deleted, etc. - ipc.on('database-phase-change', @_onPhaseChange) + ipcRenderer.on('database-phase-change', @_onPhaseChange) _.defer => @_onPhaseChange() _onPhaseChange: (event) => diff --git a/src/flux/stores/draft-store.coffee b/src/flux/stores/draft-store.coffee index a849f8ef9..4d6f5f2f7 100644 --- a/src/flux/stores/draft-store.coffee +++ b/src/flux/stores/draft-store.coffee @@ -1,9 +1,10 @@ _ = require 'underscore' -ipc = require 'ipc' crypto = require 'crypto' moment = require 'moment' sanitizeHtml = require 'sanitize-html' +{ipcRenderer} = require 'electron' + DraftStoreProxy = require './draft-store-proxy' DatabaseStore = require './database-store' AccountStore = require './account-store' @@ -58,7 +59,7 @@ class DraftStore @listenTo Actions.sendQuickReply, @_onSendQuickReply if NylasEnv.isMainWindow() - ipc.on 'new-message', => @_onPopoutBlankDraft() + ipcRenderer.on 'new-message', => @_onPopoutBlankDraft() # Remember that these two actions only fire in the current window and # are picked up by the instance of the DraftStore in the current @@ -92,9 +93,9 @@ class DraftStore # request to queue something, and when it appears on the queue. @_draftsSending = {} - ipc.on 'mailto', @_onHandleMailtoLink + ipcRenderer.on 'mailto', @_onHandleMailtoLink - ipc.on 'inline-styles-result', @_onInlineStylesResult + ipcRenderer.on 'inline-styles-result', @_onInlineStylesResult ######### PUBLIC ####################################################### @@ -371,7 +372,7 @@ class DraftStore body = @_injectUserAgentStyles(body) @_inlineStylePromises[clientId] ?= new Promise (resolve, reject) => @_inlineStyleResolvers[clientId] = resolve - ipc.send('inline-style-parse', {body, clientId}) + ipcRenderer.send('inline-style-parse', {body, clientId}) return @_inlineStylePromises[clientId] # This will prepend the user agent stylesheet so we can apply it to the @@ -383,7 +384,7 @@ class DraftStore userAgentDefault = require '../../chrome-user-agent-stylesheet-string' return "#{body[0...i]}#{body[i..-1]}" - _onInlineStylesResult: ({body, clientId}) => + _onInlineStylesResult: (event, {body, clientId}) => delete @_inlineStylePromises[clientId] @_inlineStyleResolvers[clientId](body) delete @_inlineStyleResolvers[clientId] @@ -422,19 +423,23 @@ class DraftStore title = if options.newDraft then "New Message" else "Message" + console.log('starting save') save.then => + console.log('finished save') app = require('remote').getGlobal('application') existing = app.windowManager.windowWithPropsMatching({draftClientId}) + console.log('discovered existing') if existing existing.restore() if existing.isMinimized() existing.focus() else + console.log('NylasEnv.newWindow') NylasEnv.newWindow title: title windowType: "composer" windowProps: _.extend(options, {draftClientId}) - _onHandleMailtoLink: (urlString) => + _onHandleMailtoLink: (event, urlString) => account = AccountStore.current() return unless account diff --git a/src/flux/stores/file-download-store.coffee b/src/flux/stores/file-download-store.coffee index d742c6a0a..082b04c04 100644 --- a/src/flux/stores/file-download-store.coffee +++ b/src/flux/stores/file-download-store.coffee @@ -1,8 +1,7 @@ os = require 'os' fs = require 'fs' -ipc = require 'ipc' path = require 'path' -shell = require 'shell' +{shell} = require 'electron' mkdirp = require 'mkdirp' Utils = require '../models/utils' Reflux = require 'reflux' @@ -211,7 +210,7 @@ FileDownloadStore = Reflux.createStore @_presentError(file) _fetchAndSave: (file) -> - NylasEnv.showSaveDialog @_defaultSavePath(file), (savePath) => + NylasEnv.showSaveDialog {defaultPath: @_defaultSavePath(file)}, (savePath) => return unless savePath @_runDownload(file).then (download) -> stream = fs.createReadStream(download.targetPath) diff --git a/src/flux/stores/file-upload-store.coffee b/src/flux/stores/file-upload-store.coffee index 99c6f6f60..b72184739 100644 --- a/src/flux/stores/file-upload-store.coffee +++ b/src/flux/stores/file-upload-store.coffee @@ -1,5 +1,4 @@ _ = require 'underscore' -ipc = require 'ipc' fs = require 'fs' Reflux = require 'reflux' Actions = require '../actions' diff --git a/src/flux/stores/unread-badge-store.coffee b/src/flux/stores/unread-badge-store.coffee index 6fbb949e4..715af4ff0 100644 --- a/src/flux/stores/unread-badge-store.coffee +++ b/src/flux/stores/unread-badge-store.coffee @@ -61,6 +61,6 @@ class UnreadBadgeStore extends NylasStore # NOTE: Do not underestimate how long this can take. It's a synchronous # remote call and can take ~50+msec. return if NylasEnv.config.get('core.showUnreadBadge') is false - require('ipc').send('set-badge-value', val) + require('electron').ipcRenderer.send('set-badge-value', val) module.exports = new UnreadBadgeStore() diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index 114c8119d..e5594a625 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -1,9 +1,9 @@ path = require 'path' _ = require 'underscore' -ipc = require 'ipc' CSON = require 'season' fs = require 'fs-plus' +{ipcRenderer} = require 'electron' {Disposable} = require 'event-kit' Utils = require './flux/models/utils' @@ -170,7 +170,7 @@ class MenuManager sendToBrowserProcess: (template, keystrokesByCommand) -> keystrokesByCommand = @filterMultipleKeystroke(keystrokesByCommand) - ipc.send 'update-application-menu', template, keystrokesByCommand + ipcRenderer.send 'update-application-menu', template, keystrokesByCommand # Get an {Array} of {String} classes for the given element. classesForElement: (element) -> diff --git a/src/nylas-env.coffee b/src/nylas-env.coffee index 5523aa10c..2bb863099 100644 --- a/src/nylas-env.coffee +++ b/src/nylas-env.coffee @@ -1,9 +1,8 @@ crypto = require 'crypto' -ipc = require 'ipc' os = require 'os' path = require 'path' -remote = require 'remote' -shell = require 'shell' + +{ipcRenderer, remote, shell} = require 'electron' _ = require 'underscore' {deprecate} = require 'grim' @@ -194,10 +193,10 @@ class NylasEnvConstructor extends Model # from needing this crap, which has to be updated every time a new # application: command is added: if event.binding.command.indexOf('application:') is 0 and event.binding.selector.indexOf("body") is 0 - ipc.send('command', event.binding.command) + ipcRenderer.send('command', event.binding.command) unless @inSpecMode() - @actionBridge = new ActionBridge(ipc) + @actionBridge = new ActionBridge(ipcRenderer) @commands = new CommandRegistry specMode = @inSpecMode() @@ -490,7 +489,7 @@ class NylasEnvConstructor extends Model setPosition: (x, y) -> x = ensureInteger(x, 0) y = ensureInteger(y, 0) - ipc.send('call-window-method', 'setPosition', x, y) + ipcRenderer.send('call-window-method', 'setPosition', x, y) # Extended: Get the current window getCurrentWindow: -> @@ -498,32 +497,32 @@ class NylasEnvConstructor extends Model # Extended: Move current window to the center of the screen. center: -> - ipc.send('call-window-method', 'center') + ipcRenderer.send('call-window-method', 'center') # Extended: Focus the current window. focus: -> - ipc.send('call-window-method', 'focus') + ipcRenderer.send('call-window-method', 'focus') window.focus() # Extended: Show the current window. show: -> - ipc.send('call-window-method', 'show') + ipcRenderer.send('call-window-method', 'show') isVisible: -> @getCurrentWindow().isVisible() # Extended: Hide the current window. hide: -> - ipc.send('call-window-method', 'hide') + ipcRenderer.send('call-window-method', 'hide') # Extended: Reload the current window. reload: -> - ipc.send('call-window-method', 'restart') + ipcRenderer.send('call-window-method', 'restart') # Updates the window load settings - called when the app is ready to display # a hot-loaded window. Causes listeners registered with `onWindowPropsReceived` # to receive new window props. - loadSettingsChanged: (loadSettings) => + loadSettingsChanged: (event, loadSettings) => @loadSettings = loadSettings @constructor.loadSettings = loadSettings {width, height, windowProps} = loadSettings @@ -553,10 +552,10 @@ class NylasEnvConstructor extends Model @getCurrentWindow().isMaximized() maximize: -> - ipc.send('call-window-method', 'maximize') + ipcRenderer.send('call-window-method', 'maximize') minimize: -> - ipc.send('call-window-method', 'minimize') + ipcRenderer.send('call-window-method', 'minimize') # Extended: Is the current window in full screen mode? isFullScreen: -> @@ -564,7 +563,7 @@ class NylasEnvConstructor extends Model # Extended: Set the full screen state of the current window. setFullScreen: (fullScreen=false) -> - ipc.send('call-window-method', 'setFullScreen', fullScreen) + ipcRenderer.send('call-window-method', 'setFullScreen', fullScreen) if fullScreen then document.body.classList.add("fullscreen") else document.body.classList.remove("fullscreen") # Extended: Toggle the full screen state of the current window. @@ -658,7 +657,7 @@ class NylasEnvConstructor extends Model @showRootWindow() - ipc.sendChannel('window-command', 'window:loaded') + ipcRenderer.send('window-command', 'window:loaded') showRootWindow: -> cover = document.getElementById("application-loading-cover") @@ -697,27 +696,27 @@ class NylasEnvConstructor extends Model @packages.activate() @keymaps.loadUserKeymap() - ipc.on("load-settings-changed", @loadSettingsChanged) + ipcRenderer.on("load-settings-changed", @loadSettingsChanged) @setWindowDimensions({width, height}) if width and height @menu.update() - ipc.sendChannel('window-command', 'window:loaded') + ipcRenderer.send('window-command', 'window:loaded') # Requests that the backend browser bootup a new window with the given # options. # See the valid option types in Application::newWindow in # src/browser/application.coffee - newWindow: (options={}) -> ipc.send('new-window', options) + newWindow: (options={}) -> ipcRenderer.send('new-window', options) # Registers a hot window for certain packages # See the valid option types in Application::registerHotWindow in # src/browser/application.coffee - registerHotWindow: (options={}) -> ipc.send('register-hot-window', options) + registerHotWindow: (options={}) -> ipcRenderer.send('register-hot-window', options) # Unregisters a hot window with the given windowType - unregisterHotWindow: (windowType) -> ipc.send('unregister-hot-window', windowType) + unregisterHotWindow: (windowType) -> ipcRenderer.send('unregister-hot-window', windowType) saveStateAndUnloadWindow: -> @packages.deactivatePackages() @@ -785,15 +784,15 @@ class NylasEnvConstructor extends Model # Extended: Open the dev tools for the current window. openDevTools: -> - ipc.send('call-window-method', 'openDevTools') + ipcRenderer.send('call-window-method', 'openDevTools') # Extended: Toggle the visibility of the dev tools for the current window. toggleDevTools: -> - ipc.send('call-window-method', 'toggleDevTools') + ipcRenderer.send('call-window-method', 'toggleDevTools') # Extended: Execute code in dev tools. executeJavaScriptInDevTools: (code) -> - ipc.send('call-window-method', 'executeJavaScriptInDevTools', code) + ipcRenderer.send('call-webcontents-method', 'executeJavaScriptInDevTools', code) ### Section: Private @@ -837,11 +836,12 @@ class NylasEnvConstructor extends Model showOpenDialog: (options, callback) -> dialog = remote.require('dialog') - dialog.showOpenDialog(@getCurrentWindow(), options, callback) + callback(dialog.showOpenDialog(@getCurrentWindow(), options)) - showSaveDialog: (defaultPath, callback) -> + showSaveDialog: (options, callback) -> + options.title ?= 'Save File' dialog = remote.require('dialog') - dialog.showSaveDialog(@getCurrentWindow(), {title: 'Save File', defaultPath}, callback) + callback(dialog.showSaveDialog(@getCurrentWindow(), options)) showErrorDialog: (message) -> dialog = remote.require('dialog') @@ -941,4 +941,3 @@ class NylasEnvConstructor extends Model overriddenStop.apply(@, arguments) Event::isPropagationStopped = -> @propagationStopped - diff --git a/src/react-remote/react-remote-child.js b/src/react-remote/react-remote-child.js index 86c0cd340..ecc16ac1e 100644 --- a/src/react-remote/react-remote-child.js +++ b/src/react-remote/react-remote-child.js @@ -1,6 +1,6 @@ var _ = require('underscore') var container = document.getElementById("container"); -var ipc = require('ipc'); +var ipc = require('electron').ipcRenderer; var lastSelectionData = {} document.body.classList.add("platform-"+process.platform); diff --git a/src/react-remote/react-remote-parent.js b/src/react-remote/react-remote-parent.js index 86026d539..ed559594e 100644 --- a/src/react-remote/react-remote-parent.js +++ b/src/react-remote/react-remote-parent.js @@ -1,4 +1,4 @@ -var ipc = require("ipc"); +var ipcRenderer = require("electron").ipcRenderer; var React = require('react'); var _ = require('underscore'); var LinkedValueUtils = require('react/lib/LinkedValueUtils'); @@ -117,7 +117,7 @@ setTimeout(function(){ observeMethod('ReactDOMSelect', 'componentDidMount', Custom.sendSelectCurrentValue); }, 10); -ipc.on('from-react-remote-window', function(json) { +ipcRenderer.on('from-react-remote-window', function(event, json) { var container = null; for (var ii = 0; ii < invocationTargets.length; ii ++) { if (invocationTargets[ii].windowId == json.windowId) { @@ -175,7 +175,7 @@ selectionChange = function() { } // document.addEventListener("selectionchange", selectionChange); -ipc.on('from-react-remote-window-selection', function(selectionData){ +ipcRenderer.on('from-react-remote-window-selection', function(event, selectionData){ document.removeEventListener("selectionchange", selectionChange) restoreSelection(selectionData) document.addEventListener("selectionchange", selectionChange); @@ -248,7 +248,7 @@ var openWindowForComponent = function(Component, options) { resizable: options.resizable, show: false }); - thinWindow.loadUrl(thinWindowUrl); + thinWindow.loadURL(thinWindowUrl); if (process.platform !== 'darwin') { thinWindow.setMenu(null); } diff --git a/src/sheet-toolbar.cjsx b/src/sheet-toolbar.cjsx index 81c380999..e2acddf6b 100644 --- a/src/sheet-toolbar.cjsx +++ b/src/sheet-toolbar.cjsx @@ -28,7 +28,8 @@ class WindowTitle extends React.Component @unlisten = NylasEnv.onWindowPropsReceived (windowProps) => @setState NylasEnv.getLoadSettings() - componentWillUnmount: -> @unlisten() + componentWillUnmount: -> + @unlisten?() render: ->
{@state.title}
diff --git a/src/window-bridge.coffee b/src/window-bridge.coffee index a1e3caa94..3d1593578 100644 --- a/src/window-bridge.coffee +++ b/src/window-bridge.coffee @@ -1,12 +1,12 @@ _ = require 'underscore' -ipc = require 'ipc' +{ipcRenderer} = require 'electron' Utils = require './flux/models/utils' class WindowBridge constructor: -> @_tasks = {} - ipc.on("remote-run-results", @_onResults) - ipc.on("run-in-window", @_onRunInWindow) + ipcRenderer.on("remote-run-results", @_onResults) + ipcRenderer.on("run-in-window", @_onRunInWindow) runInWindow: (window, objectName, methodName, args) -> taskId = Utils.generateTempId() @@ -14,7 +14,7 @@ class WindowBridge @_tasks[taskId] = {resolve, reject} args = Utils.serializeRegisteredObjects(args) params = {window, objectName, methodName, args, taskId} - ipc.send("run-in-window", params) + ipcRenderer.send("run-in-window", params) runInMainWindow: (args...) -> @runInWindow("main", args...) @@ -22,22 +22,22 @@ class WindowBridge runInWorkWindow: -> @runInWindow("work", args...) - _onResults: ({returnValue, taskId}={}) => + _onResults: (event, {returnValue, taskId}={}) => returnValue = Utils.deserializeRegisteredObjects(returnValue) @_tasks[taskId].resolve(returnValue) delete @_tasks[taskId] - _onRunInWindow: ({objectName, methodName, args, taskId}={}) => + _onRunInWindow: (event, {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}) + ipcRenderer.send('remote-run-results', {returnValue, taskId}) else returnValue = result returnValue = Utils.serializeRegisteredObjects(returnValue) - ipc.send('remote-run-results', {returnValue, taskId}) + ipcRenderer.send('remote-run-results', {returnValue, taskId}) module.exports = new WindowBridge diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 9f51373ac..514092cc1 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -2,8 +2,7 @@ path = require 'path' {$} = require './space-pen-extensions' _ = require 'underscore' {Disposable} = require 'event-kit' -ipc = require 'ipc' -shell = require 'shell' +{shell, ipcRenderer} = require 'electron' {Subscriber} = require 'emissary' fs = require 'fs-plus' url = require 'url' @@ -19,7 +18,7 @@ class WindowEventHandler _.defer => @showDevModeMessages() - @subscribe ipc, 'open-path', (pathToOpen) -> + @subscribe ipcRenderer, 'open-path', (event, pathToOpen) -> unless NylasEnv.project?.getPaths().length if fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen)) NylasEnv.project?.setPaths([pathToOpen]) @@ -27,20 +26,20 @@ class WindowEventHandler unless fs.isDirectorySync(pathToOpen) NylasEnv.workspace?.open(pathToOpen, {}) - @subscribe ipc, 'update-available', (detail) -> + @subscribe ipcRenderer, 'update-available', (event, detail) -> NylasEnv.updateAvailable(detail) - @subscribe ipc, 'send-feedback', (detail) -> + @subscribe ipcRenderer, 'send-feedback', (detail) -> Actions = require './flux/actions' Actions.sendFeedback() - @subscribe ipc, 'browser-window-focus', -> + @subscribe ipcRenderer, 'browser-window-focus', -> document.body.classList.remove('is-blurred') - @subscribe ipc, 'browser-window-blur', -> + @subscribe ipcRenderer, 'browser-window-blur', -> document.body.classList.add('is-blurred') - @subscribe ipc, 'command', (command, args...) -> + @subscribe ipcRenderer, 'command', (event, command, args...) -> activeElement = document.activeElement # Use the workspace element view if body has focus if activeElement is document.body and workspaceElement = document.getElementById("nylas-workspace") diff --git a/src/window-thin-bootstrap.coffee b/src/window-thin-bootstrap.coffee index cb7c6b021..9eb7a8faf 100644 --- a/src/window-thin-bootstrap.coffee +++ b/src/window-thin-bootstrap.coffee @@ -1,6 +1,6 @@ path = require('path') fs = require('fs-plus') -ipc = require('ipc') +ipc = require('electron').ipcRenderer require('module').globalPaths.push(path.resolve('exports')) diff --git a/static/index.js b/static/index.js index cb20a600b..55c4a4d2f 100644 --- a/static/index.js +++ b/static/index.js @@ -44,7 +44,7 @@ function setupWindow (loadSettings) { setupCsonCache(CompileCache.getCacheDirectory()) require(loadSettings.bootstrapScript) - require('ipc').sendChannel('window-command', 'window:loaded') + require('electron').ipcRenderer.send('window-command', 'window:loaded') } function setupCsonCache (cacheDir) {