image-helpers.ts 799 B

1234567891011121314151617181920212223
  1. import { BaseWindow, NativeImage } from 'electron';
  2. import { once } from 'node:events';
  3. /**
  4. * Opens a window to display a native image. Useful for quickly debugging tests
  5. * rather than writing a file and opening manually.
  6. *
  7. * Set the `DEBUG_PREVIEW_IMAGE` environment variable to show previews.
  8. */
  9. export async function debugPreviewImage (image: NativeImage) {
  10. if (!process.env.DEBUG_PREVIEW_IMAGE) return;
  11. const previewWindow = new BaseWindow({
  12. title: 'NativeImage preview',
  13. backgroundColor: '#444444'
  14. });
  15. const ImageView = (require('electron') as any).ImageView;
  16. const imgView = new ImageView();
  17. imgView.setImage(image);
  18. previewWindow.contentView.addChildView(imgView);
  19. imgView.setBounds({ x: 0, y: 0, ...image.getSize() });
  20. await once(previewWindow, 'close');
  21. };