2015-11-24 04:20:51 +08:00
|
|
|
React = require 'react'
|
|
|
|
{RetinaImg, Flexbox} = require 'nylas-component-kit'
|
|
|
|
{LaunchServices, AccountStore} = require 'nylas-exports'
|
|
|
|
ConfigSchemaItem = require './config-schema-item'
|
|
|
|
|
|
|
|
class DefaultMailClientItem extends React.Component
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = {}
|
|
|
|
@_services = new LaunchServices()
|
|
|
|
if @_services.available()
|
|
|
|
@_services.isRegisteredForURLScheme 'mailto', (registered) =>
|
|
|
|
@setState(defaultClient: registered)
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
return false unless process.platform is 'darwin'
|
|
|
|
<div className="item">
|
|
|
|
<input type="checkbox" id="default-client" checked={@state.defaultClient} onChange={@toggleDefaultMailClient}/>
|
|
|
|
<label htmlFor="default-client">Use Nylas as my default mail client</label>
|
|
|
|
</div>
|
|
|
|
|
2015-12-01 05:39:42 +08:00
|
|
|
toggleDefaultMailClient: (event) =>
|
2015-11-24 04:20:51 +08:00
|
|
|
if @state.defaultClient is true
|
|
|
|
@setState(defaultClient: false)
|
|
|
|
@_services.resetURLScheme('mailto')
|
|
|
|
else
|
|
|
|
@setState(defaultClient: true)
|
|
|
|
@_services.registerForURLScheme('mailto')
|
2015-12-01 05:39:42 +08:00
|
|
|
event.target.blur()
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
class AppearanceModeSwitch extends React.Component
|
|
|
|
@displayName: 'AppearanceModeSwitch'
|
|
|
|
@propTypes:
|
|
|
|
config: React.PropTypes.object.isRequired
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = {
|
|
|
|
value: @props.config.get('core.workspace.mode')
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps: (nextProps) ->
|
|
|
|
@setState({
|
|
|
|
value: nextProps.config.get('core.workspace.mode')
|
|
|
|
})
|
|
|
|
|
|
|
|
render: ->
|
|
|
|
hasChanges = @state.value isnt @props.config.get('core.workspace.mode')
|
|
|
|
applyChangesClass = "btn btn-small"
|
|
|
|
applyChangesClass += " btn-disabled" unless hasChanges
|
|
|
|
|
|
|
|
<div className="appearance-mode-switch">
|
|
|
|
<Flexbox
|
|
|
|
direction="row"
|
|
|
|
style={alignItems: "center"}
|
|
|
|
className="item">
|
|
|
|
{@_renderModeOptions()}
|
|
|
|
</Flexbox>
|
|
|
|
<div className={applyChangesClass} onClick={@_onApplyChanges}>Apply Changes</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderModeOptions: ->
|
|
|
|
['list', 'split'].map (mode) =>
|
|
|
|
<AppearanceModeOption
|
|
|
|
mode={mode}
|
|
|
|
key={mode}
|
|
|
|
active={@state.value is mode}
|
|
|
|
onClick={ => @setState(value: mode) } />
|
|
|
|
|
|
|
|
_onApplyChanges: =>
|
|
|
|
@props.config.set('core.workspace.mode', @state.value)
|
|
|
|
|
|
|
|
|
|
|
|
class AppearanceModeOption extends React.Component
|
|
|
|
@propTypes:
|
|
|
|
mode: React.PropTypes.string.isRequired
|
|
|
|
active: React.PropTypes.bool
|
|
|
|
onClick: React.PropTypes.func
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
classname = "appearance-mode"
|
|
|
|
classname += " active" if @props.active
|
2015-11-24 09:34:56 +08:00
|
|
|
|
|
|
|
label = {
|
|
|
|
'list': 'Single Panel'
|
|
|
|
'split': 'Two Panel'
|
|
|
|
}[@props.mode]
|
|
|
|
|
2015-11-24 04:20:51 +08:00
|
|
|
<div className={classname} onClick={@props.onClick}>
|
|
|
|
<RetinaImg name={"appearance-mode-#{@props.mode}.png"} mode={RetinaImg.Mode.ContentIsMask}/>
|
2015-11-24 09:34:56 +08:00
|
|
|
<div>{label}</div>
|
2015-11-24 04:20:51 +08:00
|
|
|
</div>
|
|
|
|
|
2015-12-16 01:54:59 +08:00
|
|
|
class ThemeSelector extends React.Component
|
|
|
|
constructor: (@props) ->
|
|
|
|
@_themeManager = NylasEnv.themes
|
|
|
|
@state = @_getState()
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@disposable = @_themeManager.onDidChangeActiveThemes =>
|
|
|
|
@setState @_getState()
|
|
|
|
|
|
|
|
componentWillUnmount: ->
|
|
|
|
@disposable.dispose()
|
|
|
|
|
|
|
|
_getState: =>
|
|
|
|
themes: @_themeManager.getLoadedThemes()
|
|
|
|
activeTheme: @_themeManager.getActiveTheme().name
|
|
|
|
|
|
|
|
_setActiveTheme: (theme) =>
|
|
|
|
@setState activeTheme: theme
|
|
|
|
@_themeManager.setActiveTheme theme
|
|
|
|
|
|
|
|
_onChangeTheme: (event) =>
|
|
|
|
value = event.target.value
|
|
|
|
if value is 'install'
|
|
|
|
NylasEnv.commands.dispatch document.body, 'application:install-package'
|
|
|
|
else
|
|
|
|
@_setActiveTheme(value)
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
<div className="item">
|
|
|
|
<span>Select theme: </span>
|
|
|
|
<select value={@state.activeTheme} onChange={@_onChangeTheme}>
|
|
|
|
{@state.themes.map (theme) ->
|
|
|
|
<option key={theme.name} value={theme.name}>{theme.displayName}</option>}
|
|
|
|
<option value="install">Install a theme...</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
|
2015-11-24 04:20:51 +08:00
|
|
|
class WorkspaceSection extends React.Component
|
|
|
|
@displayName: 'WorkspaceSection'
|
|
|
|
@propTypes:
|
|
|
|
config: React.PropTypes.object
|
|
|
|
configSchema: React.PropTypes.object
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
<section>
|
|
|
|
<h2>Workspace</h2>
|
|
|
|
<DefaultMailClientItem />
|
|
|
|
|
|
|
|
<ConfigSchemaItem
|
|
|
|
configSchema={@props.configSchema.properties.workspace.properties.systemTray}
|
|
|
|
keyPath="core.workspace.systemTray"
|
|
|
|
config={@props.config} />
|
|
|
|
|
|
|
|
<ConfigSchemaItem
|
|
|
|
configSchema={@props.configSchema.properties.workspace.properties.showImportant}
|
|
|
|
keyPath="core.workspace.showImportant"
|
|
|
|
config={@props.config} />
|
|
|
|
|
feat(counts): Unread counts for all folders and labels across all accounts
Summary:
This diff replaces the UnreadCountStore with a better approach that is able to track unread counts for all folders/labels without continuous (and cripplingly slow) SELECT COUNT(*) queries.
When models are written to the database, we currently don't send out notifications with the "previous" state of those objects in the database. This makes it hard to determine how to update counters. (In the future, we may need to do this for live queries). Unfortunately, getting the "previous" state is going to be very hard, because multiple windows write to the database and the "previous" state we have might be outdated. We'd almost have to run a "SELECT" right before every "REPLACE INTO".
I created an API that allows you to register observers around persistModel and unpersistModel. With this API, you can run queries before and after the database changes are made and pluck just the "before" state you're interested in.
The `ThreadCountsStore` uses this API to determine the impact of persisting a set of threads on the unread counts of different labels. Before the threads are saved, it says "how much do these thread IDs contribute to unread counts currently?". After the write is complete it looks at the models and computes the difference between the old count impact and the new count impact, and updates the counters.
I decided not to attach the unread count to the Label objects themselves because 1) they update frequently and 2) most things observing the DatabaseStore for categories do not care about counts, so they would be updating unnecessarily.
The AccountSidebar now listens to the ThreadCountsStore as well as the CategoryStore, and there's a new preference in the General tab for turning off the counts.
Test Plan: Tests are a work in progress, want to get feedback first!
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2232
2015-11-24 09:12:22 +08:00
|
|
|
<ConfigSchemaItem
|
|
|
|
configSchema={@props.configSchema.properties.workspace.properties.showUnreadForAllCategories}
|
|
|
|
keyPath="core.workspace.showUnreadForAllCategories"
|
|
|
|
config={@props.config} />
|
|
|
|
|
2016-01-09 03:30:58 +08:00
|
|
|
<ConfigSchemaItem
|
|
|
|
configSchema={@props.configSchema.properties.workspace.properties.interfaceZoom}
|
|
|
|
keyPath="core.workspace.interfaceZoom"
|
|
|
|
config={@props.config} />
|
|
|
|
|
2015-12-16 01:54:59 +08:00
|
|
|
<ThemeSelector />
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
<h2>Layout</h2>
|
|
|
|
|
|
|
|
<AppearanceModeSwitch config={@props.config} />
|
|
|
|
</section>
|
|
|
|
|
|
|
|
module.exports = WorkspaceSection
|