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

Fix light mode persistence #107

Merged
merged 2 commits into from
Jun 25, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file. Each batch

It is a summary of changes that would be pertinent to the end user of the PGEtinker website. For a comprehensive history of changes made to the project, please refer to the repository's commit history.

## 2024-06-25

- Fixed light theme persistence

## 2024-06-19

- Fixed [Issue #105](https://github.com/Moros1138/PGEtinker/issues/105)
- Fixed other dialog styles for the portrait layout

Expand Down
12 changes: 3 additions & 9 deletions resources/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ class PGEtinker
}
}

this.theme = window.localStorage.getItem("pgetinkerTheme");
if(this.theme !== "dark" && this.theme !== "light")
this.theme = "dark";

document.querySelector("#settings-menu")?.addEventListener("click", (event) =>
{
event.preventDefault();
Expand Down Expand Up @@ -460,10 +456,8 @@ class PGEtinker

async UpdateTheme()
{
// save theme into localStorage
setStorageValue("theme", this.theme);

let light = (this.theme === "light");
const theme = getStorageValue("theme");
let light = (theme === "light");

// update editor theme
await this.editorPanel.updateConfiguration();
Expand All @@ -481,7 +475,7 @@ class PGEtinker
goldenLayoutLightThemeStyle.disabled = !light;

// update player theme
this.playerPanel.setTheme(this.theme);
this.playerPanel.setTheme(theme);
}, 200);

}
Expand Down
4 changes: 3 additions & 1 deletion resources/js/lib/settingsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ export default function settingsDialog(state)
state.theme = "light";

createToast(`Changing theme: ${state.theme}`, ToastType.Info);
setStorageValue("theme", state.theme);

state.UpdateTheme();
},
["dark", "light"],
state.theme
getStorageValue("theme")
));


Expand Down
15 changes: 11 additions & 4 deletions resources/js/lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ export function conformStorage(): void
setStorageValue("code", JSON.parse(code));
}

let theme = store.getItem("pgetinkerTheme");
store.removeItem("pgetinkerTheme");
if(theme)
if(getStorageValue("theme") == null)
{
setStorageValue("theme", theme);
let theme = store.getItem("pgetinkerTheme");
store.removeItem("pgetinkerTheme");
if(theme)
{
setStorageValue("theme", theme);
}
else
{
setStorageValue("theme", "dark");
}
}

if(getStorageValue("diagnostics.javidMode") == null)
Expand Down