@@ -5,8 +5,10 @@ import PopupHeader from './components/PopupHeader';
55import PopupContainer from './components/PopupContainer' ;
66import PopupFooter from './components/PopupFooter' ;
77import ContextMenu from './components/ContextMenu' ;
8+ import { applyTheme } from './utils/theme' ;
89import './Popup.scss' ;
910
11+
1012interface PopupProps {
1113 config : Configuration
1214}
@@ -62,52 +64,4 @@ function adjustHeight(length: number) {
6264 const rootStyle = document . documentElement . style ;
6365 const height = ( length + 2 ) * 30 ;
6466 rootStyle . setProperty ( '--startup-height' , ( height > 600 ) ? '600px' : height + 'px' ) ;
65- }
66-
67- function applyTheme ( theme : 'auto' | 'light' | 'dark' ) {
68- const rootElm = document . documentElement ;
69-
70- const applyDarkTheme = ( ) => {
71- rootElm . classList . add ( 'theme-dark' ) ;
72- rootElm . classList . remove ( 'theme-light' ) ;
73- chrome . action . setIcon ( {
74- path : {
75- "16" : "/icons/qbm16-dark.png" ,
76- "32" : "/icons/qbm32-dark.png"
77- }
78- } ) ;
79- }
80-
81- const applyLightTheme = ( ) => {
82- rootElm . classList . add ( 'theme-light' ) ;
83- rootElm . classList . remove ( 'theme-dark' ) ;
84- chrome . action . setIcon ( {
85- path : {
86- "16" : "/icons/qbm16.png" ,
87- "32" : "/icons/qbm32.png"
88- }
89- } ) ;
90- }
91-
92- switch ( theme ) {
93- case 'light' :
94- applyLightTheme ( ) ;
95- break ;
96- case 'dark' :
97- applyDarkTheme ( ) ;
98- break ;
99- case 'auto' :
100- default :
101- const mql = window . matchMedia ( '(prefers-color-scheme: dark)' ) ;
102- const colorSchemeTest = ( e : MediaQueryListEvent | MediaQueryList ) => {
103- if ( e . matches ) {
104- applyDarkTheme ( ) ;
105- } else {
106- applyLightTheme ( ) ;
107- }
108- } ;
109- mql . onchange = colorSchemeTest ;
110- colorSchemeTest ( mql ) ;
111- break ;
112- }
11367}
0 commit comments