jpush.plugin.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { InjectionToken } from '@angular/core';
  2. import { Capacitor, PluginListenerHandle, registerPlugin } from '@capacitor/core';
  3. export interface JPushStatus {
  4. available: boolean;
  5. started: boolean;
  6. reason?: string;
  7. }
  8. export interface JPushNotice {
  9. kind: 'notification' | 'message';
  10. messageId: string;
  11. businessKey?: string;
  12. title?: string;
  13. body?: string;
  14. deepLink?: string;
  15. }
  16. export interface JPushPlugin {
  17. getStatus(): Promise<JPushStatus>;
  18. start(options: { privacyConsent: boolean }): Promise<JPushStatus>;
  19. stop(): Promise<void>;
  20. getRegistrationId(): Promise<{ registrationId: string | null }>;
  21. setAlias(options: { alias: string }): Promise<void>;
  22. deleteAlias(): Promise<void>;
  23. addListener(
  24. event: 'registration',
  25. listener: (data: { registrationId: string }) => void,
  26. ): Promise<PluginListenerHandle>;
  27. addListener(
  28. event: 'notificationReceived' | 'notificationOpened',
  29. listener: (data: JPushNotice) => void,
  30. ): Promise<PluginListenerHandle>;
  31. }
  32. export const JPUSH_OPTIONS = new InjectionToken<{ enabled: boolean }>('JPUSH_OPTIONS', {
  33. providedIn: 'root',
  34. factory: () => ({ enabled: false }),
  35. });
  36. export const JPUSH_PLUGIN = new InjectionToken<JPushPlugin>('JPUSH_PLUGIN', {
  37. providedIn: 'root',
  38. factory: () => registerPlugin<JPushPlugin>('FmodeJPush'),
  39. });
  40. export const JPUSH_SUPPORTED = new InjectionToken<() => boolean>('JPUSH_SUPPORTED', {
  41. providedIn: 'root',
  42. factory: () => () =>
  43. Capacitor.getPlatform() === 'android' && Capacitor.isPluginAvailable('FmodeJPush'),
  44. });