From 54f06b0ba95fed5726396ac28471972e07b426e1 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 1 Jul 2016 23:12:06 +1200 Subject: [PATCH 1/2] Override the Notification API constructor to create silent notifications when the webContents is muted --- lib/renderer/override.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/renderer/override.js b/lib/renderer/override.js index c568388876..fb81c24e55 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -248,3 +248,14 @@ Object.defineProperty(document, 'visibilityState', { return cachedVisibilityState } }) + +// Make notifications silent if the the current webContents is muted +const NativeNotification = window.Notification +class Notification extends NativeNotification { + constructor (title, opts) { + super(title, Object.assign({ + silent: remote.getCurrentWebContents().isAudioMuted() + }, opts)) + } +} +window.Notification = Notification From 4f660f3e6f2e64abb5815f878a4de7ea64dada6c Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Sat, 2 Jul 2016 13:28:28 +1200 Subject: [PATCH 2/2] Implement WebContenstAudioMuted in AtomBrowserClient --- atom/browser/atom_browser_client.cc | 7 +++++++ atom/browser/atom_browser_client.h | 2 ++ lib/renderer/override.js | 11 ----------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index c1b50459c6..13503ae57d 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -303,6 +303,13 @@ void AtomBrowserClient::WebNotificationAllowed( permission_helper->RequestWebNotificationPermission(callback); } +bool AtomBrowserClient::WebContentsAudioMuted( + int render_process_id) { + content::WebContents* web_contents = + WebContentsPreferences::GetWebContentsFromProcessID(render_process_id); + return web_contents->IsAudioMuted(); + } + void AtomBrowserClient::RenderProcessHostDestroyed( content::RenderProcessHost* host) { int process_id = host->GetID(); diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index cf1a4cc438..47d7434497 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -101,6 +101,8 @@ class AtomBrowserClient : public brightray::BrowserClient, void WebNotificationAllowed( int render_process_id, const base::Callback& callback) override; + bool WebContentsAudioMuted( + int render_process_id) override; // content::RenderProcessHostObserver: void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; diff --git a/lib/renderer/override.js b/lib/renderer/override.js index fb81c24e55..c568388876 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -248,14 +248,3 @@ Object.defineProperty(document, 'visibilityState', { return cachedVisibilityState } }) - -// Make notifications silent if the the current webContents is muted -const NativeNotification = window.Notification -class Notification extends NativeNotification { - constructor (title, opts) { - super(title, Object.assign({ - silent: remote.getCurrentWebContents().isAudioMuted() - }, opts)) - } -} -window.Notification = Notification