Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Create reload keybind
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 20, 2016
1 parent 4902a59 commit c7380f7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
42 changes: 38 additions & 4 deletions src/utils/ipc-action.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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()));
});
});
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions src/utils/menu-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); } },
] : [
Expand All @@ -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',
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 10 additions & 0 deletions src/utils/rich-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c7380f7

Please sign in to comment.