Browse Source

Merge pull request #10307 from liusy182/10240-theme-color-2

return null when theme color is transparent or not found
Cheng Zhao 7 years ago
parent
commit
cc9771a3d0

+ 5 - 1
atom/browser/api/atom_api_web_contents.cc

@@ -761,7 +761,11 @@ void WebContents::MediaStoppedPlaying(const MediaPlayerInfo& video_type,
 }
 
 void WebContents::DidChangeThemeColor(SkColor theme_color) {
-  Emit("did-change-theme-color", atom::ToRGBHex(theme_color));
+  if (theme_color != SK_ColorTRANSPARENT) {
+    Emit("did-change-theme-color", atom::ToRGBHex(theme_color));
+  } else {
+    Emit("did-change-theme-color", nullptr);
+  }
 }
 
 void WebContents::DocumentLoadedInFrame(

+ 5 - 0
docs/api/web-contents.md

@@ -403,6 +403,11 @@ a meta tag:
 <meta name='theme-color' content='#ff0000'>
 ```
 
+Returns:
+
+* `event` Event
+* `color` (String | null) - Theme color is in format of '#rrggbb'. It is `null` when no theme color is set.
+
 #### Event: 'update-target-url'
 
 Returns:

+ 17 - 0
spec/api-web-contents-spec.js

@@ -660,4 +660,21 @@ describe('webContents module', function () {
       gen.next()
     })
   })
+
+  describe('did-change-theme-color event', () => {
+    it('is triggered with correct theme color', (done) => {
+      var count = 0
+      w.webContents.on('did-change-theme-color', (e, color) => {
+        if (count === 0) {
+          count++
+          assert.equal(color, '#FFEEDD')
+          w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html'))
+        } else if (count === 1) {
+          assert.equal(color, null)
+          done()
+        }
+      })
+      w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'theme-color.html'))
+    })
+  })
 })

+ 1 - 1
vendor/native_mate

@@ -1 +1 @@
-Subproject commit 7d9c1a80f025f4c46f7da8ea73246fe0f1968579
+Subproject commit f047bb61bbd985079dd93e7ed322999550efed1d