@robotical/webapp-types 1.0.1 → 1.0.5

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.
@@ -1,4 +1,4 @@
1
- import { RaftConnectionMethod } from "../../types/raft";
1
+ import { RaftConnectionMethod, RaftTypeE } from "../../types/raft";
2
2
  import WebAppCommunicator from "../../wrapper-app/communicators/WebAppCommunicator";
3
3
  import RAFT from "../RAFTs/RAFT";
4
4
  import Marty from "../RAFTs/Marty/Marty";
@@ -15,8 +15,11 @@ export default class ApplicationManager {
15
15
  connectedRafts: {
16
16
  [key: string]: RAFT;
17
17
  };
18
+ connectedRaftsContext: ConnectedRaftItem[];
18
19
  ricSelectedCb: ((raft: RAFT) => void) | null;
19
20
  toaster: typeof Toaster;
21
+ showBackHomeButton: () => void;
22
+ hideBackHomeButton: () => void;
20
23
  connectedRaftContextMethods: {
21
24
  addConnectedRaft: (connectedRaft: ConnectedRaftItem) => void;
22
25
  removeConnectedRaft: (connectedRaftId: string) => void;
@@ -90,4 +93,5 @@ export default class ApplicationManager {
90
93
  * List the files from the device's local storage
91
94
  */
92
95
  listFilesFromDeviceLocalStorage(dirname: string): Promise<unknown>;
96
+ getTheCurrentlySelectedDeviceOrFirstOfItsKind(deviceType: RaftTypeE): RAFT | undefined;
93
97
  }
@@ -58,6 +58,7 @@ var ApplicationManager = /** @class */ (function () {
58
58
  this._observers = {};
59
59
  // Connected RICs
60
60
  this.connectedRafts = {};
61
+ this.connectedRaftsContext = [];
61
62
  // Callback to call when a RAFT is selected (Phone App only)
62
63
  // We need that to make sure the connection button gets the selected RAFT once the user selects one
63
64
  this.ricSelectedCb = null;
@@ -74,6 +75,8 @@ var ApplicationManager = /** @class */ (function () {
74
75
  // public sessionDbs = new SessionsDBManager();
75
76
  // toaster
76
77
  this.toaster = Toaster;
78
+ this.showBackHomeButton = function () { };
79
+ this.hideBackHomeButton = function () { };
77
80
  // connected raft context methods
78
81
  this.connectedRaftContextMethods = {
79
82
  addConnectedRaft: function (connectedRaft) { },
@@ -458,6 +461,40 @@ var ApplicationManager = /** @class */ (function () {
458
461
  });
459
462
  });
460
463
  };
464
+ /*======== END OF NATIVE COMMANDS ONLY ========*/
465
+ //======================//
466
+ /* UI */
467
+ //======================//
468
+ //======================//
469
+ /* HELPERS */
470
+ //======================//
471
+ ApplicationManager.prototype.getTheCurrentlySelectedDeviceOrFirstOfItsKind = function (deviceType) {
472
+ var _a;
473
+ // checks if the currently selected device is a deviceType and returns it
474
+ // if not, returns the first deviceType in the list (if there is one)
475
+ var currentlySelectedId = (_a = this.connectedRaftsContext.find(function (connectedRaft) { return connectedRaft.isSelected; })) === null || _a === void 0 ? void 0 : _a.id;
476
+ if (currentlySelectedId) {
477
+ var selectedRaft = this.connectedRafts[currentlySelectedId];
478
+ if (!selectedRaft) {
479
+ return;
480
+ }
481
+ if (selectedRaft.type === deviceType) {
482
+ // the currently selected device is a cog, return it
483
+ return selectedRaft;
484
+ }
485
+ else {
486
+ // the currently selected device is not a cog, find the first cog in the list
487
+ var fistCog = void 0;
488
+ for (var raftId in this.connectedRafts) {
489
+ if (this.connectedRafts[raftId].type === deviceType) {
490
+ fistCog = this.connectedRafts[raftId];
491
+ break;
492
+ }
493
+ }
494
+ return fistCog;
495
+ }
496
+ }
497
+ };
461
498
  // Communicator to the wrapper app
462
499
  ApplicationManager.wrapperAppCommunicator = new WebAppCommunicator();
463
500
  return ApplicationManager;
@@ -90,7 +90,7 @@ var Cog = /** @class */ (function (_super) {
90
90
  */
91
91
  Cog.prototype.getBatteryStrength = function () {
92
92
  var _a;
93
- return ((_a = this.raftStateInfo) === null || _a === void 0 ? void 0 : _a.Power.battV) || 0;
93
+ return ((_a = this.raftStateInfo) === null || _a === void 0 ? void 0 : _a.Power.battV) ? Math.round(this.raftStateInfo.Power.battV * 100) : 0;
94
94
  };
95
95
  /**
96
96
  * This methods handles RAFT events coming from the RICConnector of the wrapper
@@ -131,7 +131,7 @@ var Cog = /** @class */ (function (_super) {
131
131
  return __awaiter(this, void 0, void 0, function () {
132
132
  return __generator(this, function (_a) {
133
133
  switch (_a.label) {
134
- case 0: return [4 /*yield*/, this.sendRestMessage('led//color/#ff8585')];
134
+ case 0: return [4 /*yield*/, this.sendRestMessage('led/ring/color/#ff8585')];
135
135
  case 1:
136
136
  _a.sent();
137
137
  return [4 /*yield*/, this.sendRestMessage('audio/rtttl/NoteASharp:d=4,o=6,b=600:a#')];
@@ -140,7 +140,7 @@ var Cog = /** @class */ (function (_super) {
140
140
  return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
141
141
  case 3:
142
142
  _a.sent();
143
- return [4 /*yield*/, this.sendRestMessage('led//color/#000000')];
143
+ return [4 /*yield*/, this.sendRestMessage('led/ring/color/#000000')];
144
144
  case 4:
145
145
  _a.sent();
146
146
  return [2 /*return*/];
@@ -49,6 +49,9 @@ export var ConnectedRaftContentProvider = function (_a) {
49
49
  };
50
50
  }
51
51
  }, []);
52
+ useEffect(function () {
53
+ window.applicationManager.connectedRaftsContext = connectedRafts;
54
+ }, [connectedRafts]);
52
55
  var addConnectedRaft = function (connectedRaft) {
53
56
  // if the new raft is already in the list, do not add it again, just select it
54
57
  var existingRaft = connectedRafts.find(function (connectedRaft_) { return connectedRaft_.id === connectedRaft.id; });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "1.0.1",
3
+ "version": "1.0.5",
4
4
  "description": "Type definitions for the Application Manager",
5
5
  "main": "dist/application-manager.d.ts",
6
6
  "types": "dist/application-manager.d.ts",