Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed issue where Moments would capture even after disabling #2122

Merged
merged 2 commits into from Dec 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 21 additions & 8 deletions packages/web/src/javascripts/Controllers/Moments/MomentsService.ts
Expand Up @@ -68,6 +68,10 @@ export class MomentsService extends AbstractViewController {
}

private beginTakingPhotos() {
if (this.intervalReference) {
clearInterval(this.intervalReference)
}

void this.takePhoto()

this.intervalReference = setInterval(
Expand All @@ -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.',
Expand Down Expand Up @@ -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)
}
Expand Down