Skip to content

Commit a739b29

Browse files
committed
Fixed the native interface paths
1 parent dd791de commit a739b29

8 files changed

Lines changed: 94 additions & 141 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.codename1.initializr;
2+
3+
public class WebsiteThemeNativeImpl {
4+
public boolean isDarkMode() {
5+
return false;
6+
}
7+
8+
public boolean isSupported() {
9+
return false;
10+
}
11+
12+
}

scripts/initializr/common/native/javascript/com_codename1_initializr_WebsiteThemeNative.js

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface com_codename1_initializr_WebsiteThemeNativeImpl : NSObject {
4+
}
5+
6+
-(BOOL)isDarkMode;
7+
-(BOOL)isSupported;
8+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import "com_codename1_initializr_WebsiteThemeNativeImpl.h"
2+
3+
@implementation com_codename1_initializr_WebsiteThemeNativeImpl
4+
5+
-(BOOL)isDarkMode{
6+
return NO;
7+
}
8+
9+
-(BOOL)isSupported{
10+
return NO;
11+
}
12+
13+
@end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(function(exports){
2+
3+
var o = {};
4+
5+
o.isDarkMode_ = function(callback) {
6+
var dark = false;
7+
try {
8+
var parentDoc = (window.parent && window.parent.document) ? window.parent.document : null;
9+
if (parentDoc && parentDoc.body && parentDoc.body.classList) {
10+
dark = parentDoc.body.classList.contains("dark") || parentDoc.body.classList.contains("cn1-initializr-dark");
11+
}
12+
if (!dark && window.parent && window.parent.localStorage) {
13+
var pref = window.parent.localStorage.getItem("pref-theme");
14+
if (pref === "dark") {
15+
dark = true;
16+
} else if (pref === "light") {
17+
dark = false;
18+
}
19+
}
20+
} catch (ignored) {
21+
// Ignore parent access failures and fallback below.
22+
}
23+
if (!dark && window.matchMedia) {
24+
dark = window.matchMedia("(prefers-color-scheme: dark)").matches;
25+
}
26+
callback.complete(!!dark);
27+
};
28+
29+
o.isSupported_ = function(callback) {
30+
callback.complete(true);
31+
};
32+
33+
exports.com_codename1_initializr_WebsiteThemeNative= o;
34+
35+
})(cn1_get_native_interfaces());
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.codename1.initializr;
2+
3+
public class WebsiteThemeNativeImpl implements com.codename1.initializr.WebsiteThemeNative{
4+
public boolean isDarkMode() {
5+
return false;
6+
}
7+
8+
public boolean isSupported() {
9+
return false;
10+
}
11+
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace com.codename1.initializr{
2+
3+
4+
public class WebsiteThemeNativeImpl : IWebsiteThemeNativeImpl {
5+
public bool isDarkMode() {
6+
return false;
7+
}
8+
9+
public bool isSupported() {
10+
return false;
11+
}
12+
13+
}
14+
}

scripts/website/build.sh

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -575,99 +575,6 @@ JAVA
575575
mkdir -p "${output_dir}"
576576
unzip -q -o "${result_zip}" -d "${output_dir}"
577577

578-
if [ -f "${output_dir}/style.css" ] && ! grep -q "CN1 initializr website dark-mode bridge" "${output_dir}/style.css"; then
579-
cat >> "${output_dir}/style.css" <<'CSS'
580-
581-
/* CN1 initializr website dark-mode bridge */
582-
html.cn1-site-dark,
583-
html.cn1-site-dark body {
584-
background: #0a111d !important;
585-
}
586-
587-
html.cn1-site-dark #cn1-splash {
588-
color: #d8e4ff !important;
589-
}
590-
591-
html.cn1-site-dark #cn1-splash .progress-bar {
592-
border-color: rgba(84, 128, 221, 0.55) !important;
593-
background-color: rgba(10, 18, 31, 0.92) !important;
594-
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.7) inset, 0 1px 0 rgba(110, 146, 214, 0.2) !important;
595-
}
596-
CSS
597-
fi
598-
599-
if [ -f "${output_dir}/index.html" ] && ! grep -q "CN1 initializr website theme bridge" "${output_dir}/index.html"; then
600-
local theme_bridge_js
601-
theme_bridge_js="$(mktemp)"
602-
cat > "${theme_bridge_js}" <<'JS'
603-
<script>
604-
// CN1 initializr website theme bridge
605-
(function() {
606-
var root = document.documentElement;
607-
function syncFromParentTheme() {
608-
var dark = false;
609-
try {
610-
var parentDoc = (window.parent && window.parent.document) ? window.parent.document : null;
611-
if (parentDoc && parentDoc.body) {
612-
dark = parentDoc.body.classList.contains("dark") || parentDoc.body.classList.contains("cn1-initializr-dark");
613-
}
614-
if (!dark && window.parent && window.parent.localStorage) {
615-
var pref = window.parent.localStorage.getItem("pref-theme");
616-
if (pref === "dark") {
617-
dark = true;
618-
} else if (pref === "light") {
619-
dark = false;
620-
}
621-
}
622-
} catch (e) {
623-
// Ignore and fallback to local media query.
624-
}
625-
if (!dark && window.matchMedia) {
626-
dark = window.matchMedia("(prefers-color-scheme: dark)").matches;
627-
}
628-
root.classList.toggle("cn1-site-dark", !!dark);
629-
}
630-
syncFromParentTheme();
631-
var observer = null;
632-
try {
633-
if (window.parent && window.parent.document && window.parent.document.body && window.parent.MutationObserver) {
634-
observer = new window.parent.MutationObserver(syncFromParentTheme);
635-
observer.observe(window.parent.document.body, { attributes: true, attributeFilter: ["class"] });
636-
}
637-
} catch (e) {}
638-
if (window.matchMedia) {
639-
var mq = window.matchMedia("(prefers-color-scheme: dark)");
640-
if (mq.addEventListener) {
641-
mq.addEventListener("change", syncFromParentTheme);
642-
} else if (mq.addListener) {
643-
mq.addListener(syncFromParentTheme);
644-
}
645-
}
646-
window.addEventListener("storage", syncFromParentTheme);
647-
window.setInterval(syncFromParentTheme, 700);
648-
})();
649-
</script>
650-
JS
651-
awk -v inject_file="${theme_bridge_js}" '
652-
BEGIN {
653-
injected = 0;
654-
while ((getline line < inject_file) > 0) {
655-
snippet = snippet line "\n";
656-
}
657-
close(inject_file);
658-
}
659-
{
660-
if (!injected && $0 ~ /<\/head>/) {
661-
printf "%s", snippet;
662-
injected = 1;
663-
}
664-
print;
665-
}
666-
' "${output_dir}/index.html" > "${output_dir}/index.html.tmp"
667-
mv "${output_dir}/index.html.tmp" "${output_dir}/index.html"
668-
rm -f "${theme_bridge_js}"
669-
fi
670-
671578
if [ ! -f "${output_dir}/index.html" ]; then
672579
echo "Initializr website bundle is missing index.html after extraction." >&2
673580
exit 1

0 commit comments

Comments
 (0)