From 5b79bc1181c23fa3f492ad326270fe8e72976240 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 7 Apr 2018 23:18:20 +0900
Subject: [PATCH] refs #193 Check preferences before sound
---
src/main/index.js | 42 ++++++++++++-------
.../TimelineSpace/Contents/Cards/Toot.js | 4 +-
.../store/TimelineSpace/Modals/NewToot.js | 2 +-
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/src/main/index.js b/src/main/index.js
index d19aa286..c3a560e2 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -45,6 +45,10 @@ const preferencesDBPath = process.env.NODE_ENV === 'production'
? userData + './db/preferences.json'
: 'preferences.json'
+const soundBasePath = process.env.NODE_ENV === 'development'
+ ? path.join(__dirname, '../../build/sounds/')
+ : path.join(process.resourcesPath, 'build/sounds/')
+
async function listAccounts () {
try {
const account = new Account(accountDB)
@@ -449,22 +453,32 @@ ipcMain.on('stop-public-streaming', (event, _) => {
})
// sounds
-ipcMain.on('operation-sound01', (event, _) => {
- const sound = process.env.NODE_ENV === 'development'
- ? path.join(__dirname, '../../build/sounds/operation_sound01.wav')
- : path.join(process.resourcesPath, 'build/sounds/operation_sound01.wav')
- simplayer(sound, (err) => {
- if (err) log.error(err)
- })
+ipcMain.on('fav-rt-action-sound', (event, _) => {
+ const preferences = new Preferences(preferencesDBPath)
+ preferences.load()
+ .then((conf) => {
+ if (conf.general.sound.fav_rb) {
+ const sound = path.join(soundBasePath, 'operation_sound01.wav')
+ simplayer(sound, (err) => {
+ if (err) log.error(err)
+ })
+ }
+ })
+ .catch(err => log.error(err))
})
-ipcMain.on('operation-sound02', (event, _) => {
- const sound = process.env.NODE_ENV === 'development'
- ? path.join(__dirname, '../../build/sounds/operation_sound02.wav')
- : path.join(process.resourcesPath, 'build/sounds/operation_sound02.wav')
- simplayer(sound, (err) => {
- if (err) log.error(err)
- })
+ipcMain.on('toot-action-sound', (event, _) => {
+ const preferences = new Preferences(preferencesDBPath)
+ preferences.load()
+ .then((conf) => {
+ if (conf.general.sound.toot) {
+ const sound = path.join(soundBasePath, 'operation_sound02.wav')
+ simplayer(sound, (err) => {
+ if (err) log.error(err)
+ })
+ }
+ })
+ .catch(err => log.error(err))
})
// preferences
diff --git a/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js b/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js
index 32c0f8e9..452ae3a1 100644
--- a/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js
+++ b/src/renderer/store/TimelineSpace/Contents/Cards/Toot.js
@@ -20,7 +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-sound01')
+ ipcRenderer.send('fav-rt-action-sound')
resolve(data.reblog)
})
})
@@ -51,7 +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-sound01')
+ ipcRenderer.send('fav-rt-action-sound')
resolve(data)
})
})
diff --git a/src/renderer/store/TimelineSpace/Modals/NewToot.js b/src/renderer/store/TimelineSpace/Modals/NewToot.js
index ace6ed27..0b3ca821 100644
--- a/src/renderer/store/TimelineSpace/Modals/NewToot.js
+++ b/src/renderer/store/TimelineSpace/Modals/NewToot.js
@@ -48,7 +48,7 @@ const NewToot = {
)
client.post('/statuses', form, (err, data, res) => {
if (err) return reject(err)
- ipcRenderer.send('operation-sound02')
+ ipcRenderer.send('toot-action-sound')
resolve(res)
})
})