Add theme selection (#2428)

* fix: 🐛 remove theme from main menu bar and move to settings pag

* chore: 🤖 move toggletheme to app controller
This commit is contained in:
Dharini Jeeva authored and Zhihe Li committed 2024-09-24 11:58:24 -04:00
1 parent 25b3a940a3
commit 777380e19f
8 files changed
+132 -110

No files matched your search

+27 -1
View File
@@ -5,8 +5,8 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { getOwner } from '@ember/application';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
// =services
@@ -49,4 +49,30 @@ export default class ApplicationController extends Controller {
close() {
this.ipc.invoke('closeWindow');
}
/**
* Applies the specified color theme to the root ember element.
* @param {string} theme - "light", "dark", or nullish (system default)
*/
@action
toggleTheme(theme) {
const rootElementSelector = getOwner(this).rootElement;
const rootEl = getOwner(this)
.lookup('service:-document')
.querySelector(rootElementSelector);
this.session.set('data.theme', theme);
switch (theme) {
case 'light':
rootEl.classList.add('rose-theme-light');
rootEl.classList.remove('rose-theme-dark');
break;
case 'dark':
rootEl.classList.add('rose-theme-dark');
rootEl.classList.remove('rose-theme-light');
break;
default:
rootEl.classList.remove('rose-theme-dark');
rootEl.classList.remove('rose-theme-light');
}
}
}