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:
1 parent
25b3a940a3
commit
777380e19f
8 files changed
+132
-110
No files matched your search
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,46 @@
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class ScopesScopeProjectsSettingsIndexController extends Controller {}
|
||||
const THEMES = [
|
||||
{
|
||||
label: 'system',
|
||||
value: 'system-default-theme',
|
||||
},
|
||||
{
|
||||
label: 'light',
|
||||
value: 'light',
|
||||
},
|
||||
{
|
||||
label: 'dark',
|
||||
value: 'dark',
|
||||
},
|
||||
];
|
||||
|
||||
export default class ScopesScopeProjectsSettingsIndexController extends Controller {
|
||||
@controller('application') application;
|
||||
// Services
|
||||
|
||||
@service session;
|
||||
|
||||
// Methods
|
||||
|
||||
/**
|
||||
* Returns available themes
|
||||
*/
|
||||
get themes() {
|
||||
return THEMES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the Application controller's toggleTheme method
|
||||
* @param {string} theme - "light", "dark", or nullish (system default)
|
||||
*/
|
||||
@action
|
||||
toggleTheme({ target: { value: theme } }) {
|
||||
return this.application.toggleTheme(theme);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user