Skip to content

Commit

Permalink
Handling camera permission denial (#9)
Browse files Browse the repository at this point in the history
Showing error message and redirecting to manual input
  • Loading branch information
jlcvp authored Sep 10, 2024
1 parent ec253d5 commit ef140b7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
20 changes: 19 additions & 1 deletion src/app/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,25 @@ export class HomePage implements OnInit {
backdropDismiss: false
})
await loading.present()
await firstValueFrom(this.qrscanner.start())
try {
await firstValueFrom(this.qrscanner.start())
} catch (error) {
// camera permission denial
const header = await firstValueFrom(this.translateService.get('ADD_ACCOUNT_MODAL.ERROR_MSGS.ERROR_CAMERA_HEADER'))
const message = await firstValueFrom(this.translateService.get('ADD_ACCOUNT_MODAL.ERROR_MSGS.ERROR_CAMERA_MESSAGE'))
const alert = await this.alertController.create({
header,
message,
buttons: ['OK']
})
await loading.dismiss()
await alert.present()
this.manualInput = true
this.isScanActive = false
}



const devices = (await firstValueFrom(this.qrscanner.devices)).filter(device => device.kind === 'videoinput')
console.log({devices})
// find back camera
Expand Down
18 changes: 10 additions & 8 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"ADDING_ACCOUNT": "Adding account...",
"ERROR_MSGS": {
"ERROR_ADDING_ACCOUNT": "Error adding account",
"ERROR_CAMERA_HEADER": "Camera unavailable",
"ERROR_CAMERA_MESSAGE": "<p>Camera access is required to scan QR codes, but it seems your device either lacks a camera or camera permissions were denied. </p><p>Please check your device/permissions settings and try again.</p>",
"INVALID_QR_CODE": "Invalid QR Code",
"INVALID_SESSION": "Invalid session",
"UNKNOWN_ERROR": "Unknown error"
Expand All @@ -33,22 +35,23 @@
"COLOR_MODE_SYSTEM": "System",
"EXPORT_ACCOUNTS": "Export Backup",
"IMPORT_ACCOUNTS": "Import Backup",
"LOGOUT": "Sign out",
"LOGIN": "Sign in"
"LOGIN": "Sign in",
"LOGOUT": "Sign out"
},
"CRYPTO_API_NOT_SUPPORTED": "Crypto API not supported by the browser",
"HOME": {
"CANCEL": "Cancel",
"CONFIRM_LOGOUT_MESSAGE": "<p>All local or unsynchronized accounts will be deleted!</p><p><strong>This action cannot be undone.</strong></p>",
"CONFIRM_LOGOUT_TITLE": "Are you sure you want to sign out?",
"CONFIRM_LOGOUT_YES": "CLEAR LOCAL DATA AND SIGN OUT",
"EXPORTING_ACCOUNTS": "Exporting backup...",
"IMPORTING_ACCOUNTS": "Importing backup...",
"LOADING_ACCOUNTS": "Loading accounts...",
"LOGGING_OUT": "Signing out...",
"CONFIRM_LOGOUT_TITLE": "Are you sure you want to sign out?",
"CONFIRM_LOGOUT_MESSAGE": "<p>All local or unsynchronized accounts will be deleted!</p><p><strong>This action cannot be undone.</strong></p>",
"CONFIRM_LOGOUT_YES": "CLEAR LOCAL DATA AND SIGN OUT",
"CANCEL": "Cancel"
"LOGGING_OUT": "Signing out..."
},
"LOGIN": {
"AUTHENTICATING": "Authenticating...",
"CLOUD_SYNC": "Cloud sync",
"CONTINUE_OFFLINE": "Continue offline",
"EMAIL": "E-mail",
"ERROR_MSGS": {
Expand All @@ -58,7 +61,6 @@
"USER_NOT_FOUND": "User not found"
},
"PASSWORD": "Password",
"CLOUD_SYNC": "Cloud sync",
"SIGN_IN_BUTTON": "Sign in",
"VALIDATION_MSGS": {
"EMAIL_PATTERN": "Invalid e-mail",
Expand Down
18 changes: 10 additions & 8 deletions src/assets/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"ADDING_ACCOUNT": "Adicionando conta...",
"ERROR_MSGS": {
"ERROR_ADDING_ACCOUNT": "Erro ao adicionar conta",
"ERROR_CAMERA_HEADER": "Câmera não disponível",
"ERROR_CAMERA_MESSAGE": "<p>O acesso à câmera é necessário para escanear QR codes, mas parece que seu dispositivo não possui uma câmera ou as permissões da câmera foram negadas.</p><p>Verifique as permissões e/ou configurações do seu dispositivo e tente novamente.</p>",
"INVALID_QR_CODE": "QR Code inválido",
"INVALID_SESSION": "Sessão inválida",
"UNKNOWN_ERROR": "Erro desconhecido"
Expand All @@ -33,22 +35,23 @@
"COLOR_MODE_SYSTEM": "Sistema",
"EXPORT_ACCOUNTS": "Exportar Backup",
"IMPORT_ACCOUNTS": "Importar Backup",
"LOGOUT": "Sair",
"LOGIN": "Entrar"
"LOGIN": "Entrar",
"LOGOUT": "Sair"
},
"CRYPTO_API_NOT_SUPPORTED": "API de criptografia não suportada pelo navegador",
"HOME": {
"CANCEL": "Cancelar",
"CONFIRM_LOGOUT_MESSAGE": "<p>Todas as contas locais e não sincronizadas serão excluídas!</p><p><strong>Esta ação não pode ser desfeita.</strong></p>",
"CONFIRM_LOGOUT_TITLE": "Tem certeza de que deseja sair?",
"CONFIRM_LOGOUT_YES": "LIMPAR DADOS LOCAIS E SAIR",
"EXPORTING_ACCOUNTS": "Exportando backup...",
"IMPORTING_ACCOUNTS": "Importando backup...",
"LOADING_ACCOUNTS": "Carregando contas...",
"LOGGING_OUT": "Saindo...",
"CONFIRM_LOGOUT_TITLE": "Tem certeza de que deseja sair?",
"CONFIRM_LOGOUT_MESSAGE": "<p>Todas as contas locais e não sincronizadas serão excluídas!</p><p><strong>Esta ação não pode ser desfeita.</strong></p>",
"CONFIRM_LOGOUT_YES": "LIMPAR DADOS LOCAIS E SAIR",
"CANCEL": "Cancelar"
"LOGGING_OUT": "Saindo..."
},
"LOGIN": {
"AUTHENTICATING": "Autenticando...",
"CLOUD_SYNC": "Sincronização na nuvem",
"CONTINUE_OFFLINE": "Usar offline",
"EMAIL": "E-mail",
"ERROR_MSGS": {
Expand All @@ -58,7 +61,6 @@
"USER_NOT_FOUND": "Usuário não encontrado"
},
"PASSWORD": "Senha",
"CLOUD_SYNC": "Sincronização na nuvem",
"SIGN_IN_BUTTON": "Entrar",
"VALIDATION_MSGS": {
"EMAIL_PATTERN": "E-mail inválido",
Expand Down

0 comments on commit ef140b7

Please sign in to comment.