Files
Folo/apps/desktop/layer/main/src/lib/user.ts
T
Innei 3bee8dbd20 feat(api): integrate FollowClient for API interactions
- Introduced the FollowClient from `@follow-app/client-sdk` to manage API requests and responses, enhancing the structure and maintainability of the API client.
- Refactored the API client to utilize the new FollowClient, including request and response interceptors for logging and error handling.
- Updated the `updateNotificationsToken` and `deleteNotificationsToken` functions to use the new API methods.
- Added a new IPC service for better communication between the main and renderer processes.

This update improves API interaction efficiency and enhances error handling across the application.

Signed-off-by: Innei <tukon479@gmail.com>
2025-09-04 01:06:39 +08:00

40 lines
1.1 KiB
TypeScript

import type { Credentials } from "@eneris/push-receiver/dist/types"
import { isLinux, isMacOS, isWindows } from "~/env"
import { logger } from "~/logger"
import { apiClient } from "./api-client"
import { store } from "./store"
const notificationChannel = isMacOS
? "macos"
: isWindows
? "windows"
: isLinux
? "linux"
: "desktop"
export const updateNotificationsToken = async (newCredentials?: Credentials) => {
if (newCredentials) {
store.set("notifications-credentials", newCredentials)
}
const credentials = newCredentials || store.get("notifications-credentials")
if (credentials?.fcm?.token) {
try {
await apiClient.messaging.createToken({
token: credentials.fcm.token,
channel: notificationChannel,
})
logger.info("updateNotificationsToken success: ", credentials.fcm.token)
} catch (error) {
logger.error("updateNotificationsToken error: ", error)
}
}
}
export const deleteNotificationsToken = async () => {
await apiClient.messaging.deleteToken({
channel: notificationChannel,
})
}