Mailspring/internal_packages/composer/lib/main.cjsx
Ben Gotow a37e567888 fix(window-serialization): Restore window size, remove cruft from atom.coffee
Summary: Simplify the default window size, restore window size when the main window is loaded, fix serialization of packages in beforeunload.

Test Plan: Run tests

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2061
2015-09-24 10:40:38 -07:00

72 lines
1.9 KiB
CoffeeScript

_ = require 'underscore'
React = require 'react'
{AccountStore,
DatabaseStore,
Message,
ComponentRegistry,
WorkspaceStore} = require('nylas-exports')
ComposeButton = require('./compose-button')
ComposerView = require('./composer-view')
class ComposerWithWindowProps extends React.Component
@displayName: 'ComposerWithWindowProps'
@containerRequired: false
constructor: (@props) ->
@state = atom.getWindowProps()
componentDidMount: ->
@unlisten = atom.onWindowPropsReceived (windowProps) =>
{errorMessage} = windowProps
@setState(windowProps)
if errorMessage
@_showInitialErrorDialog(errorMessage)
componentWillUnmount: ->
@unlisten?()
render: ->
<div className="composer-full-window">
<ComposerView mode="fullwindow" draftClientId={@state.draftClientId} />
</div>
_showInitialErrorDialog: (msg) ->
remote = require('remote')
dialog = remote.require('dialog')
dialog.showMessageBox remote.getCurrentWindow(), {
type: 'warning'
buttons: ['Okay'],
message: "Error"
detail: msg
}
module.exports =
activate: (@state={}) ->
atom.registerHotWindow
windowType: 'composer'
replenishNum: 2
# Register our composer as the app-wide Composer
ComponentRegistry.register ComposerView,
role: 'Composer'
if atom.isMainWindow()
ComponentRegistry.register ComposeButton,
location: WorkspaceStore.Location.RootSidebar.Toolbar
else
atom.getCurrentWindow().setMinimumSize(480, 400)
WorkspaceStore.defineSheet 'Main', {root: true},
popout: ['Center']
ComponentRegistry.register ComposerWithWindowProps,
location: WorkspaceStore.Location.Center
deactivate: ->
atom.unregisterHotWindow('composer')
ComponentRegistry.unregister(ComposerView)
ComponentRegistry.unregister(ComposeButton)
ComponentRegistry.unregister(ComposerWithWindowProps)
serialize: -> @state