From c7380f77fe20062c0ce3ddb1bac375c247b2319a Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 20 Mar 2016 21:28:53 +0900 Subject: [PATCH] Create reload keybind --- src/utils/ipc-action.js | 42 +++++++++++++++++++++++++++++++++++---- src/utils/menu-builder.js | 15 +++++++------- src/utils/rich-state.js | 10 ++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/utils/ipc-action.js b/src/utils/ipc-action.js index 3e01f04..30b88d1 100644 --- a/src/utils/ipc-action.js +++ b/src/utils/ipc-action.js @@ -1,6 +1,7 @@ import { ipcRenderer } from 'electron'; import Actions from '../actions'; import RichState from './rich-state'; +import TimelineProxy from './timeline-proxy'; import TwitterClient from './twitter-client'; export default class IpcAction { @@ -29,23 +30,21 @@ export default class IpcAction { }); ipcRenderer.on('invoke-retweet', (event) => { - let client = new TwitterClient(this.state.activeAccount()); let active = this.state.activeTweet(); if (!active) return null; if (window.confirm(`Are you sure to retweet?: ${active.text}`)) { - client.retweetStatus(active.id_str, (tweet) => { + this.client().retweetStatus(active.id_str, (tweet) => { this.dispatch(Actions.addTweet(tweet, this.state.activeAccount(), state.activeTab())); }); } }); ipcRenderer.on('invoke-delete', (event) => { - let client = new TwitterClient(this.state.activeAccount()); let active = this.state.activeTweet(); if (!active) return null; - client.deleteStatus(active.id_str, (tweet) => { + this.client().deleteStatus(active.id_str, (tweet) => { this.dispatch(Actions.removeTweet(tweet, this.state.activeAccount(), state.activeTab())); }); }); @@ -73,6 +72,41 @@ export default class IpcAction { this.dispatch(Actions.activateAccount(index)); this.refreshTime(index); }); + + ipcRenderer.on('reload-timeline', (event) => { + let proxy = new TimelineProxy(this.addTweet.bind(this), this.state.activeAccount()); + this.client().homeTimeline((tweets) => { + for (let tweet of tweets) { + proxy.addTweet(tweet); + } + }); + + let listId = this.state.activeListId(); + if (listId) { + this.client().listsStatuses(listId, (tweets) => { + for (let tweet of tweets) { + this.addTweet(tweet, this.state.activeAccount(), 'lists'); + } + }); + } + + let query = this.state.activeSearchQuery(); + if (query) { + this.client().searchTweets(query, (tweets) => { + for (let tweet of tweets) { + this.addTweet(tweet, this.state.activeAccount(), 'search'); + } + }); + } + }); + } + + addTweet(tweet, account, tab) { + this.dispatch(Actions.addTweet(tweet, account, tab)); + } + + client() { + return new TwitterClient(this.state.activeAccount()); } refreshTime(index) { diff --git a/src/utils/menu-builder.js b/src/utils/menu-builder.js index ecae0ba..7b9410a 100644 --- a/src/utils/menu-builder.js +++ b/src/utils/menu-builder.js @@ -36,7 +36,6 @@ export default class MenuBuilder { }, { label: 'View', submenu: (process.env.NODE_ENV === 'development') ? [ - { label: 'Reload', accelerator: 'Command+R', click() { window.restart(); } }, { label: 'Toggle Full Screen', accelerator: 'Ctrl+Command+F', click() { window.setFullScreen(!window.isFullScreen()); } }, { label: 'Toggle Developer Tools', accelerator: 'Alt+Command+I', click() { window.toggleDevTools(); } }, ] : [ @@ -52,10 +51,11 @@ export default class MenuBuilder { }, { label: 'Timeline', submenu: [ + { label: 'Reload', accelerator: 'Command+R', click() { window.webContents.send('reload-timeline') } }, { label: 'Next Tab', accelerator: 'Command+Shift+]', click() { window.webContents.send('select-next-tab') } }, { label: 'Previous Tab', accelerator: 'Command+Shift+[', click() { window.webContents.send('select-prev-tab') } }, - { label: 'Next Account', accelerator: 'Command+J', click() { window.webContents.send('select-next-account') } }, - { label: 'Previous Account', accelerator: 'Command+K', click() { window.webContents.send('select-prev-account') } }, + { label: 'Next Account', accelerator: 'Command+J', click() { window.webContents.send('select-next-account') } }, + { label: 'Previous Account', accelerator: 'Command+K', click() { window.webContents.send('select-prev-account') } }, ], }, { label: 'Window', @@ -98,10 +98,11 @@ export default class MenuBuilder { }, { label: 'Timeline', submenu: [ - { label: 'Next Tab', accelerator: 'Alt+P', click() { window.webContents.send('select-next-tab') } }, - { label: 'Previous Tab', accelerator: 'Alt+O', click() { window.webContents.send('select-prev-tab') } }, - { label: 'Next Account', accelerator: 'Alt+J', click() { window.webContents.send('select-next-account') } }, - { label: 'Previous Account', accelerator: 'Alt+K', click() { window.webContents.send('select-prev-account') } }, + { label: 'Reload', accelerator: 'Ctrl+R', click() { window.webContents.send('reload-timeline') } }, + { label: 'Next Tab', accelerator: 'Alt+P', click() { window.webContents.send('select-next-tab') } }, + { label: 'Previous Tab', accelerator: 'Alt+O', click() { window.webContents.send('select-prev-tab') } }, + { label: 'Next Account', accelerator: 'Alt+J', click() { window.webContents.send('select-next-account') } }, + { label: 'Previous Account', accelerator: 'Alt+K', click() { window.webContents.send('select-prev-account') } }, ], }, this.helpMenu(), diff --git a/src/utils/rich-state.js b/src/utils/rich-state.js index c38dcce..7f20312 100644 --- a/src/utils/rich-state.js +++ b/src/utils/rich-state.js @@ -13,6 +13,16 @@ export default class RichState { return this.activeTabCache = (this.state.selectedTabByUserId[this.activeAccount().id_str] || 'home'); } + activeListId() { + return this.activeAccount() && + this.state.activeListIdByUserId[this.activeAccount().id_str]; + } + + activeSearchQuery() { + return this.activeAccount() && + this.state.searchQueryByUserId[this.activeAccount().id_str]; + } + nextTab() { return { home: 'mentions',