Skip to content
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

Correct order of property loading for simple pages #211

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?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" />
<j:new var="h" className="hudson.Functions"/>
<!-- Load the default styles -->
<st:include it="${h.simplePageDecorators.get(h.simplePageDecorators.size() - 1)}"
<st:include it="${h.simplePageDecorators.get(h.simplePageDecorators.size() - 1)}"
page="simple-head.jelly"
optional="true"/>

<script id="theme-manager-theme" type="application/json">{ "id": "${it.themeKey}", "respect_system_appearance": ${it.respectSystemAppearance} }</script>
<st:adjunct includes="io.jenkins.plugins.thememanager.header.main" />
${it.getHeaderHtml()}
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
}
window.isSystemRespectingTheme = theme.respect_system_appearance

const propertiesJson = document.getElementById('theme-manager-properties').text
const parsedProperties = JSON.parse(propertiesJson);
const propertiesJson = document.getElementById('theme-manager-properties')
// may not be present, e.g. on BlueOcean where the theme is not marked as BlueOcean compatible
if (propertiesJson) {
const parsedProperties = JSON.parse(propertiesJson.text);

window.getThemeManagerProperty = function (plugin, propertyName) {
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches

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`
let propertyNameNormalised = propertyName
if (isSystemRespectingTheme) {
propertyNameNormalised = isDark ? `${propertyName}-dark` : `${propertyName}-light`
}
return parsedProperties[`${plugin}:${propertyNameNormalised}`]
}
return parsedProperties[`${plugin}:${propertyNameNormalised}`]
}
})()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.jenkins.plugins.thememanager;

import jenkins.model.Jenkins;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;

public class PageDecoratorTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void testJavaScriptLoadsOnSimpleAndRegularPages() throws Exception {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
MockAuthorizationStrategy auth =
new MockAuthorizationStrategy().grant(Jenkins.READ).everywhere().to("alice");
j.jenkins.setAuthorizationStrategy(auth);

JenkinsRule.WebClient wc = j.createWebClient();

wc.login("alice");
wc.goTo("");
}
}