@@ -37,17 +37,35 @@ function log(s) {
3737
3838( async ( ) => {
3939 try {
40- log ( 'Registering input app...' ) ;
40+ // register the app in the real /var/lib/eim
41+ log ( 'Registering ourselves as input app if not already done...' ) ;
4142 await lunaCall ( 'luna://com.webos.service.eim/addDevice' , {
4243 appId : 'org.webosbrew.autostart' ,
4344 pigImage : '' ,
4445 mvpdIcon : '' ,
46+ type : 'MVPD_IP' , // can be either MVPD_IP or MVPD_RF, required for webOS 3.x
47+ label : 'Autostart' , // required for webOS 3.x
48+ description : 'webosbrew autostart' , // required for webOS 3.x
4549 } ) ;
50+ } catch ( err ) {
51+ const errData = JSON . parse ( err . message ) ;
52+ if ( errData . errorCode === 'EIM.105' ) { // input app already registered
53+ log ( 'Already registered, good, carrying on...' ) ;
54+ }
55+ else {
56+ log ( `An error occured:\n${ err . stack } ` ) ;
57+ return ;
58+ }
59+ }
4660
61+ try {
4762 await retry ( 3 , async ( ) => {
63+ // now setup an eim overlay so that any changes done later don't erase our own app
64+ // if /var/lib/webosbrew/eim already exists, keep it that way, changes done in previous
65+ // sessions will live here, so just bind mount it, otherwise create it from the /var/lib/eim contents
4866 log ( 'Setting up eim overlay...' ) ;
4967 const res = await lunaCall ( 'luna://org.webosbrew.hbchannel.service/exec' , {
50- command : 'if [[ ! -d /var/lib/webosbrew/eim ]]; then cp -r /var/lib/eim /var/lib/webosbrew/eim; fi ; if ! findmnt /var/lib/eim; then mount --bind /var/lib/webosbrew/eim /var/lib/eim ; fi' ,
68+ command : 'if [[ ! -d /var/lib/webosbrew/eim ]]; then cp -r /var/lib/eim /var/lib/webosbrew/eim && echo cp ok || echo cp failed ; fi ; if ! findmnt /var/lib/eim; then mount --bind /var/lib/webosbrew/eim /var/lib/eim && echo mount overlay ok || echo mount overlay failed ; fi' ,
5169 } ) ;
5270 log ( `Result: ${ res . stdoutString } ${ res . stderrString } ` ) ;
5371 } ) ;
@@ -56,7 +74,9 @@ function log(s) {
5674 const res2 = await lunaCall ( 'luna://org.webosbrew.hbchannel.service/autostart' , { } ) ;
5775 log ( `Result: ${ res2 . message } ` ) ;
5876
59- log ( "Removing input app..." ) ;
77+ // this just removes ourselves from the overlay, but we still live in the real /var/lib/eim,
78+ // which guarantees that we'll survive on the next reboot
79+ log ( "Removing our own input app from eim overlay..." ) ;
6080 await lunaCall ( 'luna://com.webos.service.eim/deleteDevice' , {
6181 appId : 'org.webosbrew.autostart' ,
6282 } ) ;
@@ -70,7 +90,7 @@ function log(s) {
7090 if ( lastinputPayload . appId ) {
7191 log ( `Last input app: ${ lastinputPayload . appId } ` ) ;
7292 if ( lastinputPayload . appId !== 'org.webosbrew.autostart' ) {
73- log ( "Relaunching..." ) ;
93+ log ( "Relaunching this app ..." ) ;
7494 await lunaCall ( 'luna://com.webos.service.applicationManager/launch' , {
7595 id : lastinputPayload . appId ,
7696 } ) ;
@@ -79,6 +99,6 @@ function log(s) {
7999 }
80100 log ( "Done." ) ;
81101 } catch ( err ) {
82- log ( `An error occured: ${ err . stack } ` ) ;
102+ log ( `An error occured:\n ${ err . stack } ` ) ;
83103 }
84104} ) ( ) ;
0 commit comments