Skip to content

Commit

Permalink
Updated close behaviour, as there was an intermittent error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Fraser committed Aug 31, 2018
1 parent 816820f commit 0a0af34
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
44 changes: 32 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ const { app, BrowserWindow, globalShortcut, Menu, ipcMain } = require('electron'
const notifier = require('node-notifier')
const path = require('path')

// For heavy debugging
// require('electron-debug')();

// Vars
let winWidth = 440
let winHeight = 620
let loadingScreen
let mainWindow
let aboutScreen
let willQuitApp = false
let windowParams = {
backgroundColor: '#131313',
icon: path.join(__dirname, 'assets/musictube.ico'),
Expand Down Expand Up @@ -39,8 +37,14 @@ function createWindow () {
mainWindow.setTitle(windowParams.title)
if (loadingScreen !== null) loadingScreen.close()
})
// Emitted when the window is closed.
mainWindow.on('closed', function () { mainWindow = null })
// Close behaviour
mainWindow.on('close', (e) => {
if (!willQuitApp) {
e.preventDefault()
mainWindow.hide()
}
})
mainWindow.on('closed', () => { mainWindow = null })
}

function createAboutWindow () {
Expand Down Expand Up @@ -73,8 +77,13 @@ app.on('ready', () => {
skipOverAdverts()
})

// activate is triggered when clicked the dock icon (osx)
app.on('activate', () => {
mainWindow.show()
})

// Notification message process
ipcMain.on('notify', function (event, obj) {
ipcMain.on('notify', (event, obj) => {
notifier.notify({
title: `${obj.status} • MusicTube Player`,
message: `${obj.title}\n${obj.by}`,
Expand Down Expand Up @@ -133,10 +142,12 @@ function globalShortcuts () {

function skipOverAdverts () {
setInterval(() => {
mainWindow.webContents.executeJavaScript(`
var skip = document.getElementsByClassName('videoAdUiSkipButton')[0];
if(typeof skip !== "undefined") { skip.click() }
`)
if (mainWindow) {
mainWindow.webContents.executeJavaScript(`
var skip = document.getElementsByClassName('videoAdUiSkipButton')[0];
if(typeof skip !== "undefined") { skip.click() }
`)
}
}, 500)
}

Expand All @@ -153,10 +164,18 @@ function createMenu () {
}
},
{
label: 'Reload',
accelerator: 'Cmd+R',
label: 'Refresh',
accelerator: 'CmdOrCtrl+R',
role: 'forceReload'
},
{
label: 'New Window',
accelerator: 'CmdOrCtrl+N',
click () {
createLoadingWindow()
createWindow()
}
},
{
label: 'Show Developer Tools',
accelerator: 'CmdOrCtrl+Shift+I',
Expand All @@ -166,6 +185,7 @@ function createMenu () {
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click () {
willQuitApp = true
app.quit()
}
}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "musictube-player",
"version": "v1.4.0",
"version": "v1.4.1",
"description": "MusicTube player is an electron wrapper application for YouTube Music with added media key support and notifications.",
"main": "index.js",
"repository": {
Expand All @@ -20,7 +20,7 @@
},
"scripts": {
"start": "electron .",
"build": "rm -rf build && electron-packager . 'MusicTube Player' --icon=assets/musictube.icns --out=build --prune=true"
"build": "electron-packager . 'MusicTube Player' --icon=assets/musictube.icns --out=build --overwrite=true --prune=true"
},
"keywords": [
"youtube",
Expand All @@ -31,7 +31,6 @@
"electron"
],
"dependencies": {
"electron-debug": "^2.*",
"node-notifier": "^5.2.*"
}
}

0 comments on commit 0a0af34

Please sign in to comment.