{"size": 1046, "ext": "js", "max_stars_repo_path": "src/notification/default-notification.js", "max_stars_repo_name": "infinityoneframework/infinityone-desktop", "max_stars_repo_stars_event_min_datetime": "2018-03-26T05:01:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T11:43:22.000Z", "max_issues_repo_path": "src/notification/default-notification.js", "max_issues_repo_name": "infinityoneframework/infinityone-desktop", "max_issues_repo_issues_event_min_datetime": "2021-04-29T10:39:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T18:48:51.000Z", "max_forks_repo_path": "src/notification/default-notification.js", "max_forks_repo_name": "infinityoneframework/infinityone-desktop", "max_forks_repo_forks_event_min_datetime": "2018-05-17T22:58:31.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-17T22:58:31.000Z"}
{"max_stars_count": 5, "max_issues_count": 2, "max_forks_count": 1, "avg_line_length": 29.8857142857, "max_line_length": 81, "alphanum_fraction": 0.7370936902}
'use strict'

const { ipcRenderer } = require('electron')
const Helpers = require('./helpers')

const NativeNotification = window.Notification
class BaseNotification extends NativeNotification {
	constructor(title, opts) {
		super(title + ', ' + opts.subtitle, opts)

		this.addEventListener('click', () => {
			// focus to the server who sent the
			// notification if not focused already
			Helpers.focusCurrentServer()
			ipcRenderer.send('focus-app')
		})
	}

	static requestPermission() {
		return // eslint-disable-line no-useless-return
	}

	// Override default Notification permission
	static get _permission() {
		// I could not figure out how to get access to the config from here. Instead,
		// the ServerWebView view watches showNotification (and silent) and uses
		// webview.execJavaScript to set window.OneChat.notifier values.
		// const showNotification = configUtil.getConfigItem('showNotification', false)
		const showNotification = true
		return showNotification ? 'granted' : 'denied'
	}
}

module.exports = BaseNotification
