diff --git a/browser/main/Main.js b/browser/main/Main.js index 30bf8e8af..f8c63709a 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -42,6 +42,7 @@ class Main extends React.Component { } this.toggleFullScreen = () => this.handleFullScreenButton() + this.probeTrayClose = () => this.handleTrayCloseProbe() } getChildContext () { @@ -172,11 +173,13 @@ class Main extends React.Component { delete CodeMirror.keyMap.emacs['Ctrl-V'] eventEmitter.on('editor:fullscreen', this.toggleFullScreen) + eventEmitter.on('tray:probe-close', this.probeTrayClose) eventEmitter.on('menubar:togglemenubar', this.toggleMenuBarVisible.bind(this)) } componentWillUnmount () { eventEmitter.off('editor:fullscreen', this.toggleFullScreen) + eventEmitter.off('tray:probe-close', this.probeTrayClose) eventEmitter.off('menubar:togglemenubar', this.toggleMenuBarVisible.bind(this)) } @@ -283,6 +286,14 @@ class Main extends React.Component { }) } + handleTrayCloseProbe (e) { + const { config } = this.props + if (!config.ui.closeToTray) { + // console.log('handleTrayClose') + eventEmitter.emitIpc('tray:quit') + } + } + hideLeftLists (noteDetail, noteList, mainBody) { this.setState({ noteDetailWidth: noteDetail.style.left }) this.setState({ mainBodyWidth: mainBody.style.left }) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index a146cb6c7..c4eb3775a 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -154,6 +154,8 @@ class NoteList extends React.Component { const prevKey = prevProps.location.search && queryString.parse(prevProps.location.search).key const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && note.key + ee.emitIpc('tray:update', _.sortBy(this.notes, note => new Date(note.updatedAt).getTime()).reverse().slice(0, 10)) + if (note && location.search === '') { if (!location.pathname.match(/\/searched/)) this.contextNotes = this.getContextNotes() diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index bea019fa9..b8be42744 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -36,6 +36,7 @@ export const DEFAULT_CONFIG = { ui: { language: 'en', theme: 'default', + closeToTray: true, showCopyNotification: true, disableDirectWrite: false, defaultNote: 'ALWAYS_ASK', // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE' diff --git a/browser/main/lib/eventEmitter.js b/browser/main/lib/eventEmitter.js index 1276545b0..f527100b4 100644 --- a/browser/main/lib/eventEmitter.js +++ b/browser/main/lib/eventEmitter.js @@ -17,9 +17,14 @@ function emit (name, ...args) { remote.getCurrentWindow().webContents.send(name, ...args) } +function emitIpc (name, ...args) { + ipcRenderer.send(name, ...args) +} + export default { emit, on, off, - once + once, + emitIpc } diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index f74dbda52..59e7b3ab2 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -68,6 +68,7 @@ class UiTab extends React.Component { const newConfig = { ui: { theme: this.refs.uiTheme.value, + closeToTray: this.refs.closeToTray.checked, language: this.refs.uiLanguage.value, defaultNote: this.refs.defaultNote.value, tagNewNoteWithFilteringTags: this.refs.tagNewNoteWithFilteringTags.checked, @@ -293,6 +294,16 @@ class UiTab extends React.Component { : null } +