Skip to content

Commit

Permalink
rewrite wip
Browse files Browse the repository at this point in the history
  • Loading branch information
drbeat committed Dec 10, 2023
1 parent d572b06 commit b09c444
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 1,049 deletions.
101 changes: 34 additions & 67 deletions frontend/src/actions/root.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,52 @@
import { hbchannelRequests, piccapRequests } from './webosRequests';

let checkRootStatusIntervalID = null;
const onHBExec = (result, logStore) => {
if (result.returnValue) {
logStore.setPiccapLog(`HBChannel exec returned. stdout: ${result.stdoutString} stderr: ${result.stderrString}`);
} else {
logStore.setPiccapLog(`HBChannel exec failed! Code: ${result.errorCode}`);
}

const killHyperion = () => {
hbchannelRequests('exec', {
command: 'kill -9 $(pidof hyperion-webos)',
});
};

const makeServiceRoot = (logStore) => {
logStore.setPiccapLog('Rooting..');
logStore.setInfoState('Rooting app and service..');
logStore.setPiccapLog('Calling HBChannel exec to elevate app and service');
/* eslint-disable no-undef */
webOS.service.request(
'luna://org.webosbrew.hbchannel.service',
const makeServiceRoot = () => {
hbchannelRequests(
'exec',
{
method: 'exec',
parameters: {
command: '/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service org.webosbrew.piccap; /media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service org.webosbrew.piccap.service',
},
onSuccess: (result) => {
onHBExec(result, logStore);

logStore.setPiccapLog('Elevation completed - killing service process..');
logStore.setInfoState('Killing service..');
killHyperion();
},
onFailure: (result) => onHBExec(result, logStore),
command: '/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service org.webosbrew.piccap; /media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service org.webosbrew.piccap.service',
},
() => {
killHyperion();
},
);
/* eslint-enable no-undef */

logStore.setInfoState('Finished making root processing');
};

const onCheckRootStatus = (result, logStore, rootStore) => {
if (result.returnValue === true) {
if (result.elevated) {
logStore.setPiccapLog('PicCap-Service returned rooted!');
document.getElementById('txtInfoState').innerHTML = 'Running as root';
rootStore.setRoot(true);
clearInterval(checkRootStatusIntervalID);
rootStore.setRootingInProgress(false);
} else {
if (!rootStore.rootingInProgress) {
logStore.setPiccapLog('Rooting not in progress yet.');
makeServiceRoot();
rootStore.setRootingInProgress(true);
}
logStore.setPiccapLog('PicCap-Service returned not rooted yet! Will check again soon.');
document.getElementById('txtInfoState').innerHTML = 'Not running as root. Service elevation in progress..';
}
} else {
logStore.setPiccapLog(`Getting root-status from PicCap-Service failed! Will try again. Code: ${result.errorCode}`);
document.getElementById('txtInfoState').innerHTML = 'PicCap-Service status failed!';
const onCheckRootStatus = (result, rootStore) => {
if (!result.returnValue) {
return;
}
};

const checkRoot = (logStore, rootStore) => {
logStore.setStatus('Processing root check');
logStore.setPiccapLog('Starting loop for PicCap-Service to get root-status');
if (result.elevated) {
rootStore.setRoot(true);
clearInterval(checkRootStatusIntervalID);
rootStore.setRootingInProgress(false);
} else if (!rootStore.rootingInProgress) {
makeServiceRoot();
rootStore.setRootingInProgress(true);
}
};

const checkRoot = (rootStore) => {
let firstInterval = true;
checkRootStatusIntervalID = window.setInterval(() => {
logStore.setPiccapLog('Calling PicCap-Service to get root-status');
document.getElementById('txtInfoState').innerHTML = 'Checking root status';
/* eslint-disable no-undef */
webOS.service.request(
'luna://org.webosbrew.piccap.service',
{
method: 'status',
parameters: {},
onSuccess: (result) => onCheckRootStatus(result, logStore, rootStore),
onFailure: (result) => onCheckRootStatus(result, logStore, rootStore),
},
piccapRequests(
'status',
{},
(result) => onCheckRootStatus(result, rootStore),
(result) => onCheckRootStatus(result, rootStore),
);
/* eslint-enable no-undef */

if (!rootStore.rootingInProgress && !rootStore.root && !firstInterval) {
logStore.setPiccapLog('Not rooted and rooting not in progress yet.');
makeServiceRoot(logStore);
makeServiceRoot();
rootStore.setRootingInProgress(true);
}
firstInterval = false;
Expand All @@ -88,5 +55,5 @@ const checkRoot = (logStore, rootStore) => {

export {
checkRoot,
onHBExec,
killHyperion,
};
22 changes: 4 additions & 18 deletions frontend/src/actions/service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getSettings } from './settings';
import { piccapRequests } from './webosRequests';

const onServiceCallback = (result, logStore) => {
if (result.returnValue) {
Expand All @@ -10,27 +11,12 @@ const onServiceCallback = (result, logStore) => {
}
};

const serviceStart = (logStore) => {
logStore.setPiccapLog('Start clicked');
const serviceStart = () => {
try {
logStore.setStatus('Starting service...');
logStore.setInfoState('Sending start command');
/* eslint-disable no-undef */
webOS.service.request(
'luna://org.webosbrew.piccap.service',
{
method: 'start',
parameters: {},
onSuccess: (result) => onServiceCallback(result, logStore),
onFailure: (result) => onServiceCallback(result, logStore),
},
);
/* eslint-enable no-undef */
piccapRequests('start', {});
} catch (err) {
logStore.setStatus(`Failed: ${JSON.stringify(err)}`);
console.log();
}

logStore.setInfoState('Start command send');
};

const serviceStop = (logStore) => {
Expand Down
Loading

0 comments on commit b09c444

Please sign in to comment.