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

Dark mode #4244

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@
></a
>
</li>
<li>
<a
id="darkModeIcon"
class="tooltipped"
data-position="bottom"
><i class="material-icons md-48"
>brightness_4</i
></a>
</li>
<li>
<a
id="mergeWithCurrentIcon"
Expand Down
35 changes: 35 additions & 0 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,28 @@ class Activity {
//Flag to check if any other input box is active or not
this.isInputON = false;

// Flag to check if dark mode is on or not
this.isDarkModeON = false;
try {
console.log("log from activity");
if (this.storage.darkMode === undefined) {
this.isDarkModeON = false;
} else if (this.storage.darkMode !== null) {
this.isDarkModeON = this.storage.darkMode;

if (typeof this.isDarkModeON === "string") {
if (this.isDarkModeON === "true") {
this.isDarkModeON = true;
} else if (this.isDarkModeON === "false") {
this.isDarkModeON = false;
}
}
}
} catch (e) {
console.error("Error accessing darkMode storage:", e);
this.isDarkModeON = false;
}

this.beginnerMode = true;
try {
if (this.storage.beginnerMode === undefined) {
Expand Down Expand Up @@ -6464,6 +6486,17 @@ class Activity {

this._createErrorContainers();

// Function to toggle dark mode
this.toggleDarkMode = () => {
this.isDarkModeON = !this.isDarkModeON; // Toggle the boolean value
console.log(`Dark Mode is now ${this.isDarkModeON ? "ON" : "OFF"}`);
try {
this.storage.darkMode = this.isDarkModeON.toString(); // Save the state as a string
} catch (e) {
console.error("Error saving darkMode state to storage:", e);
}
};

/* Z-Order (top to bottom):
* menus
* palettes
Expand Down Expand Up @@ -6530,6 +6563,7 @@ class Activity {
this.toolbar.renderModeSelectIcon(doSwitchMode, doRecordButton, doAnalytics, doOpenPlugin, deletePlugin, setScroller);
this.toolbar.renderRunSlowlyIcon(doSlowButton);
this.toolbar.renderRunStepIcon(doStepButton);
this.toolbar.renderDarkModeIcon(this.toggleDarkMode);
this.toolbar.renderMergeIcon(_doMergeLoad);
this.toolbar.renderRestoreIcon(restoreTrash);
if (_THIS_IS_MUSIC_BLOCKS_) {
Expand Down Expand Up @@ -7093,6 +7127,7 @@ class Activity {
saveLocally() {
try {
localStorage.setItem('beginnerMode', this.beginnerMode.toString());
localStorage.setItem('isDarkModeON', this.isDarkModeON.toString());
} catch (e) {
console.error('Error saving to localStorage:', e);
}
Expand Down
14 changes: 13 additions & 1 deletion js/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Toolbar {
["delPluginIcon", _("Delete plugin")],
["enableHorizScrollIcon", _("Enable horizontal scrolling")],
["disableHorizScrollIcon", _("Disable horizontal scrolling")],
["darkModeIcon", _("Change theme")],
["mergeWithCurrentIcon", _("Merge with current project")],
["chooseKeyIcon", _("Set Pitch Preview")],
["toggleJavaScriptIcon", _("JavaScript Editor")],
Expand Down Expand Up @@ -128,6 +129,7 @@ class Toolbar {
_("Delete plugin"),
_("Enable horizontal scrolling"),
_("Disable horizontal scrolling"),
_("Change theme"),
_("Merge with current project"),
_("Set Pitch Preview"),
_("JavaScript Editor"),
Expand Down Expand Up @@ -193,6 +195,7 @@ class Toolbar {
["delPluginIcon", _("Delete plugin")],
["enableHorizScrollIcon", _("Enable horizontal scrolling")],
["disableHorizScrollIcon", _("Disable horizontal scrolling")],
["darkModeIcon", _("Change theme")],
["mergeWithCurrentIcon", _("Merge with current project")],
["toggleJavaScriptIcon", _("JavaScript Editor")],
["restoreIcon", _("Restore")],
Expand Down Expand Up @@ -249,6 +252,7 @@ class Toolbar {
_("Delete plugin"),
_("Enable horizontal scrolling"),
_("Disable horizontal scrolling"),
_("Change theme"),
_("Merge with current project"),
_("JavaScript Editor"),
_("Restore"),
Expand Down Expand Up @@ -422,7 +426,7 @@ class Toolbar {

/**
* Renders the load icon with the provided onclick handler.
*
*
* @public
* @param {Function} onclick - The onclick handler for the load icon.
* @returns {void}
Expand All @@ -435,6 +439,14 @@ class Toolbar {
};
}

renderDarkModeIcon(onclick) {
const darkModeIcon = docById("darkModeIcon");

darkModeIcon.onclick = () => {
onclick();
}
}

/**
* Renders the wrap icon.
*
Expand Down
Loading
Loading