From 07e810a23181ea1b82271389a44793b919b5bbcf Mon Sep 17 00:00:00 2001 From: Mika Andrianarijaona Date: Wed, 22 Aug 2018 10:58:53 +0200 Subject: [PATCH 1/3] init touchbar menu --- lib/main-app.js | 2 ++ lib/touchbar-menu.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 lib/touchbar-menu.js diff --git a/lib/main-app.js b/lib/main-app.js index 1f3f1320..1ab9f4ca 100644 --- a/lib/main-app.js +++ b/lib/main-app.js @@ -78,9 +78,11 @@ app.on('ready', function () { var template = require('./main-menu') var menu = Menu.buildFromTemplate(template) + var touchBarMenu = require('./touchbar-menu') switch (process.platform) { case 'darwin': Menu.setApplicationMenu(menu) + mainWindow.setTouchBar(touchBarMenu) break case 'win32': mainWindow.setMenu(menu) diff --git a/lib/touchbar-menu.js b/lib/touchbar-menu.js new file mode 100644 index 00000000..bb7ae79a --- /dev/null +++ b/lib/touchbar-menu.js @@ -0,0 +1,26 @@ +const {TouchBar} = require('electron') +const {TouchBarButton, TouchBarSpacer} = TouchBar + +const allNotes = new TouchBarButton({ + label: '📒', + click: () => {} +}) + +const starredNotes = new TouchBarButton({ + label: '⭐️', + click: () => {} +}) + +const trash = new TouchBarButton({ + label: '🗑', + click: () => {} +}) + +module.exports = new TouchBar([ + allNotes, + new TouchBarSpacer({size: 'small'}), + starredNotes, + new TouchBarSpacer({size: 'small'}), + trash +]) + From 64d4cd84afdc644ecd25200600b23c037ccd8a89 Mon Sep 17 00:00:00 2001 From: Mika Andrianarijaona Date: Wed, 22 Aug 2018 18:09:55 +0200 Subject: [PATCH 2/3] send events when user click touchbar buttons --- browser/main/NoteList/index.js | 12 ++++++++++++ lib/touchbar-menu.js | 24 ++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index f7dd0764..880f8479 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -80,6 +80,7 @@ class NoteList extends React.Component { this.getViewType = this.getViewType.bind(this) this.restoreNote = this.restoreNote.bind(this) this.copyNoteLink = this.copyNoteLink.bind(this) + this.navigate = this.navigate.bind(this) // TODO: not Selected noteKeys but SelectedNote(for reusing) this.state = { @@ -98,6 +99,7 @@ class NoteList extends React.Component { ee.on('list:isMarkdownNote', this.alertIfSnippetHandler) ee.on('import:file', this.importFromFileHandler) ee.on('list:jump', this.jumpNoteByHash) + ee.on('list:navigate', this.navigate) } componentWillReceiveProps (nextProps) { @@ -687,6 +689,16 @@ class NoteList extends React.Component { return copy(noteLink) } + navigate (sender, pathname) { + const { router } = this.context + router.push({ + pathname, + query: { + // key: noteKey + } + }) + } + save (note) { const { dispatch } = this.props dataApi diff --git a/lib/touchbar-menu.js b/lib/touchbar-menu.js index bb7ae79a..fa2fae9e 100644 --- a/lib/touchbar-menu.js +++ b/lib/touchbar-menu.js @@ -1,19 +1,33 @@ const {TouchBar} = require('electron') const {TouchBarButton, TouchBarSpacer} = TouchBar +const mainWindow = require('./main-window') const allNotes = new TouchBarButton({ label: '📒', - click: () => {} + click: () => { + mainWindow.webContents.send('list:navigate', '/home') + } }) const starredNotes = new TouchBarButton({ label: '⭐️', - click: () => {} + click: () => { + mainWindow.webContents.send('list:navigate', '/starred') + } }) const trash = new TouchBarButton({ label: '🗑', - click: () => {} + click: () => { + mainWindow.webContents.send('list:navigate', '/trashed') + } +}) + +const newNote = new TouchBarButton({ + label: '✎', + click: () => { + mainWindow.webContents.send('top:new-note') + } }) module.exports = new TouchBar([ @@ -21,6 +35,8 @@ module.exports = new TouchBar([ new TouchBarSpacer({size: 'small'}), starredNotes, new TouchBarSpacer({size: 'small'}), - trash + trash, + new TouchBarSpacer({size: 'large'}), + newNote ]) From a19c13eb3c4bac65386073a097877e13b8f4b8f5 Mon Sep 17 00:00:00 2001 From: Mika Andrianarijaona Date: Wed, 22 Aug 2018 18:14:31 +0200 Subject: [PATCH 3/3] remove unused spacing --- lib/touchbar-menu.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/touchbar-menu.js b/lib/touchbar-menu.js index fa2fae9e..90a64410 100644 --- a/lib/touchbar-menu.js +++ b/lib/touchbar-menu.js @@ -26,17 +26,16 @@ const trash = new TouchBarButton({ const newNote = new TouchBarButton({ label: '✎', click: () => { + mainWindow.webContents.send('list:navigate', '/home') mainWindow.webContents.send('top:new-note') } }) module.exports = new TouchBar([ allNotes, - new TouchBarSpacer({size: 'small'}), starredNotes, - new TouchBarSpacer({size: 'small'}), trash, - new TouchBarSpacer({size: 'large'}), + new TouchBarSpacer({size: 'small'}), newNote ])