From b6123f6bd359088b55220d6501209c86dc271a3c Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Thu, 5 Apr 2018 09:00:42 +0900
Subject: [PATCH] refs #190 Sound a system sound when user favourite or reblog
---
.electron-vue/build.js | 2 +-
package-lock.json | 5 +++++
package.json | 4 ++++
src/main/index.js | 16 ++++++++++++++--
.../store/TimelineSpace/Contents/Cards/Toot.js | 3 +++
5 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/.electron-vue/build.js b/.electron-vue/build.js
index 2d96f17e..1e54e8f4 100644
--- a/.electron-vue/build.js
+++ b/.electron-vue/build.js
@@ -24,7 +24,7 @@ else if (process.env.BUILD_TARGET === 'web') web()
else build()
function clean () {
- del.sync(['build/*', '!build/icons', '!build/icons/icon.*'])
+ del.sync(['build/*', '!build/icons', '!build/icons/icon.*', '!build/sounds', '!build/sounds/*'])
console.log(`\n${doneLog}\n`)
process.exit()
}
diff --git a/package-lock.json b/package-lock.json
index a62dfc9a..a906354b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13699,6 +13699,11 @@
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true
},
+ "simplayer": {
+ "version": "0.0.8",
+ "resolved": "https://registry.npmjs.org/simplayer/-/simplayer-0.0.8.tgz",
+ "integrity": "sha1-8gzrIzFmrH84J0VmbSPzxIeSw8g="
+ },
"single-line-log": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/single-line-log/-/single-line-log-1.1.2.tgz",
diff --git a/package.json b/package.json
index bccaf9eb..33977bbc 100644
--- a/package.json
+++ b/package.json
@@ -39,6 +39,9 @@
"directories": {
"output": "build"
},
+ "extraResources": [
+ "build/sounds/"
+ ],
"files": [
"dist/electron/**/*",
"build/icons/*"
@@ -87,6 +90,7 @@
"mastodon-api": "^1.3.0",
"moment": "^2.21.0",
"nedb": "^1.8.0",
+ "simplayer": "0.0.8",
"vue": "^2.3.3",
"vue-awesome": "^2.3.5",
"vue-electron": "^1.0.6",
diff --git a/src/main/index.js b/src/main/index.js
index f9c45f0b..eab378bb 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -5,6 +5,8 @@ import Datastore from 'nedb'
import empty from 'is-empty'
import log from 'electron-log'
import windowStateKeeper from 'electron-window-state'
+import simplayer from 'simplayer'
+import path from 'path'
import Authentication from './auth'
import Account from './account'
@@ -21,7 +23,7 @@ log.transports.file.level = 'info'
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== 'development') {
- global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
+ global.__static = path.join(__dirname, '/static').replace(/\\/g, '\\\\')
}
let mainWindow
@@ -192,7 +194,7 @@ function createWindow () {
width: mainWindowState.width,
height: mainWindowState.height,
useContentSize: true,
- icon: require('path').join(__dirname, '../../build/icons/256x256.png')
+ icon: path.join(__dirname, '../../build/icons/256x256.png')
})
mainWindowState.manage(mainWindow)
@@ -441,6 +443,16 @@ ipcMain.on('stop-public-streaming', (event, _) => {
publicStreaming = null
})
+// sounds
+ipcMain.on('operation-sound', (event, _) => {
+ const sound = process.env.NODE_ENV === 'development'
+ ? path.join(__dirname, '../../build/sounds/operation_sound.wav')
+ : path.join(process.resourcesPath, 'build/sounds/operation_sound.wav')
+ simplayer(sound, (err) => {
+ if (err) log.error(err)
+ })
+})
+
/**
* Auto Updater
*
diff --git a/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js b/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js
index c3882278..cbdf611a 100644
--- a/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js
+++ b/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js
@@ -1,4 +1,5 @@
import Mastodon from 'mastodon-api'
+import { ipcRenderer } from 'electron'
const Toot = {
namespaced: true,
@@ -19,6 +20,7 @@ const Toot = {
// Reblog target status is in the data.reblog.
// So I send data.reblog as status for update local timeline.
commit('TimelineSpace/updateToot', data.reblog, { root: true })
+ ipcRenderer.send('operation-sound')
resolve(data.reblog)
})
})
@@ -49,6 +51,7 @@ const Toot = {
client.post(`/statuses/${message.id}/favourite`, {}, (err, data, res) => {
if (err) return reject(err)
commit('TimelineSpace/updateToot', data, { root: true })
+ ipcRenderer.send('operation-sound')
resolve(data)
})
})