mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-21 01:53:57 +00:00
feat: getMe on launch
This commit is contained in:
@@ -7,6 +7,7 @@ import { WindowManager } from "../window-manager";
|
||||
import { HydraApi } from "../hydra-api";
|
||||
import { getUnlockedAchievements } from "@main/events/user/get-unlocked-achievements";
|
||||
import { Game } from "@main/entity";
|
||||
import { achievementsLogger } from "../logger";
|
||||
|
||||
const saveAchievementsOnLocal = async (
|
||||
objectId: string,
|
||||
@@ -117,6 +118,12 @@ export const mergeAchievements = async (
|
||||
const mergedLocalAchievements = unlockedAchievements.concat(newAchievements);
|
||||
|
||||
if (game.remoteId) {
|
||||
achievementsLogger.log(
|
||||
"Syncing achievements with cloud",
|
||||
game.title,
|
||||
game.objectID,
|
||||
game.remoteId
|
||||
);
|
||||
await HydraApi.put(
|
||||
"/profile/games/achievements",
|
||||
{
|
||||
@@ -133,7 +140,8 @@ export const mergeAchievements = async (
|
||||
publishNotification
|
||||
);
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((err) => {
|
||||
achievementsLogger.error(err);
|
||||
return saveAchievementsOnLocal(
|
||||
game.objectID,
|
||||
game.shop,
|
||||
|
||||
@@ -44,7 +44,8 @@ export class HydraApi {
|
||||
return userSubscriptionRepository
|
||||
.findOne({ where: { id: 1 } })
|
||||
.then((userSubscription) => {
|
||||
if (userSubscription?.status !== "active") return false;
|
||||
if (!userSubscription) return false;
|
||||
|
||||
return (
|
||||
!userSubscription.expiresAt ||
|
||||
userSubscription!.expiresAt > new Date()
|
||||
|
||||
43
src/main/services/user/get-user-data.ts
Normal file
43
src/main/services/user/get-user-data.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import type { UserDetails } from "@types";
|
||||
import { HydraApi } from "../hydra-api";
|
||||
import {
|
||||
userAuthRepository,
|
||||
userSubscriptionRepository,
|
||||
} from "@main/repository";
|
||||
import * as Sentry from "@sentry/electron/main";
|
||||
|
||||
export const getUserData = () => {
|
||||
return HydraApi.get<UserDetails>(`/profile/me`).then(async (me) => {
|
||||
userAuthRepository.upsert(
|
||||
{
|
||||
id: 1,
|
||||
displayName: me.displayName,
|
||||
profileImageUrl: me.profileImageUrl,
|
||||
backgroundImageUrl: me.backgroundImageUrl,
|
||||
userId: me.id,
|
||||
},
|
||||
["id"]
|
||||
);
|
||||
|
||||
if (me.subscription) {
|
||||
await userSubscriptionRepository.upsert(
|
||||
{
|
||||
id: 1,
|
||||
subscriptionId: me.subscription?.id || "",
|
||||
status: me.subscription?.status || "",
|
||||
planId: me.subscription?.plan.id || "",
|
||||
planName: me.subscription?.plan.name || "",
|
||||
expiresAt: me.subscription?.expiresAt || null,
|
||||
user: { id: 1 },
|
||||
},
|
||||
["id"]
|
||||
);
|
||||
} else {
|
||||
await userSubscriptionRepository.delete({ id: 1 });
|
||||
}
|
||||
|
||||
Sentry.setUser({ id: me.id, username: me.username });
|
||||
|
||||
return me;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user