Skip to content

Commit

Permalink
Fix ytmdesktop#124 and improve
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerluiz committed May 28, 2020
1 parent 9d8e7df commit 206427b
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 61 deletions.
69 changes: 42 additions & 27 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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 {}
})

Expand All @@ -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 {}
})

Expand Down Expand Up @@ -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
Expand All @@ -477,24 +487,26 @@ function createWindow() {
}
})

globalShortcut.register('CmdOrCtrl+Shift+Space', function() {
mediaControl.playPauseTrack(view)
})

globalShortcut.register('MediaStop', function() {
mediaControl.stopTrack(view)
})

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)
})
Expand All @@ -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())
}
})

Expand Down Expand Up @@ -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() {
Expand Down
53 changes: 44 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
Loading

0 comments on commit 206427b

Please sign in to comment.