-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OK-23599: add request camera permission
- Loading branch information
Showing
6 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useIntl } from 'react-intl'; | ||
|
||
import { Dialog, Icon } from '@onekeyhq/components'; | ||
|
||
import backgroundApiProxy from '../../background/instance/backgroundApiProxy'; | ||
import { ModalRoutes, RootRoutes } from '../../routes/routesEnum'; | ||
|
||
import { ScanQrcodeRoutes } from './types'; | ||
|
||
export const PermitDeniedDialog = () => { | ||
const intl = useIntl(); | ||
return ( | ||
<Dialog | ||
visible | ||
contentProps={{ | ||
icon: <Icon name="ExclamationTriangleOutline" size={48} />, | ||
title: intl.formatMessage({ id: 'title__camera_permission_required' }), | ||
content: intl.formatMessage({ | ||
id: 'msg__approving_camera_permission_needs_to_be_turned_on_in_expand_view', | ||
}), | ||
}} | ||
footerButtonProps={{ | ||
primaryActionProps: { | ||
children: intl.formatMessage({ id: 'action__open_expand_view' }), | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-shadow | ||
onPrimaryActionPress: ({ onClose }) => { | ||
backgroundApiProxy.serviceApp.openExtensionExpandTab({ | ||
routes: [RootRoutes.Modal, ModalRoutes.ScanQrcode], | ||
params: { | ||
screen: ScanQrcodeRoutes.RequestPermission, | ||
}, | ||
}); | ||
onClose?.(); | ||
}, | ||
}} | ||
/> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/kit/src/views/ScanQrcode/RequestCameraPermissionExt.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
|
||
import { useIntl } from 'react-intl'; | ||
|
||
import { Modal, Typography } from '@onekeyhq/components'; | ||
import debugLogger from '@onekeyhq/shared/src/logger/debugLogger'; | ||
import platformEnv from '@onekeyhq/shared/src/platformEnv'; | ||
|
||
const RequestCameraPermissionExt = () => { | ||
const intl = useIntl(); | ||
useEffect(() => { | ||
async function main() { | ||
if (platformEnv.isExtension) { | ||
try { | ||
await navigator.mediaDevices.getUserMedia({ video: true }); | ||
} catch { | ||
debugLogger.common.info('failed to request camera permission on ext'); | ||
} | ||
} | ||
} | ||
main(); | ||
}, []); | ||
const onPrimaryActionPress = useCallback( | ||
({ close }: { close: () => void }) => { | ||
close?.(); | ||
}, | ||
[], | ||
); | ||
return ( | ||
<Modal | ||
header={intl.formatMessage({ id: 'title__camera_permission_required' })} | ||
onPrimaryActionPress={onPrimaryActionPress} | ||
> | ||
<Typography.Body1Strong> | ||
{intl.formatMessage({ | ||
id: 'msg__please_approve_camera_permission_on_your_browser', | ||
})} | ||
</Typography.Body1Strong> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default RequestCameraPermissionExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters