From fa9061a430417b3e0bfc72ae22edc75eddbcb36f Mon Sep 17 00:00:00 2001 From: Alok Date: Mon, 8 Apr 2024 10:53:09 +0530 Subject: [PATCH 1/3] feat(component): a new component weblock added --- __app/component/WakeLock/WakeLock.js | 57 ++++++++++++++++++++++------ package.json | 3 +- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/__app/component/WakeLock/WakeLock.js b/__app/component/WakeLock/WakeLock.js index 48a05a8..216cb6a 100644 --- a/__app/component/WakeLock/WakeLock.js +++ b/__app/component/WakeLock/WakeLock.js @@ -1,26 +1,59 @@ +import PropTypes from 'prop-types'; import { handleError, handleSuccess } from '../services/handlerService'; function WakeLock(props = {}) { - const successCb = props.successCb || (() => {}); - const failureCb = props.failureCb || (() => {}); + const successCb = props.successCb || (() => { }); + const failureCb = props.failureCb || (() => { }); const successMsg = props.successMsg || ''; const failureMsg = props.failureMsg || {}; if (WakeLock.isBrowserSupport()) { - // const abort = new AbortController(); - // abortAutoFill(abort, 3); - // navigator.credentials.get({ - // otp: { transport: ['sms'] }, - // signal: abort.signal, - // }).then((otp) => { - // const { code } = otp; - // handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: code }); - // }).catch((error) => handleError({ msgType: 'ERROR', msg: error, failureCb })); + let wakeLocker = null; + wakeLocker = navigator.wakeLock.request('screen'); + try { + if (wakeLocker) { + handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb }); + } else { + return handleError({ + msgType: 'CANCELLED', + msg: failureMsg.cancelled, + failureCb, + }); + } + } catch (error) { + return handleError({ + msgType: 'ERROR', + msg: failureMsg.error || JSON.stringify(error), + failureCb, + }); + } } else { - return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported || 'WakeLock is not supporting in your device', failureCb }); + return handleError({ + msgType: 'UN_SUPPORTED_FEATURE', + msg: + failureMsg.unSupported || 'WakeLock is not supporting in your device', + failureCb, + }); } + return true; } WakeLock.isBrowserSupport = () => 'wakeLock' in navigator; +WakeLock.propTypes = { + successCb: PropTypes.func, + failureCb: PropTypes.func, + successMsg: PropTypes.string, + failureMsg: PropTypes.object, +}; + +WakeLock.defaultProps = { + successCb: () => { }, + failureCb: () => { }, + successMsg: 'WakeLock successfully!!', + failureMsg: { + unSupported: 'Your browser does not support the WakeLock fetaure', + error: 'Unable to apply WakeLock', + }, +}; export default WakeLock; diff --git a/package.json b/package.json index a96e578..f2fb93c 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,8 @@ "share", "livelocationtracking", "detectmylocation", - "colorpicker" + "colorpicker", + "wakelock" ], "config": { "commitizen": { From bc4ed15d4d77198e5e099b58e1a7efacf06c92b7 Mon Sep 17 00:00:00 2001 From: Alok Date: Mon, 8 Apr 2024 11:16:37 +0530 Subject: [PATCH 2/3] perf: removed --- __app/component/WakeLock/WakeLock.js | 1 - 1 file changed, 1 deletion(-) diff --git a/__app/component/WakeLock/WakeLock.js b/__app/component/WakeLock/WakeLock.js index 216cb6a..d9cc6f6 100644 --- a/__app/component/WakeLock/WakeLock.js +++ b/__app/component/WakeLock/WakeLock.js @@ -35,7 +35,6 @@ function WakeLock(props = {}) { failureCb, }); } - return true; } WakeLock.isBrowserSupport = () => 'wakeLock' in navigator; From e0be5597c511e353addea5fb12753158518215b7 Mon Sep 17 00:00:00 2001 From: Alok Date: Mon, 8 Apr 2024 11:24:26 +0530 Subject: [PATCH 3/3] refactor(com): code change --- __app/component/WakeLock/WakeLock.js | 1 - 1 file changed, 1 deletion(-) diff --git a/__app/component/WakeLock/WakeLock.js b/__app/component/WakeLock/WakeLock.js index d9cc6f6..6d81707 100644 --- a/__app/component/WakeLock/WakeLock.js +++ b/__app/component/WakeLock/WakeLock.js @@ -16,7 +16,6 @@ function WakeLock(props = {}) { } else { return handleError({ msgType: 'CANCELLED', - msg: failureMsg.cancelled, failureCb, }); }