stremiok 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ module.exports.onExit = function () {};
24
24
  function run() {
25
25
  if (_ran) { return; }
26
26
  _ran = true;
27
- var json = null, fs = null;
27
+ var json = null, fs = null, fromApp = false;
28
28
  try { fs = require('fs'); } catch (e) {}
29
29
  try {
30
30
  var req = tizen.application.getCurrentApplication().getRequestedAppControl();
@@ -33,12 +33,22 @@ function run() {
33
33
  if (d.key === 'caller') { caller = d.value && d.value[0]; }
34
34
  if (d.key === 'tiles') { tiles = d.value && d.value[0]; }
35
35
  });
36
- if (caller === 'ForegroundApp' && typeof tiles === 'string' && tiles.length <= TILES_MAX) { json = tiles; }
36
+ if (caller === 'ForegroundApp' && typeof tiles === 'string' && tiles.length <= TILES_MAX) { json = tiles; fromApp = true; }
37
37
  } catch (e1) {}
38
38
  if (json) { try { fs.writeFileSync(dataDir() + '/' + TILES_FILE, json); } catch (e2) {} }
39
39
  else { try { json = String(fs.readFileSync(dataDir() + '/' + TILES_FILE, 'utf8')); } catch (e3) { json = null; } } // (the TV asking: the last ones sent)
40
40
  var ok = false;
41
41
  try { var o = JSON.parse(json); ok = !!o && Array.isArray(o.sections) && json.length <= TILES_MAX; } catch (e4) {}
42
- if (!ok || typeof webapis === 'undefined' || !webapis || !webapis.preview || typeof webapis.preview.setPreviewData !== 'function') { done(); return; }
43
- try { webapis.preview.setPreviewData(json, done, done); } catch (e5) { done(); }
42
+ // StremioK (not the TV) asked: told whether the TV took them (it counts them as sent only then)
43
+ function answer(took) {
44
+ if (fromApp) {
45
+ try {
46
+ var rq = tizen.application.getCurrentApplication().getRequestedAppControl();
47
+ if (took) { rq.replyResult([new tizen.ApplicationControlData('result', ['ok'])]); } else { rq.replyFailure(); }
48
+ } catch (e6) {}
49
+ }
50
+ done();
51
+ }
52
+ if (!ok || typeof webapis === 'undefined' || !webapis || !webapis.preview || typeof webapis.preview.setPreviewData !== 'function') { answer(false); return; }
53
+ try { webapis.preview.setPreviewData(json, function () { answer(true); }, function () { answer(false); }); } catch (e5) { answer(false); }
44
54
  }