18 lines
1.4 KiB
JavaScript
18 lines
1.4 KiB
JavaScript
'use strict';
|
|
require('/opt/usr/share/q70t-remap/compat.js');
|
|
|
|
var fs=require("fs"), Bridge=require("/opt/usr/share/q70t-remap/physical-input.js").Bridge;
|
|
var serial=0;
|
|
function execute(command, timeout) {return new Promise(function(resolve,reject){var n=++serial, base="/tmp/q70t-remap-work/"+n; fs.writeFileSync(base+".tmp",command);fs.renameSync(base+".tmp",base+".cmd");var start=Date.now(),timer=setInterval(function(){if(fs.existsSync(base+".done")){clearInterval(timer);resolve({exit_code:+fs.readFileSync(base+".done","utf8"),stdout:fs.readFileSync(base+".out","utf8"),stderr:fs.readFileSync(base+".err","utf8")});}else if(Date.now()-start>(timeout||15000)){clearInterval(timer);reject(new Error("command timed out"));}},100);});}
|
|
var last=0;
|
|
var bridge=new Bridge(execute,function(event){
|
|
console.log(JSON.stringify(event));
|
|
if(event.value!==1 || Date.now()-last<800)return;
|
|
var app=event.code===226?'AprZAARz4r.Jellyfin':event.code===500?'kIciSQlYEM.plex':null;
|
|
if(!app)return;
|
|
last=Date.now();
|
|
execute('app_launcher -s '+app,10000).then(function(r){console.log('launch '+app+' '+JSON.stringify(r));});
|
|
},{helperRuntime:'tizen55',helperPath:'/opt/usr/apps/FreeMyTVio/res/q70t/SamsungTvRemoteInputAgent.dll'});
|
|
bridge.start('/dev/input/event5','filter',['226','500']).then(function(s){console.log('READY '+JSON.stringify(s));},function(e){console.error(e.stack);process.exit(1);});
|
|
process.on('SIGTERM',function(){bridge.stop();process.exit(0);});
|