-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch properties to a JavaScript API to support system themes (#171)
- Loading branch information
Showing
7 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/resources/io/jenkins/plugins/thememanager/ThemeManagerPageDecorator/header.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?jelly escape-by-default='false'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"> | ||
<script id="theme-manager-theme" type="application/json">{ "id": "${it.themeKey}" }</script> | ||
<st:adjunct includes="io.jenkins.plugins.thememanager.header.main" /> | ||
<script id="theme-manager-theme" type="application/json">{ "id": "${it.themeKey}", "respect_system_appearance": ${it.respectSystemAppearance} }</script> | ||
${it.getHeaderHtml()} | ||
<st:adjunct includes="io.jenkins.plugins.thememanager.header.main" /> | ||
</j:jelly> |
25 changes: 21 additions & 4 deletions
25
src/main/resources/io/jenkins/plugins/thememanager/header/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
const themeJson = document.getElementById('theme-manager-theme').text | ||
const theme = JSON.parse(themeJson); | ||
(function () { | ||
const themeJson = document.getElementById('theme-manager-theme').text | ||
const theme = JSON.parse(themeJson); | ||
|
||
if (theme.id && theme.id !== '') { | ||
if (theme.id && theme.id !== '') { | ||
document.documentElement.dataset.theme = theme.id | ||
} | ||
} | ||
window.isSystemRespectingTheme = theme.respect_system_appearance | ||
|
||
const propertiesJson = document.getElementById('theme-manager-properties').text | ||
const parsedProperties = JSON.parse(propertiesJson); | ||
|
||
|
||
window.getThemeManagerProperty = function (plugin, propertyName) { | ||
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches | ||
|
||
let propertyNameNormalised = propertyName | ||
if (isSystemRespectingTheme) { | ||
propertyNameNormalised = isDark ? `${propertyName}-dark` : `${propertyName}-light` | ||
} | ||
return parsedProperties[`${plugin}:${propertyNameNormalised}`] | ||
} | ||
})() |