diff --git a/main.js b/main.js index 812c734d9..e6e95e661 100644 --- a/main.js +++ b/main.js @@ -28,7 +28,7 @@ const { companionWindowSettings, } = require('./server.config') const settingsProvider = require('./providers/settingsProvider') -const infoPlayer = require('./utils/injectGetInfoPlayer') +const infoPlayerProvider = require('./providers/infoPlayerProvider') const rainmeterNowPlaying = require('./providers/rainmeterNowPlaying') const companionServer = require('./providers/companionServer') const discordRPC = require('./providers/discordRpcProvider') @@ -222,7 +222,7 @@ function createWindow() { // mainWindow.webContents.openDevTools({ mode: 'detach' }); // view.webContents.openDevTools({ mode: 'detach' }) - mediaControl.createThumbar(mainWindow, infoPlayer.getAllInfo()) + mediaControl.createThumbar(mainWindow, infoPlayerProvider.getAllInfo()) if (windowMaximized) { setTimeout(function() { @@ -237,6 +237,10 @@ function createWindow() { } } + mainWindow.on('ready-to-show', () => { + console.log('show') + }) + // Emitted when the window is closed. mainWindow.on('closed', function() { // Dereference the window object, usually you would store windows @@ -248,7 +252,7 @@ function createWindow() { mainWindow.on('show', function() { globalShortcut.unregister('CmdOrCtrl+M') - mediaControl.createThumbar(mainWindow, infoPlayer.getAllInfo()) + mediaControl.createThumbar(mainWindow, infoPlayerProvider.getAllInfo()) }) view.webContents.on('new-window', function(event, url) { @@ -284,9 +288,9 @@ function createWindow() { }) view.webContents.on('media-started-playing', function() { - if (!infoPlayer.hasInitialized()) { - infoPlayer.init(view) - //mprisProvider.setRealPlayer(infoPlayer) //this lets us keep track of the current time in playback. + if (!infoPlayerProvider.hasInitialized()) { + infoPlayerProvider.init(view) + //mprisProvider.setRealPlayer(infoPlayerProvider) //this lets us keep track of the current time in playback. } if (isMac()) { @@ -319,8 +323,8 @@ function createWindow() { }) function updateActivity() { - var trackInfo = infoPlayer.getTrackInfo() - var playerInfo = infoPlayer.getPlayerInfo() + var trackInfo = infoPlayerProvider.getTrackInfo() + var playerInfo = infoPlayerProvider.getPlayerInfo() var title = trackInfo.title var author = trackInfo.author @@ -334,7 +338,7 @@ function createWindow() { rainmeterNowPlaying.setActivity(getAll()) //mprisProvider.setActivity(getAll()) - mediaControl.createThumbar(mainWindow, infoPlayer.getAllInfo()) + mediaControl.createThumbar(mainWindow, infoPlayerProvider.getAllInfo()) mediaControl.setProgress( mainWindow, @@ -381,8 +385,11 @@ function createWindow() { } global.sharedObj.paused = false - mediaControl.createThumbar(mainWindow, infoPlayer.getAllInfo()) - ipcMain.emit('play-pause', infoPlayer.getTrackInfo()) + mediaControl.createThumbar( + mainWindow, + infoPlayerProvider.getAllInfo() + ) + ipcMain.emit('play-pause', infoPlayerProvider.getTrackInfo()) } catch {} }) @@ -394,8 +401,11 @@ function createWindow() { } global.sharedObj.paused = true - ipcMain.emit('play-pause', infoPlayer.getTrackInfo()) - mediaControl.createThumbar(mainWindow, infoPlayer.getAllInfo()) + ipcMain.emit('play-pause', infoPlayerProvider.getTrackInfo()) + mediaControl.createThumbar( + mainWindow, + infoPlayerProvider.getAllInfo() + ) } catch {} }) @@ -458,8 +468,8 @@ function createWindow() { if (settingsProvider.get('settings-enable-double-tapping-show-hide')) { if (!doublePressPlayPause) { // The first press - if (infoPlayer.getTrackInfo().id == '') { - infoPlayer.firstPlay(view.webContents) + if (infoPlayerProvider.getTrackInfo().id == '') { + infoPlayerProvider.firstPlay(view.webContents) } doublePressPlayPause = true @@ -477,10 +487,6 @@ function createWindow() { } }) - globalShortcut.register('CmdOrCtrl+Shift+Space', function() { - mediaControl.playPauseTrack(view) - }) - globalShortcut.register('MediaStop', function() { mediaControl.stopTrack(view) }) @@ -488,13 +494,19 @@ function createWindow() { globalShortcut.register('MediaPreviousTrack', function() { mediaControl.previousTrack(view) }) - globalShortcut.register('CmdOrCtrl+Shift+PageDown', function() { - mediaControl.previousTrack(view) - }) globalShortcut.register('MediaNextTrack', function() { mediaControl.nextTrack(view) }) + + globalShortcut.register('CmdOrCtrl+Shift+Space', function() { + mediaControl.playPauseTrack(view) + }) + + globalShortcut.register('CmdOrCtrl+Shift+PageDown', function() { + mediaControl.previousTrack(view) + }) + globalShortcut.register('CmdOrCtrl+Shift+PageUp', function() { mediaControl.nextTrack(view) }) @@ -510,12 +522,15 @@ function createWindow() { ipcMain.on('retrieve-player-info', function(e, _) { // IPCRenderer if (e !== undefined) { - e.sender.send('song-playing-now-is', infoPlayer.getAllInfo()) + e.sender.send( + 'song-playing-now-is', + infoPlayerProvider.getAllInfo() + ) } // IPCMain - if (infoPlayer.hasInitialized()) { - ipcMain.emit('song-playing-now-is', infoPlayer.getAllInfo()) + if (infoPlayerProvider.hasInitialized()) { + ipcMain.emit('song-playing-now-is', infoPlayerProvider.getAllInfo()) } }) @@ -1134,11 +1149,11 @@ function logDebug(data) { } function songInfo() { - return infoPlayer.getTrackInfo() + return infoPlayerProvider.getTrackInfo() } function playerInfo() { - return infoPlayer.getPlayerInfo() + return infoPlayerProvider.getPlayerInfo() } function getAll() { diff --git a/package-lock.json b/package-lock.json index 9653372bd..34261184b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -193,6 +193,23 @@ "core-js": "^3.4.1" } }, + "@nodert-win10/windows.media.playback": { + "version": "0.2.96", + "resolved": "https://registry.npmjs.org/@nodert-win10/windows.media.playback/-/windows.media.playback-0.2.96.tgz", + "integrity": "sha1-AX7rxWu1MPm48qRWUAw7fRzkLzU=", + "optional": true, + "requires": { + "nan": "^2.14.1" + }, + "dependencies": { + "nan": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", + "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==", + "optional": true + } + } + }, "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -1039,6 +1056,7 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/dbus-next/-/dbus-next-0.5.1.tgz", "integrity": "sha512-PzsudTX5HMLocSuwHefIohto8L4Gnh5ST2+VNAoax9Xurh+lTosmXIfgi/Mrc93vqUU3D1v7jE9/vjiWd3KIbA==", + "optional": true, "requires": { "abstract-socket": "^2.0.0", "event-stream": "3.3.4", @@ -1092,6 +1110,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.1.tgz", "integrity": "sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g==", + "optional": true, "requires": { "is-arguments": "^1.0.4", "is-date-object": "^1.0.1", @@ -1195,7 +1214,8 @@ "duplexer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", - "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=" + "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", + "optional": true }, "duplexer3": { "version": "0.1.4", @@ -1564,6 +1584,7 @@ "version": "3.3.4", "resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", "integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=", + "optional": true, "requires": { "duplexer": "~0.1.1", "from": "~0", @@ -1713,7 +1734,8 @@ "from": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz", - "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=" + "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=", + "optional": true }, "fs-extra": { "version": "8.1.0", @@ -1911,7 +1933,8 @@ "hexy": { "version": "0.2.11", "resolved": "https://registry.npmjs.org/hexy/-/hexy-0.2.11.tgz", - "integrity": "sha512-ciq6hFsSG/Bpt2DmrZJtv+56zpPdnq+NQ4ijEFrveKN0ZG1mhl/LdT1NQZ9se6ty1fACcI4d4vYqC9v8EYpH2A==" + "integrity": "sha512-ciq6hFsSG/Bpt2DmrZJtv+56zpPdnq+NQ4ijEFrveKN0ZG1mhl/LdT1NQZ9se6ty1fACcI4d4vYqC9v8EYpH2A==", + "optional": true }, "hosted-git-info": { "version": "2.8.5", @@ -2064,7 +2087,8 @@ "is-arguments": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz", - "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==" + "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==", + "optional": true }, "is-arrayish": { "version": "0.2.1", @@ -2216,7 +2240,8 @@ "jsbi": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/jsbi/-/jsbi-2.0.5.tgz", - "integrity": "sha512-TzO/62Hxeb26QMb4IGlI/5X+QLr9Uqp1FPkwp2+KOICW+Q+vSuFj61c8pkT6wAns4WcK56X7CmSHhJeDGWOqxQ==" + "integrity": "sha512-TzO/62Hxeb26QMb4IGlI/5X+QLr9Uqp1FPkwp2+KOICW+Q+vSuFj61c8pkT6wAns4WcK56X7CmSHhJeDGWOqxQ==", + "optional": true }, "jsbn": { "version": "0.1.1", @@ -2359,7 +2384,8 @@ "long": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", - "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" + "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==", + "optional": true }, "lowercase-keys": { "version": "1.0.1", @@ -2393,7 +2419,8 @@ "map-stream": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.1.0.tgz", - "integrity": "sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ=" + "integrity": "sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ=", + "optional": true }, "matcher": { "version": "2.1.0", @@ -2515,6 +2542,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/mpris-service/-/mpris-service-2.1.0.tgz", "integrity": "sha512-HWFimtWYrfm7iMz8VjTrY68c2vwBMb5kDXqAQ9GmgIMv5exfgz+w277F1XFBc72Nu6FM3QH6jqMGT89m2MMDBg==", + "optional": true, "requires": { "dbus-next": "^0.5.1", "deep-equal": "^1.0.1", @@ -6105,6 +6133,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.2.tgz", "integrity": "sha512-5lHCz+0uufF6wZ7CRFWJN3hp8Jqblpgve06U5CMQ3f//6iDjPr2PEo9MWCjEssDsa+UZEL4PkFpr+BMop6aKzQ==", + "optional": true, "requires": { "define-properties": "^1.1.3", "es-abstract": "^1.17.5" @@ -6281,6 +6310,7 @@ "version": "0.0.11", "resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", "integrity": "sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=", + "optional": true, "requires": { "through": "~2.3" } @@ -6526,7 +6556,8 @@ "put": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/put/-/put-0.0.6.tgz", - "integrity": "sha1-MPX2C9bkOJvTKeFqJThsuy5KAKM=" + "integrity": "sha1-MPX2C9bkOJvTKeFqJThsuy5KAKM=", + "optional": true }, "qrcode-generator": { "version": "1.4.4", @@ -6610,6 +6641,7 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz", "integrity": "sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ==", + "optional": true, "requires": { "define-properties": "^1.1.3", "es-abstract": "^1.17.0-next.1" @@ -6998,6 +7030,7 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz", "integrity": "sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8=", + "optional": true, "requires": { "through": "2" } @@ -7033,6 +7066,7 @@ "version": "0.0.4", "resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.4.tgz", "integrity": "sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ=", + "optional": true, "requires": { "duplexer": "~0.1.1" } @@ -7158,7 +7192,8 @@ "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "optional": true }, "timm": { "version": "1.6.2", diff --git a/package.json b/package.json index 14d3f3f44..89ce1e485 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "i18n": "^0.8.5", "js-base64": "^2.5.1", "materialize-css": "^1.0.0", - "mpris-service": "^2.1.0", "node-vibrant": "^3.1.5", "npx": "^10.2.2", "prettier": "^1.19.1", @@ -59,5 +58,9 @@ "socket.io": "^2.3.0", "utf-8-validate": "^5.0.2", "ws": "^7.2.1" + }, + "optionalDependencies": { + "@nodert-win10/windows.media.playback": "^0.2.95", + "mpris-service": "^2.1.0" } } diff --git a/pages/settings/last-fm-login.js b/pages/settings/last-fm-login.js index d0beba4b7..86f18411a 100644 --- a/pages/settings/last-fm-login.js +++ b/pages/settings/last-fm-login.js @@ -1,18 +1,18 @@ -const __ = require("../../providers/translateProvider"); -const scrobbleProvider = require("../../providers/scrobblerProvider"); -__.loadi18n(); -const Base64 = require("js-base64").Base64; +const __ = require('../../providers/translateProvider') +const scrobbleProvider = require('../../providers/scrobblerProvider') +__.loadi18n() + +var login = scrobbleProvider.getLogin() -var login = scrobbleProvider.getLogin(); if (login) { - document.getElementById("username").value = login.username; - document.getElementById("password").value = login.password; + document.getElementById('username').value = login.username + document.getElementById('password').value = login.password } -document.getElementById("btn-save").addEventListener("click", function() { - var username = document.getElementById("username").value; - var password = document.getElementById("password").value; - scrobbleProvider.setLogin(username, password); +document.getElementById('btn-save').addEventListener('click', function() { + var username = document.getElementById('username').value + var password = document.getElementById('password').value + scrobbleProvider.setLogin(username, password) - scrobbleProvider.getToken(); -}); + scrobbleProvider.getToken() +}) diff --git a/providers/companionServer.js b/providers/companionServer.js index 9b3b2cc7d..6adfd13c2 100644 --- a/providers/companionServer.js +++ b/providers/companionServer.js @@ -3,7 +3,7 @@ const http = require('http') const os = require('os') const networkInterfaces = os.networkInterfaces() const qrcode = require('qrcode-generator') -const infoPlayer = require('../utils/injectGetInfoPlayer') +const infoPlayerProvider = require('../providers/infoPlayerProvider') const settingsProvider = require('../providers/settingsProvider') const ip = '0.0.0.0' @@ -85,21 +85,21 @@ var serverFunction = function(req, res) {