@robotical/webapp-types 3.22.3 → 3.23.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.
- package/dist-types/package.json +1 -1
- package/dist-types/src/application/communicators/WrapperCommunicator.js +4 -0
- package/dist-types/src/types/communication-between-apps/wrapper-communication.d.ts +20 -1
- package/dist-types/src/types/communication-between-apps/wrapper-communication.js +6 -0
- package/dist-types/src/utils/phone-app-communication/app-updates.d.ts +10 -0
- package/dist-types/src/utils/phone-app-communication/app-updates.js +141 -0
- package/package.json +1 -1
package/dist-types/package.json
CHANGED
|
@@ -40,6 +40,7 @@ import randomHashGenerator from "../../utils/helpers/randomHashGenerator";
|
|
|
40
40
|
import isPhoneApp from "../../utils/phone-app-communication/is-phone-app";
|
|
41
41
|
import SelfdestructiveMessagePromise from "./SelfdestructiveMessagePromise";
|
|
42
42
|
import { RaftConnectionMethod } from "../../types/raft";
|
|
43
|
+
import { publishPhoneAppUpdateState } from "../../utils/phone-app-communication/app-updates";
|
|
43
44
|
var SHOW_LOGS = true;
|
|
44
45
|
var TAG = "WrapperAppCommunicator";
|
|
45
46
|
var WrapperCommunicator = /** @class */ (function () {
|
|
@@ -137,6 +138,9 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
|
|
|
137
138
|
case WrapperSentMessage.RAFT_PUBLISHED_EVENT:
|
|
138
139
|
window.applicationManager.receivedRICEvent(data.raftId, data.eventType, data.eventEnum, data.eventName, data.eventData);
|
|
139
140
|
break;
|
|
141
|
+
case WrapperSentMessage.UPDATE_STATE_CHANGED:
|
|
142
|
+
publishPhoneAppUpdateState(data);
|
|
143
|
+
break;
|
|
140
144
|
default:
|
|
141
145
|
console.log("Unhandled message");
|
|
142
146
|
}
|
|
@@ -39,12 +39,31 @@ export declare enum AppSentMessage {
|
|
|
39
39
|
MARTY_CALIBRATE_COLOUR_SENSOR = "MARTY_CALIBRATE_COLOUR_SENSOR",
|
|
40
40
|
MARTY_RESET_COLOUR_SENSOR_OFFSETS = "MARTY_RESET_COLOUR_SENSOR_OFFSETS",
|
|
41
41
|
GET_DEVICE_INFO = "GET_DEVICE_INFO",
|
|
42
|
+
UPDATE_UI_READY = "UPDATE_UI_READY",
|
|
43
|
+
UPDATE_GET_STATE = "UPDATE_GET_STATE",
|
|
44
|
+
UPDATE_APPLY_WEB = "UPDATE_APPLY_WEB",
|
|
45
|
+
UPDATE_OPEN_NATIVE_STORE = "UPDATE_OPEN_NATIVE_STORE",
|
|
42
46
|
SEND_ATOMIC_READ_OPERATION_TO_MARTY = "SEND_ATOMIC_READ_OPERATION_TO_MARTY"
|
|
43
47
|
}
|
|
44
48
|
export declare enum WrapperSentMessage {
|
|
45
49
|
RAFT_PUBLISHED_EVENT = "RAFT_PUBLISHED_EVENT",
|
|
46
|
-
RAFT_CONNECTED_RESULTS = "RAFT_CONNECTED_RESULTS"
|
|
50
|
+
RAFT_CONNECTED_RESULTS = "RAFT_CONNECTED_RESULTS",
|
|
51
|
+
UPDATE_STATE_CHANGED = "UPDATE_STATE_CHANGED"
|
|
47
52
|
}
|
|
53
|
+
export declare const UPDATE_UI_CAPABILITY: "updateUi:v1";
|
|
54
|
+
export type NativeAppUpdate = {
|
|
55
|
+
currentVersion: string;
|
|
56
|
+
latestVersion: string;
|
|
57
|
+
platform: "ios" | "android";
|
|
58
|
+
};
|
|
59
|
+
export type WebAppUpdate = {
|
|
60
|
+
webappVersion: string;
|
|
61
|
+
};
|
|
62
|
+
export type AppUpdateSnapshot = {
|
|
63
|
+
capability: typeof UPDATE_UI_CAPABILITY;
|
|
64
|
+
nativeUpdate: NativeAppUpdate | null;
|
|
65
|
+
webUpdate: WebAppUpdate | null;
|
|
66
|
+
};
|
|
48
67
|
export interface WRAPPER_RESPONSE_BASE {
|
|
49
68
|
success: boolean;
|
|
50
69
|
error?: string;
|
|
@@ -27,10 +27,16 @@ export var AppSentMessage;
|
|
|
27
27
|
AppSentMessage["MARTY_CALIBRATE_COLOUR_SENSOR"] = "MARTY_CALIBRATE_COLOUR_SENSOR";
|
|
28
28
|
AppSentMessage["MARTY_RESET_COLOUR_SENSOR_OFFSETS"] = "MARTY_RESET_COLOUR_SENSOR_OFFSETS";
|
|
29
29
|
AppSentMessage["GET_DEVICE_INFO"] = "GET_DEVICE_INFO";
|
|
30
|
+
AppSentMessage["UPDATE_UI_READY"] = "UPDATE_UI_READY";
|
|
31
|
+
AppSentMessage["UPDATE_GET_STATE"] = "UPDATE_GET_STATE";
|
|
32
|
+
AppSentMessage["UPDATE_APPLY_WEB"] = "UPDATE_APPLY_WEB";
|
|
33
|
+
AppSentMessage["UPDATE_OPEN_NATIVE_STORE"] = "UPDATE_OPEN_NATIVE_STORE";
|
|
30
34
|
AppSentMessage["SEND_ATOMIC_READ_OPERATION_TO_MARTY"] = "SEND_ATOMIC_READ_OPERATION_TO_MARTY";
|
|
31
35
|
})(AppSentMessage || (AppSentMessage = {}));
|
|
32
36
|
export var WrapperSentMessage;
|
|
33
37
|
(function (WrapperSentMessage) {
|
|
34
38
|
WrapperSentMessage["RAFT_PUBLISHED_EVENT"] = "RAFT_PUBLISHED_EVENT";
|
|
35
39
|
WrapperSentMessage["RAFT_CONNECTED_RESULTS"] = "RAFT_CONNECTED_RESULTS";
|
|
40
|
+
WrapperSentMessage["UPDATE_STATE_CHANGED"] = "UPDATE_STATE_CHANGED";
|
|
36
41
|
})(WrapperSentMessage || (WrapperSentMessage = {}));
|
|
42
|
+
export var UPDATE_UI_CAPABILITY = "updateUi:v1";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type AppUpdateSnapshot } from "../../types/communication-between-apps/wrapper-communication";
|
|
2
|
+
type UpdateListener = (snapshot: AppUpdateSnapshot) => void;
|
|
3
|
+
export declare const isAppUpdateSnapshot: (value: unknown) => value is AppUpdateSnapshot;
|
|
4
|
+
export declare const publishPhoneAppUpdateState: (value: unknown) => void;
|
|
5
|
+
export declare const subscribeToPhoneAppUpdates: (listener: UpdateListener) => () => void;
|
|
6
|
+
export declare const announcePhoneAppUpdateUiReady: () => Promise<AppUpdateSnapshot | null>;
|
|
7
|
+
export declare const getPhoneAppUpdateState: () => Promise<AppUpdateSnapshot | null>;
|
|
8
|
+
export declare const applyPhoneWebUpdate: () => Promise<"restarting" | "unavailable">;
|
|
9
|
+
export declare const openPhoneNativeStore: () => Promise<boolean>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { AppSentMessage, UPDATE_UI_CAPABILITY, } from "../../types/communication-between-apps/wrapper-communication";
|
|
38
|
+
import isPhoneApp from "./is-phone-app";
|
|
39
|
+
var listeners = new Set();
|
|
40
|
+
var isNativeUpdate = function (value) {
|
|
41
|
+
if (!value || typeof value !== "object") {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
var update = value;
|
|
45
|
+
return (typeof update.currentVersion === "string" &&
|
|
46
|
+
typeof update.latestVersion === "string" &&
|
|
47
|
+
(update.platform === "ios" || update.platform === "android"));
|
|
48
|
+
};
|
|
49
|
+
var isWebUpdate = function (value) {
|
|
50
|
+
if (!value || typeof value !== "object") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return typeof value.webappVersion === "string";
|
|
54
|
+
};
|
|
55
|
+
export var isAppUpdateSnapshot = function (value) {
|
|
56
|
+
if (!value || typeof value !== "object") {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
var candidate = value;
|
|
60
|
+
return (candidate.capability === UPDATE_UI_CAPABILITY &&
|
|
61
|
+
(candidate.nativeUpdate === null || isNativeUpdate(candidate.nativeUpdate)) &&
|
|
62
|
+
(candidate.webUpdate === null || isWebUpdate(candidate.webUpdate)));
|
|
63
|
+
};
|
|
64
|
+
export var publishPhoneAppUpdateState = function (value) {
|
|
65
|
+
if (!isAppUpdateSnapshot(value)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
listeners.forEach(function (listener) { return listener(value); });
|
|
69
|
+
};
|
|
70
|
+
export var subscribeToPhoneAppUpdates = function (listener) {
|
|
71
|
+
listeners.add(listener);
|
|
72
|
+
return function () {
|
|
73
|
+
listeners.delete(listener);
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var requestUpdateState = function (message) { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
var snapshot, _a;
|
|
78
|
+
return __generator(this, function (_b) {
|
|
79
|
+
switch (_b.label) {
|
|
80
|
+
case 0:
|
|
81
|
+
if (!isPhoneApp()) {
|
|
82
|
+
return [2 /*return*/, null];
|
|
83
|
+
}
|
|
84
|
+
_b.label = 1;
|
|
85
|
+
case 1:
|
|
86
|
+
_b.trys.push([1, 3, , 4]);
|
|
87
|
+
return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(message, {})];
|
|
88
|
+
case 2:
|
|
89
|
+
snapshot = _b.sent();
|
|
90
|
+
if (!isAppUpdateSnapshot(snapshot)) {
|
|
91
|
+
return [2 /*return*/, null];
|
|
92
|
+
}
|
|
93
|
+
publishPhoneAppUpdateState(snapshot);
|
|
94
|
+
return [2 /*return*/, snapshot];
|
|
95
|
+
case 3:
|
|
96
|
+
_a = _b.sent();
|
|
97
|
+
return [2 /*return*/, null];
|
|
98
|
+
case 4: return [2 /*return*/];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}); };
|
|
102
|
+
export var announcePhoneAppUpdateUiReady = function () {
|
|
103
|
+
return requestUpdateState(AppSentMessage.UPDATE_UI_READY);
|
|
104
|
+
};
|
|
105
|
+
export var getPhoneAppUpdateState = function () {
|
|
106
|
+
return requestUpdateState(AppSentMessage.UPDATE_GET_STATE);
|
|
107
|
+
};
|
|
108
|
+
export var applyPhoneWebUpdate = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
+
var response, _a;
|
|
110
|
+
return __generator(this, function (_b) {
|
|
111
|
+
switch (_b.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
_b.trys.push([0, 2, , 3]);
|
|
114
|
+
return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.UPDATE_APPLY_WEB, {})];
|
|
115
|
+
case 1:
|
|
116
|
+
response = _b.sent();
|
|
117
|
+
return [2 /*return*/, (response === null || response === void 0 ? void 0 : response.status) === "restarting" ? "restarting" : "unavailable"];
|
|
118
|
+
case 2:
|
|
119
|
+
_a = _b.sent();
|
|
120
|
+
return [2 /*return*/, "unavailable"];
|
|
121
|
+
case 3: return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}); };
|
|
125
|
+
export var openPhoneNativeStore = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
126
|
+
var response, _a;
|
|
127
|
+
return __generator(this, function (_b) {
|
|
128
|
+
switch (_b.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
_b.trys.push([0, 2, , 3]);
|
|
131
|
+
return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.UPDATE_OPEN_NATIVE_STORE, {})];
|
|
132
|
+
case 1:
|
|
133
|
+
response = _b.sent();
|
|
134
|
+
return [2 /*return*/, (response === null || response === void 0 ? void 0 : response.opened) === true];
|
|
135
|
+
case 2:
|
|
136
|
+
_a = _b.sent();
|
|
137
|
+
return [2 /*return*/, false];
|
|
138
|
+
case 3: return [2 /*return*/];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}); };
|