Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Add menu setting 'show notifications' #227

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const SoundCloud = require('./soundcloud')
const touchBarMenu = require('./touch-bar-menu')
const windowOpenPolicy = require('./window-open-policy')
const windowState = require('electron-window-state')
const storage = require('electron-json-storage')

let mainWindow = null
let aboutWindow = null
Expand Down Expand Up @@ -247,10 +248,15 @@ app.on('ready', () => {
})

soundcloud.on('play-new-track', ({ title, subtitle, artworkURL }) => {
mainWindow.webContents.send('notification', {
title,
body: subtitle,
icon: artworkURL
storage.get('settings', (error, settings) => {
if (error) throw error
if (settings && settings.notifications) {
mainWindow.webContents.send('notification', {
title,
body: subtitle,
icon: artworkURL
})
}
})
})

Expand Down
26 changes: 26 additions & 0 deletions app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { app, Menu, shell } = require('electron')
const Events = require('events')
const storage = require('electron-json-storage')

module.exports = function menu(options = {}) {
return buildMenu(options)
Expand Down Expand Up @@ -157,6 +158,19 @@ function buildMenu(options) {
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close'
},
{
label: 'Show notifications',
type: 'checkbox',
checked: true,
click() {
storage.get('settings', (error, data) => {
if (error) throw error
const settings = data || {}
settings.notifications = !settings.notifications
storage.set('settings', settings)
})
}
}
]
},
Expand Down Expand Up @@ -267,5 +281,17 @@ function buildMenu(options) {

const built = Menu.buildFromTemplate(menu)
built.events = events

storage.get('settings', (error, data) => {
if (error) throw error
const settings = data || {}
if (typeof settings.notifications != 'undefined') {
built.items[5].submenu.items[3].checked = settings.notifications
} else {
settings.notifications = built.items[5].submenu.items[3].checked
storage.set('settings', settings)
}
})

return built
}
142 changes: 140 additions & 2 deletions app/package-lock.json

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

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"main": "./main.js",
"dependencies": {
"electron-context-menu": "^0.15.2",
"electron-json-storage": "^4.4.0",
"electron-squirrel-startup": "^1.0.0",
"electron-window-state": "^5.0.3",
"optimist": "^0.6.1"
Expand Down