From ef5025d41f3ad223252ea297e7e67b16618e7134 Mon Sep 17 00:00:00 2001 From: Sander Steenhuis Date: Sun, 11 Feb 2018 19:35:02 +0100 Subject: [PATCH 1/7] Add tray icon with <=10 last updated notes --- browser/main/NoteList/index.js | 1 + browser/main/lib/eventEmitter.js | 7 ++++- lib/main-window.js | 53 ++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 30317095f..e946f682e 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -109,6 +109,7 @@ class NoteList extends React.Component { componentDidUpdate (prevProps) { const { location } = this.props + ee.emitIpc('tray:update', _.sortBy(this.notes, note => new Date(note.updatedAt).getTime()).reverse().slice(0, 10)) if (this.notes.length > 0 && location.query.key == null) { const { router } = this.context diff --git a/browser/main/lib/eventEmitter.js b/browser/main/lib/eventEmitter.js index de08f0784..92ee5570e 100644 --- a/browser/main/lib/eventEmitter.js +++ b/browser/main/lib/eventEmitter.js @@ -18,9 +18,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/lib/main-window.js b/lib/main-window.js index 573f41cf9..709e7c7f8 100644 --- a/lib/main-window.js +++ b/lib/main-window.js @@ -1,11 +1,12 @@ const electron = require('electron') -const app = electron.app -const BrowserWindow = electron.BrowserWindow +const { app, BrowserWindow, Menu, MenuItem, Tray, ipcMain } = electron const path = require('path') const Config = require('electron-config') const config = new Config() const _ = require('lodash') +const manifest = require('../package.json') +var menu var showMenu = process.platform !== 'win32' const windowSize = config.get('windowsize') || { width: 1080, height: 720 } @@ -77,4 +78,52 @@ app.on('activate', function () { mainWindow.show() }) +ipcMain.on('tray:update', function (e, notes) { + updateTray(notes) +}) + +function updateTray (notes) { + const menu = new Menu() + + menu.append(new MenuItem({ + label: 'Open Boostnote', + click: function () { + mainWindow.show() + } + })) + + if (notes && notes.length) { + menu.append(new MenuItem({type: 'separator'})) + notes.forEach(note => { + menu.append(new MenuItem({ + label: note.title, + click: function () { + mainWindow.webContents.send('list:jump', `${note.storage}-${note.key}`) + mainWindow.show() + } + })) + }) + menu.append(new MenuItem({type: 'separator'})) + } + + menu.append(new MenuItem({ + label: 'Quit', + click: function () { + app.quit() + } + })) + + tray.setContextMenu(menu) + + return menu +} + +const tray = new Tray(path.join(__dirname, '../resources/tray-icon-dark@2x.png')) +menu = updateTray() +tray.setToolTip(`${manifest.productName} ${manifest.version}`) +tray.on('click', function (e) { + e.preventDefault() + tray.popUpContextMenu(menu) +}) + module.exports = mainWindow From 44a41b18ff31fdb6bdf0bd3fb793d4fe7d362e6c Mon Sep 17 00:00:00 2001 From: Sander Steenhuis Date: Sun, 11 Feb 2018 19:50:18 +0100 Subject: [PATCH 2/7] Add version --- lib/main-window.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/main-window.js b/lib/main-window.js index 709e7c7f8..57dc14568 100644 --- a/lib/main-window.js +++ b/lib/main-window.js @@ -5,6 +5,7 @@ const Config = require('electron-config') const config = new Config() const _ = require('lodash') const manifest = require('../package.json') +const product = `${manifest.productName} ${manifest.version}` var menu var showMenu = process.platform !== 'win32' @@ -86,7 +87,7 @@ function updateTray (notes) { const menu = new Menu() menu.append(new MenuItem({ - label: 'Open Boostnote', + label: `Open ${product}`, click: function () { mainWindow.show() } @@ -120,7 +121,7 @@ function updateTray (notes) { const tray = new Tray(path.join(__dirname, '../resources/tray-icon-dark@2x.png')) menu = updateTray() -tray.setToolTip(`${manifest.productName} ${manifest.version}`) +tray.setToolTip(product) tray.on('click', function (e) { e.preventDefault() tray.popUpContextMenu(menu) From 548fd248ea114be479765defd0d049e9e96c4a7c Mon Sep 17 00:00:00 2001 From: Sander Steenhuis Date: Thu, 15 Feb 2018 20:24:28 +0100 Subject: [PATCH 3/7] Add option to quit on main window close --- browser/main/Main.js | 11 ++++++ browser/main/lib/ConfigManager.js | 1 + browser/main/modals/PreferencesModal/UiTab.js | 12 ++++++ lib/main-window.js | 39 ++++++++++++------- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/browser/main/Main.js b/browser/main/Main.js index f9be60856..63119ad08 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -40,6 +40,7 @@ class Main extends React.Component { } this.toggleFullScreen = () => this.handleFullScreenButton() + this.probeTrayClose = () => this.handleTrayCloseProbe() } getChildContext () { @@ -164,10 +165,12 @@ class Main extends React.Component { }) eventEmitter.on('editor:fullscreen', this.toggleFullScreen) + eventEmitter.on('tray:probe-close', this.probeTrayClose) } componentWillUnmount () { eventEmitter.off('editor:fullscreen', this.toggleFullScreen) + eventEmitter.off('tray:probe-close', this.probeTrayClose) } handleLeftSlideMouseDown (e) { @@ -258,6 +261,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/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index fde7dafdd..54fff3471 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -22,6 +22,7 @@ export const DEFAULT_CONFIG = { }, ui: { theme: 'default', + closeToTray: true, showCopyNotification: true, disableDirectWrite: false, defaultNote: 'ALWAYS_ASK' // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE' diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index df35e2608..eeacea893 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -61,6 +61,7 @@ class UiTab extends React.Component { const newConfig = { ui: { theme: this.refs.uiTheme.value, + closeToTray: this.refs.closeToTray.checked, showCopyNotification: this.refs.showCopyNotification.checked, confirmDeletion: this.refs.confirmDeletion.checked, disableDirectWrite: this.refs.uiD2w != null @@ -201,6 +202,17 @@ class UiTab extends React.Component { : null } +
+ +
+
Editor
diff --git a/lib/main-window.js b/lib/main-window.js index 57dc14568..8fabb7664 100644 --- a/lib/main-window.js +++ b/lib/main-window.js @@ -42,8 +42,8 @@ mainWindow.webContents.sendInputEvent({ keyCode: '\u0008' }) -if (process.platform === 'darwin' || process.env.DESKTOP_SESSION === 'cinnamon') { - mainWindow.on('close', function (e) { +mainWindow.on('close', function (e) { + if (process.platform === 'darwin' || process.env.DESKTOP_SESSION === 'cinnamon') { e.preventDefault() if (mainWindow.isFullScreen()) { mainWindow.once('leave-full-screen', function () { @@ -53,16 +53,19 @@ if (process.platform === 'darwin' || process.env.DESKTOP_SESSION === 'cinnamon') } else { mainWindow.hide() } - }) - - app.on('before-quit', function (e) { - mainWindow.removeAllListeners() - }) -} else { - app.on('window-all-closed', function () { - app.quit() - }) -} + } + + mainWindow.webContents.send('tray:probe-close') +}) + +app.on('before-quit', function (e) { + mainWindow.removeAllListeners() +}) + +app.on('window-all-closed', function () { + app.quit() +}) + mainWindow.on('resize', _.throttle(storeWindowSize, 500)) function storeWindowSize () { @@ -79,10 +82,18 @@ app.on('activate', function () { mainWindow.show() }) -ipcMain.on('tray:update', function (e, notes) { - updateTray(notes) +ipcMain.on('tray:update', handleTrayUpdate) + +ipcMain.on('tray:quit', function (e, notes) { + ipcMain.removeListener('tray:update', handleTrayUpdate) + menu = null + app.quit() }) +function handleTrayUpdate (e, notes) { + updateTray(notes) +} + function updateTray (notes) { const menu = new Menu() From ec205a081ef6d4205b5c619f65695eae74057aa7 Mon Sep 17 00:00:00 2001 From: Sander Steenhuis Date: Fri, 16 Feb 2018 13:56:21 +0100 Subject: [PATCH 4/7] Update boostnoterc.all for test --- tests/lib/boostnoterc/.boostnoterc.all | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/boostnoterc/.boostnoterc.all b/tests/lib/boostnoterc/.boostnoterc.all index 8419061df..3212583ea 100644 --- a/tests/lib/boostnoterc/.boostnoterc.all +++ b/tests/lib/boostnoterc/.boostnoterc.all @@ -24,6 +24,7 @@ }, "sortBy": "UPDATED_AT", "ui": { + "closeToTray": false, "defaultNote": "ALWAYS_ASK", "disableDirectWrite": false, "theme": "default" From 441041db23835b5800c6323f8599cc6e22f44d3c Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Mon, 1 Jul 2019 22:47:25 +0200 Subject: [PATCH 5/7] fix navigation & fix linting --- lib/main-window.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/main-window.js b/lib/main-window.js index 8d511a96d..cb3094eb5 100644 --- a/lib/main-window.js +++ b/lib/main-window.js @@ -8,7 +8,6 @@ const manifest = require('../package.json') const product = `${manifest.productName} ${manifest.version}` var menu -var showMenu = process.platform !== 'win32' // set up some chrome extensions if (process.env.NODE_ENV === 'development') { const { @@ -145,7 +144,7 @@ function updateTray (notes) { menu.append(new MenuItem({ label: note.title, click: function () { - mainWindow.webContents.send('list:jump', `${note.storage}-${note.key}`) + mainWindow.webContents.send('list:jump', note.key) mainWindow.show() } })) From 3c3d250a6acfa33eaff5da8fc002cc249d9c17e4 Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Wed, 3 Jul 2019 22:57:13 +0200 Subject: [PATCH 6/7] change tray menu creation to show recently updated across storages --- browser/main/NoteList/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index c4eb3775a..3ead47d1f 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -146,7 +146,7 @@ class NoteList extends React.Component { } componentDidUpdate (prevProps) { - const { dispatch, location } = this.props + const { data, dispatch, location } = this.props const { selectedNoteKeys } = this.state const visibleNoteKeys = this.notes && this.notes.map(note => note.key) const note = this.notes && this.notes[0] @@ -154,7 +154,7 @@ 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)) + ee.emitIpc('tray:update', data.noteMap.map((note) => note).sort(sortByUpdatedAt).slice(0, 10).filter(note => note.title !== '')) if (note && location.search === '') { if (!location.pathname.match(/\/searched/)) this.contextNotes = this.getContextNotes() From d314a3a233c95220fe3e94c44e2c90966a16975b Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Sun, 28 Jul 2019 23:43:18 +0200 Subject: [PATCH 7/7] Show only not trashed notes in the tray menu --- browser/main/NoteList/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index ef3c40314..0cf2f4f59 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -154,7 +154,7 @@ 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', data.noteMap.map((note) => note).sort(sortByUpdatedAt).slice(0, 10).filter(note => note.title !== '')) + ee.emitIpc('tray:update', data.noteMap.map((note) => note).sort(sortByUpdatedAt).slice(0, 10).filter(note => note.title !== '' && !note.isTrashed)) if (note && location.search === '') { if (!location.pathname.match(/\/searched/)) this.contextNotes = this.getContextNotes()