diff --git a/background.js b/background.js index 55ceb6d..cf0bf5b 100644 --- a/background.js +++ b/background.js @@ -308,9 +308,15 @@ const checkDonate = async (loginName = null, opayid = null) => { values }) let msg = `/me 感謝 ${i.name} 贊助了 ${i.amount} 元, ${i.msg}` - event.emit('twitchSend', { - msg, - channel: loginName + //event.emit('twitchSend', { + // msg, + // channel: loginName + //}) + process.send({ + type: 'twitchSend', + data: { + msg, channel: loginName + } }) } catch (err) { console.log(err) diff --git a/index.js b/index.js index 7e02b8d..3ddb90a 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,22 @@ require('module-alias/register') const fs = require('fs') +const fork = require('child_process').fork const path = require('path') try { fs.accessSync(path.resolve(__dirname, '.env')) require('dotenv').config() } catch (err) {} require('./app') -require('./background') -require('./event') +const event = require('./event') +let bgProc = fork('./background.js') +bgProc.on('message', data => { + if ('type' in data && 'data' in data) { + event.emit(data.type, data.data) + } +}) +bgProc.on('close', () => { + console.log(`background close`) +}) +//require('./background') const twitchChat = require('./libs/twitch-bot') twitchChat.runBot()