Skip to content

Commit 79addf7

Browse files
committed
Stable auto elevation routing (elevation, elevation .. the only word I know...)
1 parent 7338f4d commit 79addf7

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

frontend/views/MainPanel.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var serviceName = "org.webosbrew.hyperion.ng.loader.service";
1414
var servicePath = "/media/developer/apps/usr/palm/services/" + serviceName;
1515
var autostartFilepath = servicePath + "/autostart.sh";
1616
var linkPath = "/var/lib/webosbrew/init.d/90-start_hyperiond";
17-
var elevationCommand = "/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service " + serviceName;
17+
var elevationCommand = "/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service " + serviceName + " && killall -9 loader_service";
1818

1919
var not = function (x) { return !x };
2020
var yes_no_bool = function (x) {
@@ -89,6 +89,8 @@ module.exports = kind({
8989
hyperionVersionText: 'unknown',
9090
resultText: 'unknown',
9191

92+
initDone: false,
93+
9294
bindings: [
9395
{from: "autostartEnabled", to: '$.autostart.checked'},
9496
{from: "serviceElevated", to: '$.startButton.disabled', transform: not},
@@ -103,11 +105,21 @@ module.exports = kind({
103105
create: function () {
104106
this.inherited(arguments);
105107
console.info("Application created");
106-
// At first, elevate the native service
107-
// It does not do harm if service is elevated already
108-
this.elevate();
109-
this.set('resultText','Checking service status...');
110-
this.$.serviceStatus.send({});
108+
this.set('resultText', 'Waiting for startup...');
109+
// Spawn startup routine after 2 seconds, so UI has time to load
110+
var self = this;
111+
setTimeout(function() {
112+
self.doStartup();
113+
}, 3000);
114+
},
115+
// Spawned from this.create() with a little delay
116+
doStartup: function() {
117+
this.set('resultText', 'Startup routine started...');
118+
var self = this;
119+
// Start to continuosly poll service status
120+
setInterval(function () {
121+
self.$.serviceStatus.send({});
122+
}, 2000);
111123
},
112124
// Elevates the native service - this enables hyperion.ng.loader.service to run as root by default
113125
elevate: function () {
@@ -161,15 +173,24 @@ module.exports = kind({
161173
onServiceStatus: function (sender, evt) {
162174
console.info("onServiceStatus");
163175
console.info(sender, evt);
176+
177+
if (!evt.returnValue) {
178+
console.info('Service status call failed!');
179+
return;
180+
}
181+
164182
this.set('serviceElevated', evt.elevated);
165183
this.set('daemonRunning', evt.running);
166-
this.set('resultText', 'Service status received..');
167-
if (this.serviceElevated) {
184+
if (this.serviceElevated && !this.initDone) {
185+
this.set('resultText', 'Startup routine finished!');
186+
this.initDone = true;
168187
this.checkAutostart();
169188
this.fetchVersion();
170-
} else {
171-
this.set('resultText', 'Restarting native service to elevate...');
172-
this.terminate();
189+
} else if (!this.serviceElevated) {
190+
// Elevate the native service
191+
// Eventually the next service status callback will report elevation
192+
this.set('resultText', 'Trying to elevate...');
193+
this.elevate();
173194
}
174195
},
175196
onAutostartCheck: function (sender, evt) {

0 commit comments

Comments
 (0)