diff --git a/packages/web/src/javascripts/Controllers/Moments/MomentsService.ts b/packages/web/src/javascripts/Controllers/Moments/MomentsService.ts index 5ccc80171..5c4aef7a5 100644 --- a/packages/web/src/javascripts/Controllers/Moments/MomentsService.ts +++ b/packages/web/src/javascripts/Controllers/Moments/MomentsService.ts @@ -68,6 +68,10 @@ export class MomentsService extends AbstractViewController { } private beginTakingPhotos() { + if (this.intervalReference) { + clearInterval(this.intervalReference) + } + void this.takePhoto() this.intervalReference = setInterval( @@ -93,16 +97,24 @@ export class MomentsService extends AbstractViewController { return } - const toastId = addToast({ - type: ToastType.Regular, - message: 'Capturing Moment...', - pauseOnWindowBlur: false, - }) + const isAppInForeground = document.visibilityState === 'visible' + + let toastId: string | undefined + + if (isAppInForeground) { + toastId = addToast({ + type: ToastType.Regular, + message: 'Capturing Moment...', + pauseOnWindowBlur: false, + }) + } if (this.application.desktopDevice) { const granted = await this.application.desktopDevice.askForMediaAccess('camera') if (!granted) { - dismissToast(toastId) + if (toastId) { + dismissToast(toastId) + } addToast({ type: ToastType.Error, message: 'Please enable Camera permissions for Standard Notes to enable Moments.', @@ -130,12 +142,13 @@ export class MomentsService extends AbstractViewController { } } - dismissToast(toastId) + if (toastId) { + dismissToast(toastId) + } const uploadedFile = await this.filesController.uploadNewFile(file) if (uploadedFile) { - const isAppInForeground = document.visibilityState === 'visible' if (isAppInForeground) { void this.application.linkingController.linkItemToSelectedItem(uploadedFile) }