From c99b95e611c0c36d7577650b6fc2703738af72dc Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Mon, 22 Nov 2021 22:52:38 +0200 Subject: [PATCH] use `config.plugins.isEnabled` --- plugins/shortcuts/mpris.js | 6 ++---- plugins/tuna-obs/back.js | 2 +- providers/song-controls-front.js | 35 +++++++++----------------------- providers/song-info-front.js | 6 +++++- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/plugins/shortcuts/mpris.js b/plugins/shortcuts/mpris.js index 6b6b8590..e6c6539f 100644 --- a/plugins/shortcuts/mpris.js +++ b/plugins/shortcuts/mpris.js @@ -22,14 +22,12 @@ function registerMPRIS(win) { const microToSec = n => Math.round(Number(n) / 1e6); const seekTo = e => win.webContents.send("seekTo", microToSec(e.position)); - const seek = o => win.webContents.send("seek", microToSec(o)); + const seekBy = o => win.webContents.send("seekBy", microToSec(o)); const player = setupMPRIS(); const mprisSeek = player.seeked; - win.webContents.send("registerOnSeek"); - ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t))); let currentSeconds = 0; @@ -59,7 +57,7 @@ function registerMPRIS(win) { player.on("next", next); player.on("previous", previous); - player.on('seek', seek); + player.on('seek', seekBy); player.on('position', seekTo); registerCallback(songInfo => { diff --git a/plugins/tuna-obs/back.js b/plugins/tuna-obs/back.js index cf5ad1c5..0a2bc3a3 100644 --- a/plugins/tuna-obs/back.js +++ b/plugins/tuna-obs/back.js @@ -27,7 +27,7 @@ const post = async (data) => { fetch(url, { method: 'POST', headers, body: JSON.stringify({ data }) }).catch(e => console.log(`Error: '${e.code || e.errno}' - when trying to access obs-tuna webserver at port ${port}`)); } -module.exports = async () => { +module.exports = async (win) => { ipcMain.on('timeChanged', async (_, t) => { if (!data.title) return; data.progress = secToMilisec(t); diff --git a/providers/song-controls-front.js b/providers/song-controls-front.js index bb98ae30..19031388 100644 --- a/providers/song-controls-front.js +++ b/providers/song-controls-front.js @@ -1,30 +1,15 @@ const { ipcRenderer } = require("electron"); - -module.exports.seekTo = seekTo; -function seekTo(t) { - document.querySelector('video').currentTime = t; -} - -module.exports.seek = seek; -function seek(o) { - document.querySelector('video').currentTime += o; -} +const config = require("../config"); +const is = require("electron-is"); module.exports.setupSongControls = () => { - ipcRenderer.on("seekTo", async (_, t) => seekTo(t)); - ipcRenderer.on("seek", async (_, t) => seek(t)); - ipcRenderer.once("registerOnSeek", registerOnSeek) -}; + document.addEventListener('apiLoaded', e => { + ipcRenderer.on("seekTo", (_, t) => e.target.seekTo(t)); + ipcRenderer.on("seekBy", (_, t) => e.target.seekBy(t)); -async function registerOnSeek() { - const register = v => v.addEventListener('seeked', () => ipcRenderer.send('seeked', v.currentTime)); - let video = document.querySelector('video'); - if (video) { - register(video); + }, { once: true, passive: true }) + + if (is.linux() && config.plugins.isEnabled('shortcuts')) { // MPRIS Enabled + document.querySelector('video').addEventListener('seeked', () => ipcRenderer.send('seeked', v.currentTime)); } - else { - document.addEventListener('apiLoaded', () => { - register(document.querySelector('video')) - }, { once: true, passive: true }) - } -} +}; diff --git a/providers/song-info-front.js b/providers/song-info-front.js index 04fcbe08..0d8df3e9 100644 --- a/providers/song-info-front.js +++ b/providers/song-info-front.js @@ -2,6 +2,8 @@ const { ipcRenderer } = require("electron"); const { getImage } = require("./song-info"); +const config = require("../config"); + global.songInfo = {}; function $(selector) { return document.querySelector(selector); } @@ -13,7 +15,9 @@ ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => { module.exports = () => { document.addEventListener('apiLoaded', e => { - setupTimeChangeListener(); + if (config.plugins.isEnabled('tuna-obs')) { + setupTimeChangeListener(); + } $('video').addEventListener('loadedmetadata', () => { const data = e.detail.getPlayerResponse();