diff --git a/src/main/index.js b/src/main/index.js index 235811d1..6e520a30 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -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 */ diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue index 26694288..e1820bf0 100644 --- a/src/renderer/components/TimelineSpace.vue +++ b/src/renderer/components/TimelineSpace.vue @@ -4,15 +4,17 @@
+ diff --git a/src/renderer/components/TimelineSpace/NewTootModal.vue b/src/renderer/components/TimelineSpace/NewTootModal.vue new file mode 100644 index 00000000..f9c2c9a8 --- /dev/null +++ b/src/renderer/components/TimelineSpace/NewTootModal.vue @@ -0,0 +1,121 @@ + + + + + diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js index 6992317b..f56a0efa 100644 --- a/src/renderer/store/TimelineSpace.js +++ b/src/renderer/store/TimelineSpace.js @@ -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,14 @@ const TimelineSpace = { stopUserStreaming ({ commit }) { ipcRenderer.send('stop-user-streaming') }, + watchShortcutEvents ({ commit }, account) { + ipcRenderer.on('CmdOrCtrl+N', () => { + commit('changeNewTootModal', true) + }) + ipcRenderer.on('CmdOrCtrl+R', () => { + console.log('reply') + }) + }, fetchHomeTimeline ({ commit }, account) { return new Promise((resolve, reject) => { const client = new Mastodon( @@ -117,8 +129,34 @@ const TimelineSpace = { reject(err) }) }) + }, + postToot ({ commit, state }, body) { + return new Promise((resolve, reject) => { + if (state.account.accessToken === undefined || state.account.accessToken === null) { + return reject(new AuthenticationError()) + } + const client = new Mastodon( + { + access_token: state.account.accessToken, + api_url: state.account.baseURL + '/api/v1' + } + ) + client.post('/statuses', { + status: body + }) + .then((res) => { + commit('changeNewTootModal', false) + resolve(res) + }) + .catch((err) => { + reject(err) + }) + }) } } } export default TimelineSpace + +class AuthenticationError { +}