in-app-purchase.ts 992 B

12345678910111213141516171819202122232425
  1. import { EventEmitter } from 'events';
  2. let _inAppPurchase;
  3. if (process.platform === 'darwin') {
  4. const { inAppPurchase } = process._linkedBinding('electron_browser_in_app_purchase');
  5. const _purchase = inAppPurchase.purchaseProduct as (productID: string, quantity?: number, username?: string) => Promise<boolean>;
  6. inAppPurchase.purchaseProduct = (productID: string, opts?: number | { quantity?: number, username?: string }) => {
  7. const quantity = typeof opts === 'object' ? opts.quantity : opts;
  8. const username = typeof opts === 'object' ? opts.username : undefined;
  9. return _purchase.apply(inAppPurchase, [productID, quantity, username]);
  10. };
  11. _inAppPurchase = inAppPurchase;
  12. } else {
  13. _inAppPurchase = new EventEmitter();
  14. Object.assign(_inAppPurchase, {
  15. purchaseProduct: () => {
  16. throw new Error('The inAppPurchase module can only be used on macOS');
  17. },
  18. canMakePayments: () => false,
  19. getReceiptURL: () => ''
  20. });
  21. }
  22. export default _inAppPurchase;