mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +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> {
|
export async function applyTheme(theme: string): Promise<void> {
|
||||||
if (!existsSync(path.join(themesDir(), theme))) return
|
if (!existsSync(path.join(themesDir(), theme))) return
|
||||||
const css = await readFile(path.join(themesDir(), theme), 'utf-8')
|
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)
|
insertedCSSKey = await mainWindow?.webContents.insertCSS(css)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,11 +66,7 @@ const App: React.FC = () => {
|
|||||||
navigate = useNavigate()
|
navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const page = useRoutes(routes)
|
const page = useRoutes(routes)
|
||||||
|
const setTitlebar = (): void => {
|
||||||
const changeTheme = async (): Promise<void> => {
|
|
||||||
setNativeTheme(appTheme)
|
|
||||||
setTheme(appTheme)
|
|
||||||
if (customTheme) await applyTheme(customTheme)
|
|
||||||
if (!useWindowFrame) {
|
if (!useWindowFrame) {
|
||||||
const options = { height: 48 } as TitleBarOverlayOptions
|
const options = { height: 48 } as TitleBarOverlayOptions
|
||||||
try {
|
try {
|
||||||
@ -97,8 +93,16 @@ const App: React.FC = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changeTheme()
|
setNativeTheme(appTheme)
|
||||||
}, [appTheme, systemTheme, customTheme])
|
setTheme(appTheme)
|
||||||
|
setTitlebar()
|
||||||
|
}, [appTheme, systemTheme])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
applyTheme(customTheme || 'default.css').then(() => {
|
||||||
|
setTitlebar()
|
||||||
|
})
|
||||||
|
}, [customTheme])
|
||||||
|
|
||||||
const onDragEnd = async (event: DragEndEvent): Promise<void> => {
|
const onDragEnd = async (event: DragEndEvent): Promise<void> => {
|
||||||
const { active, over } = event
|
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))
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('importThemes', files))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let applyThemeRunning = false
|
||||||
|
const waitList: string[] = []
|
||||||
export async function applyTheme(theme: string): Promise<void> {
|
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(
|
export async function registerShortcut(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user