|
26 | 26 | getMacroExpansion, getOctaveRatio, getTemperament, GOHOMEBUTTON, |
27 | 27 | GOHOMEFADEDBUTTON, GRAND, HelpWidget, HIDEBLOCKSFADEDBUTTON, |
28 | 28 | hideDOMLabel, initBasicProtoBlocks, initPalettes, |
29 | | - INLINECOLLAPSIBLES, jQuery, JSEditor, LanguageBox, Logo, MSGBLOCK, |
| 29 | + INLINECOLLAPSIBLES, jQuery, JSEditor, LanguageBox, ThemeBox, Logo, MSGBLOCK, |
30 | 30 | NANERRORMSG, NOACTIONERRORMSG, NOBOXERRORMSG, NOINPUTERRORMSG, |
31 | 31 | NOMICERRORMSG, NOSQRTERRORMSG, NOSTRINGERRORMSG, PALETTEFILLCOLORS, |
32 | 32 | PALETTESTROKECOLORS, PALETTEHIGHLIGHTCOLORS, HIGHLIGHTSTROKECOLORS, |
@@ -85,6 +85,7 @@ let MYDEFINES = [ |
85 | 85 | "activity/turtle-singer", |
86 | 86 | "activity/turtle-painter", |
87 | 87 | "activity/languagebox", |
| 88 | + "activity/themebox", |
88 | 89 | "activity/basicblocks", |
89 | 90 | "activity/blockfactory", |
90 | 91 | "activity/piemenus", |
@@ -272,15 +273,17 @@ class Activity { |
272 | 273 | //Flag to check if any other input box is active or not |
273 | 274 | this.isInputON = false; |
274 | 275 |
|
275 | | - // If the theme is set to "darkMode", enable dark mode else diable |
| 276 | + this.themes = ["light", "dark"]; |
276 | 277 | try { |
277 | | - if (this.storage.myThemeName === "darkMode") { |
278 | | - body.classList.add("dark-mode"); |
279 | | - } else { |
280 | | - body.classList.remove("dark-mode"); |
| 278 | + for (let i = 0; i < this.themes.length; i++) { |
| 279 | + if (this.themes[i] === this.storage.themePreference) { |
| 280 | + body.classList.add(this.themes[i]); |
| 281 | + } else { |
| 282 | + body.classList.remove(this.themes[i]); |
| 283 | + } |
281 | 284 | } |
282 | 285 | } catch (e) { |
283 | | - console.error("Error accessing myThemeName storage:", e); |
| 286 | + console.error("Error accessing themePreference storage:", e); |
284 | 287 | } |
285 | 288 |
|
286 | 289 | this.beginnerMode = true; |
@@ -385,6 +388,7 @@ class Activity { |
385 | 388 | this.logo = null; |
386 | 389 | this.pasteBox = null; |
387 | 390 | this.languageBox = null; |
| 391 | + this.themeBox = null; |
388 | 392 | this.planet = null; |
389 | 393 | window.converter = null; |
390 | 394 | this.buttonsVisible = true; |
@@ -6678,28 +6682,7 @@ class Activity { |
6678 | 6682 |
|
6679 | 6683 | this._createErrorContainers(); |
6680 | 6684 |
|
6681 | | - // Function to toggle theme mode |
6682 | | - this.toggleThemeMode = () => { |
6683 | | - if (this.storage.myThemeName === "darkMode") { |
6684 | | - delete this.storage.myThemeName; |
6685 | | - localStorage.setItem("darkMode", "disabled"); |
6686 | | - } else { |
6687 | | - this.storage.myThemeName = "darkMode"; |
6688 | | - localStorage.setItem("darkMode", "enabled"); |
6689 | | - } |
6690 | | - const planetIframe = document.getElementById("planet-iframe"); |
6691 | | - if (planetIframe) { |
6692 | | - planetIframe.contentWindow.postMessage( |
6693 | | - { darkMode: localStorage.getItem("darkMode") }, |
6694 | | - "*" |
6695 | | - ); |
6696 | | - } |
6697 | | - try { |
6698 | | - window.location.reload(); |
6699 | | - } catch (e) { |
6700 | | - console.error("Error reloading the window:", e); |
6701 | | - } |
6702 | | - }; |
| 6685 | + |
6703 | 6686 |
|
6704 | 6687 | /* Z-Order (top to bottom): |
6705 | 6688 | * menus |
@@ -6727,6 +6710,7 @@ class Activity { |
6727 | 6710 |
|
6728 | 6711 | this.pasteBox = new PasteBox(this); |
6729 | 6712 | this.languageBox = new LanguageBox(this); |
| 6713 | + this.themeBox = new ThemeBox(this); |
6730 | 6714 |
|
6731 | 6715 | // Show help on startup if first-time user. |
6732 | 6716 | if (this.firstTimeUser) { |
@@ -6768,7 +6752,7 @@ class Activity { |
6768 | 6752 | this.toolbar.renderModeSelectIcon(doSwitchMode, doRecordButton, doAnalytics, doOpenPlugin, deletePlugin, setScroller); |
6769 | 6753 | this.toolbar.renderRunSlowlyIcon(doSlowButton); |
6770 | 6754 | this.toolbar.renderRunStepIcon(doStepButton); |
6771 | | - this.toolbar.renderDarkModeIcon(this.toggleThemeMode); |
| 6755 | + this.toolbar.renderThemeSelectIcon(this.themeBox, this.themes); |
6772 | 6756 | this.toolbar.renderMergeIcon(_doMergeLoad); |
6773 | 6757 | this.toolbar.renderRestoreIcon(restoreTrash); |
6774 | 6758 | if (_THIS_IS_MUSIC_BLOCKS_) { |
@@ -7333,7 +7317,7 @@ class Activity { |
7333 | 7317 | saveLocally() { |
7334 | 7318 | try { |
7335 | 7319 | localStorage.setItem('beginnerMode', this.beginnerMode.toString()); |
7336 | | - localStorage.setItem('isDarkModeON', this.isDarkModeON.toString()); |
| 7320 | + localStorage.setItem("themePreference", this.themePreference.toString()); |
7337 | 7321 | } catch (e) { |
7338 | 7322 | // eslint-disable-next-line no-console |
7339 | 7323 | console.error('Error saving to localStorage:', e); |
|
0 commit comments