mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
		
			
				
	
	
		
			71 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import { computed } from 'vue';
 | 
						|
import { useI18n } from 'vue-i18n';
 | 
						|
import {
 | 
						|
  ICON_APPEARANCE,
 | 
						|
  ICON_LIGHT_MODE,
 | 
						|
  ICON_DARK_MODE,
 | 
						|
  ICON_SYSTEM_MODE,
 | 
						|
} from 'dashboard/helper/commandbar/icons';
 | 
						|
import { LocalStorage } from 'shared/helpers/localStorage';
 | 
						|
import { LOCAL_STORAGE_KEYS } from 'dashboard/constants/localStorage';
 | 
						|
import { setColorTheme } from 'dashboard/helper/themeHelper.js';
 | 
						|
 | 
						|
const getThemeOptions = t => [
 | 
						|
  {
 | 
						|
    key: 'light',
 | 
						|
    label: t('COMMAND_BAR.COMMANDS.LIGHT_MODE'),
 | 
						|
    icon: ICON_LIGHT_MODE,
 | 
						|
  },
 | 
						|
  {
 | 
						|
    key: 'dark',
 | 
						|
    label: t('COMMAND_BAR.COMMANDS.DARK_MODE'),
 | 
						|
    icon: ICON_DARK_MODE,
 | 
						|
  },
 | 
						|
  {
 | 
						|
    key: 'auto',
 | 
						|
    label: t('COMMAND_BAR.COMMANDS.SYSTEM_MODE'),
 | 
						|
    icon: ICON_SYSTEM_MODE,
 | 
						|
  },
 | 
						|
];
 | 
						|
 | 
						|
const setAppearance = theme => {
 | 
						|
  LocalStorage.set(LOCAL_STORAGE_KEYS.COLOR_SCHEME, theme);
 | 
						|
  const isOSOnDarkMode = window.matchMedia(
 | 
						|
    '(prefers-color-scheme: dark)'
 | 
						|
  ).matches;
 | 
						|
  setColorTheme(isOSOnDarkMode);
 | 
						|
};
 | 
						|
 | 
						|
export function useAppearanceHotKeys() {
 | 
						|
  const { t } = useI18n();
 | 
						|
 | 
						|
  const themeOptions = computed(() => getThemeOptions(t));
 | 
						|
 | 
						|
  const goToAppearanceHotKeys = computed(() => {
 | 
						|
    const options = themeOptions.value.map(theme => ({
 | 
						|
      id: theme.key,
 | 
						|
      title: theme.label,
 | 
						|
      parent: 'appearance_settings',
 | 
						|
      section: t('COMMAND_BAR.SECTIONS.APPEARANCE'),
 | 
						|
      icon: theme.icon,
 | 
						|
      handler: () => {
 | 
						|
        setAppearance(theme.key);
 | 
						|
      },
 | 
						|
    }));
 | 
						|
    return [
 | 
						|
      {
 | 
						|
        id: 'appearance_settings',
 | 
						|
        title: t('COMMAND_BAR.COMMANDS.CHANGE_APPEARANCE'),
 | 
						|
        section: t('COMMAND_BAR.SECTIONS.APPEARANCE'),
 | 
						|
        icon: ICON_APPEARANCE,
 | 
						|
        children: options.map(option => option.id),
 | 
						|
      },
 | 
						|
      ...options,
 | 
						|
    ];
 | 
						|
  });
 | 
						|
 | 
						|
  return {
 | 
						|
    goToAppearanceHotKeys,
 | 
						|
  };
 | 
						|
}
 |