fix(desktop): update dock badge handling based on UI settings
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { isMobile } from "@follow/components/hooks/useMobile.js"
|
||||
import type { UISettings } from "@follow/shared/settings/interface"
|
||||
import { useUnreadAll } from "@follow/store/unread/hooks"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import i18next from "i18next"
|
||||
@@ -13,16 +14,31 @@ import { langChain } from "~/i18n"
|
||||
import { ipcServices } from "~/lib/client"
|
||||
import { loadLanguageAndApply } from "~/lib/load-language"
|
||||
|
||||
const useUpdateDockBadge = () => {
|
||||
const useUpdateDockBadge = (setting: UISettings) => {
|
||||
const unreadCount = useUnreadAll()
|
||||
const { mutate, isPending } = useMutation({
|
||||
mutationFn: async (unread: number) => ipcServices?.dock.setDockBadge(unread),
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (setting.showDockBadge) {
|
||||
ipcServices?.dock.pollingUpdateUnreadCount()
|
||||
} else {
|
||||
ipcServices?.dock.cancelPollingUpdateUnreadCount().then(() => {
|
||||
ipcServices?.dock.setDockBadge(0)
|
||||
})
|
||||
}
|
||||
return
|
||||
}, [setting.showDockBadge])
|
||||
|
||||
useEffect(() => {
|
||||
if (!setting.showDockBadge) {
|
||||
return
|
||||
}
|
||||
if (!isPending) {
|
||||
mutate(unreadCount)
|
||||
}
|
||||
}, [unreadCount, mutate, isPending])
|
||||
}, [unreadCount, mutate, isPending, setting.showDockBadge])
|
||||
}
|
||||
|
||||
const useUISettingSync = () => {
|
||||
@@ -49,18 +65,7 @@ const useUISettingSync = () => {
|
||||
})
|
||||
}, [setting.uiFontFamily, setting.usePointerCursor])
|
||||
|
||||
useEffect(() => {
|
||||
if (setting.showDockBadge) {
|
||||
ipcServices?.dock.pollingUpdateUnreadCount()
|
||||
} else {
|
||||
ipcServices?.dock.cancelPollingUpdateUnreadCount().then(() => {
|
||||
ipcServices?.dock.setDockBadge(0)
|
||||
})
|
||||
}
|
||||
return
|
||||
}, [setting.showDockBadge])
|
||||
|
||||
useUpdateDockBadge()
|
||||
useUpdateDockBadge(setting)
|
||||
}
|
||||
|
||||
const useUXSettingSync = () => {
|
||||
|
||||
Reference in New Issue
Block a user