-
-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Window Theme with Pulsar Theme #545
Changes from all commits
da7f0ab
ac40c6a
5ea83bf
d697005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ const { Emitter, CompositeDisposable } = require('event-kit'); | |
const { File } = require('pathwatcher'); | ||
const fs = require('fs-plus'); | ||
const LessCompileCache = require('./less-compile-cache'); | ||
const Color = require('./color'); | ||
|
||
// Extended: Handles loading and activating available themes. | ||
// | ||
|
@@ -16,8 +17,10 @@ module.exports = class ThemeManager { | |
config, | ||
styleManager, | ||
notificationManager, | ||
viewRegistry | ||
viewRegistry, | ||
applicationDelegate | ||
}) { | ||
this.applicationDelegate = applicationDelegate; | ||
this.packageManager = packageManager; | ||
this.config = config; | ||
this.styleManager = styleManager; | ||
|
@@ -372,6 +375,20 @@ On linux there are currently problems with watch sizes. See | |
return this.styleSheetDisposablesBySourcePath[path]; | ||
} | ||
|
||
refreshWindowTheme() { | ||
let bgColor = Color.parse(getComputedStyle(document.documentElement).backgroundColor); | ||
|
||
let luminosity = 0.2126 * bgColor.red + 0.7152 * bgColor.green + 0.0722 * bgColor.blue; | ||
// ^^ Luminosity per ITU-R BT.709 | ||
Comment on lines
+381
to
+382
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source: Maybe from here? https://stackoverflow.com/questions/596216/formula-to-determine-perceived-brightness-of-rgb-color --> https://en.wikipedia.org/wiki/Relative_luminance#Relative_luminance_and_%22gamma_encoded%22_colorspaces --> https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.709-6-201506-I!!PDF-E.pdf (??) Just for reference sake. |
||
if (luminosity < 40) { | ||
// Considered Dark | ||
this.applicationDelegate.setWindowTheme("dark"); | ||
} else { | ||
// Considered Bright | ||
this.applicationDelegate.setWindowTheme("light"); | ||
} | ||
} | ||
|
||
activateThemes() { | ||
return new Promise(resolve => { | ||
// @config.observe runs the callback once, then on subsequent changes. | ||
|
@@ -396,6 +413,9 @@ On linux there are currently problems with watch sizes. See | |
this.refreshLessCache(); // Update cache again now that @getActiveThemes() is populated | ||
this.loadUserStylesheet(); | ||
this.reloadBaseStylesheets(); | ||
if (this.config.get("editor.syncWindowThemeWithPulsarTheme")) { | ||
this.refreshWindowTheme(); | ||
} | ||
this.initialLoadComplete = true; | ||
this.emitter.emit('did-change-active-themes'); | ||
resolve(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to look this up, but seems legit!
https://www.electronjs.org/docs/latest/api/native-theme#nativethemethemesource