refs #28 Catch menu and shortcut events

This commit is contained in:
AkiraFukushima 2018-03-13 01:00:19 +09:00
parent 7326710d2a
commit dc025d03ed
3 changed files with 49 additions and 2 deletions

View File

@ -1,6 +1,6 @@
'use strict'
import { app, ipcMain, BrowserWindow, shell } from 'electron'
import { app, ipcMain, BrowserWindow, shell, Menu } from 'electron'
import Datastore from 'nedb'
import storage from 'electron-json-storage'
import empty from 'is-empty'
@ -28,6 +28,39 @@ let db = new Datastore({
})
function createWindow () {
/**
* Set menu
*/
const template = [
{
label: 'Toot',
submenu: [
{
label: 'New Toot',
accelerator: 'CmdOrCtrl+N',
role: 'toot',
click: () => {
mainWindow.webContents.send('CmdOrCtrl+N')
}
},
{
type: 'separator'
},
{
label: 'Reply',
accelerator: 'CmdOrCtrl+R',
role: 'reply',
click: () => {
mainWindow.webContents.send('CmdOrCtrl+R')
}
}
]
}
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
/**
* Initial window options
*/

View File

@ -20,6 +20,7 @@ export default {
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/username', account)
this.$store.dispatch('TimelineSpace/fetchNotifications', account)
this.$store.dispatch('TimelineSpace/watchShortcutEvents', account)
})
.catch(() => {
this.$message({

View File

@ -14,7 +14,8 @@ const TimelineSpace = {
},
username: '',
homeTimeline: [],
notifications: []
notifications: [],
newTootModal: false
},
mutations: {
updateAccount (state, account) {
@ -34,6 +35,9 @@ const TimelineSpace = {
},
insertNotifications (state, notifications) {
state.notifications = state.notifications.concat(notifications)
},
changeNewTootModal (state, modal) {
state.newTootModal = modal
}
},
actions: {
@ -82,6 +86,15 @@ const TimelineSpace = {
stopUserStreaming ({ commit }) {
ipcRenderer.send('stop-user-streaming')
},
watchShortcutEvents ({ commit }, account) {
ipcRenderer.on('CmdOrCtrl+N', () => {
console.log('new toot')
commit('changeNewTootModal', true)
})
ipcRenderer.on('CmdOrCtrl+R', () => {
console.log('reply')
})
},
fetchHomeTimeline ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(