import { InjectionToken } from '@angular/core'; import { Capacitor, PluginListenerHandle, registerPlugin } from '@capacitor/core'; export interface JPushStatus { available: boolean; started: boolean; reason?: string; } export interface JPushNotice { kind: 'notification' | 'message'; messageId: string; businessKey?: string; title?: string; body?: string; deepLink?: string; } export interface JPushPlugin { getStatus(): Promise; start(options: { privacyConsent: boolean }): Promise; stop(): Promise; getRegistrationId(): Promise<{ registrationId: string | null }>; setAlias(options: { alias: string }): Promise; deleteAlias(): Promise; addListener( event: 'registration', listener: (data: { registrationId: string }) => void, ): Promise; addListener( event: 'notificationReceived' | 'notificationOpened', listener: (data: JPushNotice) => void, ): Promise; } export const JPUSH_OPTIONS = new InjectionToken<{ enabled: boolean }>('JPUSH_OPTIONS', { providedIn: 'root', factory: () => ({ enabled: false }), }); export const JPUSH_PLUGIN = new InjectionToken('JPUSH_PLUGIN', { providedIn: 'root', factory: () => registerPlugin('FmodeJPush'), }); export const JPUSH_SUPPORTED = new InjectionToken<() => boolean>('JPUSH_SUPPORTED', { providedIn: 'root', factory: () => () => Capacitor.getPlatform() === 'android' && Capacitor.isPluginAvailable('FmodeJPush'), });