Skip to content

Commit afcb471

Browse files
committed
feat: set default settings for localStorage and implement theme handling
1 parent 09a57d9 commit afcb471

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

webapp/controller/Main.controller.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ export default class Main extends BaseController {
4747

4848
public onInit() {
4949
this.db = new Database();
50+
this.setDefaultSettings();
5051
void this.handleInit();
5152
this.showWelcomeDialog();
5253
this.setModel(new JSONModel(this.local, true), "local");
54+
this.handleTheme();
5355
}
5456

5557
private async handleInit() {
@@ -78,6 +80,33 @@ export default class Main extends BaseController {
7880
this.focusSearch();
7981
}
8082

83+
private setDefaultSettings() {
84+
if (localStorage.getItem("copyWithPrefix") === null) {
85+
localStorage.setItem("copyWithPrefix", "true");
86+
}
87+
if (localStorage.getItem("resetSearchAfterCopy") === null) {
88+
localStorage.setItem("resetSearchAfterCopy", "true");
89+
}
90+
if (localStorage.getItem("theme") === null) {
91+
localStorage.setItem("theme", "System");
92+
}
93+
}
94+
95+
private handleTheme() {
96+
const theme = localStorage.getItem("theme") || "System";
97+
this.applyTheme(theme);
98+
99+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
100+
mediaQuery.addEventListener("change", (e) => {
101+
const darkMode = e.matches;
102+
if (darkMode) {
103+
this.applyTheme("Dark");
104+
} else {
105+
this.applyTheme("Light");
106+
}
107+
});
108+
}
109+
81110
private async refresh(): Promise<void> {
82111
const customTransactions = await this.db.getTransactions();
83112
const transactions = [...this.standardTransactions, ...customTransactions];

0 commit comments

Comments
 (0)