fix: polling unread and add ua for electron api client
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
parent
c5500f9b52
commit
549f10d7eb
|
|
@ -5,7 +5,7 @@ import { ofetch } from "ofetch"
|
|||
|
||||
import type { AppType } from "../../../../packages/shared/src/hono"
|
||||
import { logger } from "../logger"
|
||||
import { getAuthSessionToken } from "./user"
|
||||
import { getAuthSessionToken, getUser } from "./user"
|
||||
|
||||
const abortController = new AbortController()
|
||||
export const apiFetch = ofetch.create({
|
||||
|
|
@ -33,10 +33,12 @@ export const apiClient = hc<AppType>("", {
|
|||
fetch: async (input, options = {}) => apiFetch(input.toString(), options),
|
||||
headers() {
|
||||
const authSessionToken = getAuthSessionToken()
|
||||
const user = getUser()
|
||||
return {
|
||||
"X-App-Version": PKG.version,
|
||||
"X-App-Dev": process.env.NODE_ENV === "development" ? "1" : "0",
|
||||
Cookie: authSessionToken ? `authjs.session-token=${authSessionToken}` : "",
|
||||
"User-Agent": `Follow/${PKG.version}${user?.id ? ` uid: ${user.id}` : ""}`,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,10 +4,6 @@ import { setDockCount } from "../lib/dock"
|
|||
import { sleep } from "../lib/utils"
|
||||
import { t } from "./_instance"
|
||||
|
||||
const timerMap = {
|
||||
unread: undefined as any,
|
||||
}
|
||||
|
||||
const pollingMap = {
|
||||
unread: false,
|
||||
}
|
||||
|
|
@ -27,8 +23,8 @@ async function updateUnreadCount() {
|
|||
}
|
||||
|
||||
export async function pollingUpdateUnreadCount() {
|
||||
if (timerMap.unread) {
|
||||
timerMap.unread = clearTimeout(timerMap.unread)
|
||||
if (pollingMap.unread) {
|
||||
return
|
||||
}
|
||||
|
||||
pollingMap.unread = true
|
||||
|
|
@ -42,5 +38,4 @@ export async function pollingUpdateUnreadCount() {
|
|||
|
||||
export async function cancelPollingUpdateUnreadCount() {
|
||||
pollingMap.unread = false
|
||||
timerMap.unread = clearTimeout(timerMap.unread)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue