jenkinsci / theme-manager-plugin

Adds theme management to Jenkins, at a global or user level
https://plugins.jenkins.io/theme-manager/
MIT License
13 stars 15 forks source link

Switch properties to a JavaScript API to support system themes #171

Closed timja closed 1 year ago

timja commented 1 year ago

New JavaScript API, expected use:

if (window.getThemeManagerProperty) {
    setTheme();

    if (window.isSystemRespectingTheme) {
        window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
            setTheme()
        });
    }

function setTheme() {
  const theme = window.getThemeManagerProperty('your-plugin-name', 'theme') || 'your-fallback'
}

}

For theme adaption see: https://github.com/jenkinsci/dark-theme-plugin/pull/385

For plugin adaption see: https://github.com/jenkinsci/workflow-cps-plugin/pull/769

basil commented 1 year ago
======= EXCEPTION START ========
EcmaError: lineNumber=[10] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[http://localhost:37003/jenkins/adjuncts/f41afffc/io/jenkins/plugins/thememanager/header/main.js] message=[TypeError: Cannot read property "text" from null (http://localhost:37003/jenkins/adjuncts/f41afffc/io/jenkins/plugins/thememanager/header/main.js#10)]
org.htmlunit.ScriptException: TypeError: Cannot read property "text" from null (http://localhost:37003/jenkins/adjuncts/f41afffc/io/jenkins/plugins/thememanager/header/main.js#10)
    at org.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:990)
    at org.htmlunit.corejs.javascript.Context.call(Context.java:590)
    at org.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:484)
    at org.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:348)
    at org.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:868)
    at org.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:844)
    at org.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:114)
    at org.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1043)
    at org.htmlunit.html.ScriptElementSupport.executeScriptIfNeeded(ScriptElementSupport.java:194)
    at org.htmlunit.html.ScriptElementSupport$1.execute(ScriptElementSupport.java:118)
    at org.htmlunit.html.ScriptElementSupport.onAllChildrenAddedToPage(ScriptElementSupport.java:141)
    at org.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:191)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:599)
    at org.htmlunit.cyberneko.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:412)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:548)
    at org.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1291)
    at org.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1218)
    at org.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:204)
    at org.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:274)
    at org.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:2969)
    at org.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:1953)
    at org.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:834)
    at org.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:346)
    at org.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:297)
    at org.htmlunit.cyberneko.xerces.parsers.XMLParser.parse(XMLParser.java:76)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.parse(HtmlUnitNekoDOMBuilder.java:842)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parse(HtmlUnitNekoHtmlParser.java:202)
    at org.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:301)
    at org.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:220)
    at org.jvnet.hudson.test.HudsonPageCreator.createPage(HudsonPageCreator.java:53)
    at org.htmlunit.WebClient.loadWebResponseInto(WebClient.java:665)
    at org.htmlunit.WebClient.loadWebResponseInto(WebClient.java:567)
    at org.htmlunit.WebClient.getPage(WebClient.java:485)
    at org.htmlunit.WebClient.getPage(WebClient.java:392)
    at org.htmlunit.WebClient.getPage(WebClient.java:530)
    at org.htmlunit.WebClient.getPage(WebClient.java:512)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.goTo(JenkinsRule.java:2628)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.goTo(JenkinsRule.java:2608)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.login(JenkinsRule.java:2460)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.login(JenkinsRule.java:2338)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.login(JenkinsRule.java:2484)
    at org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategyTest.testDontRestrictJobConfiguration(SpecificUsersAuthorizationStrategyTest.java:966)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:606)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: org.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "text" from null (http://localhost:37003/jenkins/adjuncts/f41afffc/io/jenkins/plugins/thememanager/header/main.js#10)
    at org.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4635)
    at org.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4616)
    at org.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4648)
    at org.htmlunit.corejs.javascript.ScriptRuntime.typeErrorById(ScriptRuntime.java:4653)
    at org.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:4685)
    at org.htmlunit.corejs.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1671)
    at org.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1554)
    at org.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1051)
    at org.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:89)
    at org.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:392)
    at org.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:334)
    at org.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3916)
    at org.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:102)
    at org.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:859)
    at org.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:973)
    ... 52 more
Enclosed exception: 
org.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "text" from null (http://localhost:37003/jenkins/adjuncts/f41afffc/io/jenkins/plugins/thememanager/header/main.js#10)
    at org.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4635)
    at org.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4616)
    at org.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4648)
    at org.htmlunit.corejs.javascript.ScriptRuntime.typeErrorById(ScriptRuntime.java:4653)
    at org.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:4685)
    at org.htmlunit.corejs.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1671)
    at org.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1554)
    at script(http://localhost:37003/jenkins/adjuncts/f41afffc/io/jenkins/plugins/thememanager/header/main.js:10)
    at script(http://localhost:37003/jenkins/adjuncts/f41afffc/io/jenkins/plugins/thememanager/header/main.js:1)
    at org.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1051)
    at org.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:89)
    at org.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:392)
    at org.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:334)
    at org.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3916)
    at org.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:102)
    at org.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:859)
    at org.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:973)
    at org.htmlunit.corejs.javascript.Context.call(Context.java:590)
    at org.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:484)
    at org.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:348)
    at org.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:868)
    at org.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:844)
    at org.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:114)
    at org.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1043)
    at org.htmlunit.html.ScriptElementSupport.executeScriptIfNeeded(ScriptElementSupport.java:194)
    at org.htmlunit.html.ScriptElementSupport$1.execute(ScriptElementSupport.java:118)
    at org.htmlunit.html.ScriptElementSupport.onAllChildrenAddedToPage(ScriptElementSupport.java:141)
    at org.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:191)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:599)
    at org.htmlunit.cyberneko.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:412)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:548)
    at org.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1291)
    at org.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1218)
    at org.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:204)
    at org.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:274)
    at org.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:2969)
    at org.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:1953)
    at org.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:834)
    at org.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:346)
    at org.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:297)
    at org.htmlunit.cyberneko.xerces.parsers.XMLParser.parse(XMLParser.java:76)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.parse(HtmlUnitNekoDOMBuilder.java:842)
    at org.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parse(HtmlUnitNekoHtmlParser.java:202)
    at org.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:301)
    at org.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:220)
    at org.jvnet.hudson.test.HudsonPageCreator.createPage(HudsonPageCreator.java:53)
    at org.htmlunit.WebClient.loadWebResponseInto(WebClient.java:665)
    at org.htmlunit.WebClient.loadWebResponseInto(WebClient.java:567)
    at org.htmlunit.WebClient.getPage(WebClient.java:485)
    at org.htmlunit.WebClient.getPage(WebClient.java:392)
    at org.htmlunit.WebClient.getPage(WebClient.java:530)
    at org.htmlunit.WebClient.getPage(WebClient.java:512)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.goTo(JenkinsRule.java:2628)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.goTo(JenkinsRule.java:2608)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.login(JenkinsRule.java:2460)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.login(JenkinsRule.java:2338)
    at org.jvnet.hudson.test.JenkinsRule$WebClient.login(JenkinsRule.java:2484)
    at org.jenkinsci.plugins.authorizeproject.strategy.SpecificUsersAuthorizationStrategyTest.testDontRestrictJobConfiguration(SpecificUsersAuthorizationStrategyTest.java:966)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:606)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at java.base/java.lang.Thread.run(Thread.java:1583)
======= EXCEPTION END ========