feat: send current track to main process and provide an api

master
qier222 4 years ago
parent c564d03c17
commit 07455c8ecd
No known key found for this signature in database
GPG Key ID: 9C85007ED905F14D

@ -88,6 +88,9 @@ class Background {
const expressApp = express(); const expressApp = express();
expressApp.use('/', express.static(__dirname + '/')); expressApp.use('/', express.static(__dirname + '/'));
expressApp.use('/api', expressProxy('http://127.0.0.1:10754')); expressApp.use('/api', expressProxy('http://127.0.0.1:10754'));
expressApp.use('/player', (req, res) => {
res.send(this.store.get('playerInfo'));
});
this.expressApp = expressApp.listen(27232); this.expressApp = expressApp.listen(27232);
} }

@ -121,4 +121,8 @@ export function initIpcMain(win, store) {
console.log('removeProxy'); console.log('removeProxy');
win.webContents.session.setProxy({}); win.webContents.session.setProxy({});
}); });
ipcMain.on('playerInfo', (event, info) => {
store.set('playerInfo', info);
});
} }

@ -177,6 +177,14 @@ export default class {
setInterval(() => { setInterval(() => {
this._progress = this._howler === null ? 0 : this._howler.seek(); this._progress = this._howler === null ? 0 : this._howler.seek();
}, 1000); }, 1000);
// 发送正在播放的信息给主进程
setInterval(() => {
ipcRenderer.send('playerInfo', {
currentTrack: this.currentTrack,
progress: this._progress,
});
}, 1000);
} }
_getNextTrack() { _getNextTrack() {
if (this._playNextList.length > 0) { if (this._playNextList.length > 0) {

Loading…
Cancel
Save