fix: polling unread and add ua for electron api client

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-11-08 21:49:58 +08:00
parent c5500f9b52
commit 549f10d7eb
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
2 changed files with 5 additions and 8 deletions

View File

@ -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}` : ""}`,
}
},
})

View File

@ -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)
}