feat(infra): framework

This commit is contained in:
EYHN
2024-04-17 14:12:29 +08:00
parent ab17a05df3
commit 06fda3b62c
467 changed files with 9996 additions and 8697 deletions

View File

@@ -0,0 +1,8 @@
import type { Framework } from '@toeverything/infra';
import { AuthService } from '../cloud';
import { TelemetryService } from './services/telemetry';
export function configureTelemetryModule(framework: Framework) {
framework.service(TelemetryService, [AuthService]);
}

View File

@@ -0,0 +1,32 @@
import { mixpanel } from '@affine/core/utils';
import { ApplicationStarted, OnEvent, Service } from '@toeverything/infra';
import {
AccountChanged,
type AuthAccountInfo,
type AuthService,
} from '../../cloud';
@OnEvent(ApplicationStarted, e => e.onApplicationStart)
@OnEvent(AccountChanged, e => e.onAccountChanged)
export class TelemetryService extends Service {
constructor(private readonly auth: AuthService) {
super();
}
onApplicationStart() {
const account = this.auth.session.account$.value;
if (account) {
mixpanel.identify(account.id);
}
}
onAccountChanged(account: AuthAccountInfo | null) {
if (account === null) {
mixpanel.reset();
} else {
mixpanel.reset();
mixpanel.identify(account.id);
}
}
}