Skip to content

Commit

Permalink
Merge pull request #19 from Alok30/feature_wakelock
Browse files Browse the repository at this point in the history
Feature wakelock
  • Loading branch information
opensrc0 committed Apr 8, 2024
2 parents 453ceea + e0be559 commit 0adfd16
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
55 changes: 43 additions & 12 deletions __app/component/WakeLock/WakeLock.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
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',
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,
});
}
}

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 @@ -58,7 +58,8 @@
"share",
"livelocationtracking",
"detectmylocation",
"colorpicker"
"colorpicker",
"wakelock"
],
"config": {
"commitizen": {
Expand Down

0 comments on commit 0adfd16

Please sign in to comment.