mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
fix css inject
This commit is contained in:
parent
cdc4c3fe3c
commit
beb19f237d
|
@ -57,8 +57,6 @@ export async function importThemes(files: string[]): Promise<void> {
|
|||
export async function applyTheme(theme: string): Promise<void> {
|
||||
if (!existsSync(path.join(themesDir(), theme))) return
|
||||
const css = await readFile(path.join(themesDir(), theme), 'utf-8')
|
||||
if (insertedCSSKey) {
|
||||
await mainWindow?.webContents.removeInsertedCSS(insertedCSSKey)
|
||||
}
|
||||
await mainWindow?.webContents.removeInsertedCSS(insertedCSSKey || '')
|
||||
insertedCSSKey = await mainWindow?.webContents.insertCSS(css)
|
||||
}
|
||||
|
|
|
@ -66,11 +66,7 @@ const App: React.FC = () => {
|
|||
navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const page = useRoutes(routes)
|
||||
|
||||
const changeTheme = async (): Promise<void> => {
|
||||
setNativeTheme(appTheme)
|
||||
setTheme(appTheme)
|
||||
if (customTheme) await applyTheme(customTheme)
|
||||
const setTitlebar = (): void => {
|
||||
if (!useWindowFrame) {
|
||||
const options = { height: 48 } as TitleBarOverlayOptions
|
||||
try {
|
||||
|
@ -97,8 +93,16 @@ const App: React.FC = () => {
|
|||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
changeTheme()
|
||||
}, [appTheme, systemTheme, customTheme])
|
||||
setNativeTheme(appTheme)
|
||||
setTheme(appTheme)
|
||||
setTitlebar()
|
||||
}, [appTheme, systemTheme])
|
||||
|
||||
useEffect(() => {
|
||||
applyTheme(customTheme || 'default.css').then(() => {
|
||||
setTitlebar()
|
||||
})
|
||||
}, [customTheme])
|
||||
|
||||
const onDragEnd = async (event: DragEndEvent): Promise<void> => {
|
||||
const { active, over } = event
|
||||
|
|
|
@ -343,8 +343,22 @@ export async function importThemes(files: string[]): Promise<void> {
|
|||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('importThemes', files))
|
||||
}
|
||||
|
||||
let applyThemeRunning = false
|
||||
const waitList: string[] = []
|
||||
export async function applyTheme(theme: string): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('applyTheme', theme))
|
||||
if (applyThemeRunning) {
|
||||
waitList.push(theme)
|
||||
return
|
||||
}
|
||||
applyThemeRunning = true
|
||||
try {
|
||||
return await ipcErrorWrapper(window.electron.ipcRenderer.invoke('applyTheme', theme))
|
||||
} finally {
|
||||
applyThemeRunning = false
|
||||
if (waitList.length > 0) {
|
||||
await applyTheme(waitList.shift() || '')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function registerShortcut(
|
||||
|
|
Loading…
Reference in New Issue
Block a user