Skip to content

Commit

Permalink
feat(component): wakelock component added'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alok committed Apr 8, 2024
1 parent f4349f3 commit 1e94802
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 17 deletions.
74 changes: 58 additions & 16 deletions __app/component/WakeLock/WakeLock.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,68 @@
import React from 'react';
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 || {};
const { children } = props;

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 }));
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported || 'WakeLock is not supporting in your device', failureCb });
}
}
const wakeLock = async () => {
if (WakeLock.isBrowserSupport()) {
let wakeLocker = null;
wakeLocker = await 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 true;
};

return (
React.Children.map(children || 'WakeLock', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child, {
onClick: wakeLock,
}))
);
}
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;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"autofillotp",
"share",
"livelocationtracking",
"detectmylocation"
"detectmylocation",
"wakelock"
],
"config": {
"commitizen": {
Expand Down

0 comments on commit 1e94802

Please sign in to comment.