Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notification and Improve tray icon #7

Merged
merged 3 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { app, BrowserWindow, globalShortcut, ipcMain, Menu, Tray } = require('electron')
const windowStateKeeper = require('electron-window-state')
const notifier = require('node-notifier')
const path = require('path')

// variables
Expand Down Expand Up @@ -139,7 +138,36 @@ function trayIcon () {
tray = new Tray(path.join(__dirname, `assets/icons/menu-standard-${trayTheme}.png`))
tray.setToolTip('MusicTube Player')
tray.on('click', () => {
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show()
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.show()
})
trayContextMenu()
}

function trayContextMenu () {
const contextMenu = Menu.buildFromTemplate([
{
label: app.getName()
},
{
type: 'separator'
},
{
label: 'About',
click: () => {
createAboutWindow()
}
},
{
label: 'Quit',
click: () => {
app.quit()
}
}
])
tray.setContextMenu(contextMenu)
tray.on('right-click', () => {
tray.popUpContextMenu(contextMenu)
})
}

Expand All @@ -148,9 +176,9 @@ function playStatus () {
if (mainWindow) {
mainWindow.webContents.executeJavaScript(`
var ipcRenderer = require('electron').ipcRenderer
var status = (document.querySelector('.play-pause-button').title === 'Pause')? 'Playing' : 'Paused'
var status = (!document.querySelector('.play-pause-button').title.includes('Paus')) ? 'Playing' : 'Paused'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this verification to work in pt-br also

var title = (document.querySelector('.title.ytmusic-player-bar')) ? document.querySelector('.title.ytmusic-player-bar').innerText : ''
var artist = (document.querySelector('.byline.ytmusic-player-bar')) ? document.querySelector('.byline.ytmusic-player-bar').innerText : ''
var artist = (document.querySelector('.byline.ytmusic-player-bar')) ? document.querySelector('.byline.ytmusic-player-bar').innerText.split('•')[0].trim() : ''
var object = {
status: status,
title: title,
Expand Down Expand Up @@ -186,6 +214,7 @@ function skipOver () {
// Application ready to run
app.on('ready', () => {
trayTheme = (process.platform === 'darwin') ? 'dark' : 'light'
app.setName('MusicTube Player')

createLoadingWindow()
createWindow()
Expand All @@ -209,10 +238,10 @@ app.on('before-quit', () => {
// Status IPC receiver
ipcMain.on('player', (event, object) => {
if (JSON.stringify(object) !== status && object.title !== '' && object.artist !== '') {
notifier.notify({
title: `${object.status} • MusicTube Player`,
message: `${object.title}\n${object.artist}`,
icon: path.join(__dirname, 'assets/musictube.ico')
tray.displayBalloon({
title: object.title,
content: object.artist.replace(/\n/g, ''),
icon: path.join(__dirname, 'assets', 'musictube.png')
})
}
status = JSON.stringify(object)
Expand Down
Loading