html2apk 0.2.0 → 0.4.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/README.md +323 -12
- package/examples/minimal/app.json +2 -0
- package/examples/minimal/dist/MeuApp-1.0.0-debug.apk +0 -0
- package/package.json +3 -2
- package/src/cli/index.js +10 -1
- package/src/cordova/config-xml.js +59 -1
- package/src/cordova/project.js +19 -1
- package/src/core/build-apk.js +399 -23
- package/src/core/config.js +47 -1
- package/src/core/defaults.js +6 -0
- package/src/desktop/main.js +152 -2
- package/src/desktop/preload.js +14 -0
- package/src/desktop/renderer/index.html +20 -2
- package/src/desktop/renderer/renderer.js +1254 -41
- package/src/desktop/renderer/styles.css +98 -2
- package/src/templates/cordova-plugin-html2apk-bridge/plugin.xml +4 -0
- package/src/templates/cordova-plugin-html2apk-bridge/src/android/Html2ApkBridge.java +1770 -38
- package/src/templates/cordova-plugin-html2apk-bridge/src/android/NotificationReceiver.java +19 -5
- package/src/templates/cordova-plugin-html2apk-bridge/src/android/NotificationStore.java +13 -1
- package/src/templates/cordova-plugin-html2apk-bridge/www/html2apk-bridge.js +516 -3
- package/src/templates/html2apk-auto-theme.js +144 -0
- package/src/templates/html2apk-onesignal.js +155 -0
- package/src/utils/command-runner.js +3 -0
|
@@ -21,21 +21,33 @@ public class NotificationReceiver extends BroadcastReceiver {
|
|
|
21
21
|
|
|
22
22
|
@Override
|
|
23
23
|
public void onReceive(Context context, Intent intent) {
|
|
24
|
+
JSONObject options = parseOptions(intent);
|
|
25
|
+
int id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, Html2ApkBridge.notificationId(options));
|
|
26
|
+
|
|
24
27
|
if (Build.VERSION.SDK_INT >= 33 && context.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
|
28
|
+
if (Html2ApkBridge.repeatInterval(options) > 0) {
|
|
29
|
+
Html2ApkBridge.rescheduleRepeatingNotification(context, id, options, Html2ApkBridge.canScheduleExactAlarms(context));
|
|
30
|
+
} else {
|
|
31
|
+
NotificationStore.remove(context, id);
|
|
32
|
+
}
|
|
25
33
|
return;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
JSONObject
|
|
29
|
-
|
|
36
|
+
JSONObject displayOptions;
|
|
37
|
+
try {
|
|
38
|
+
displayOptions = Html2ApkBridge.notificationDisplayOptions(options);
|
|
39
|
+
} catch (Exception error) {
|
|
40
|
+
displayOptions = options;
|
|
41
|
+
}
|
|
30
42
|
NotificationStore.remove(context, id);
|
|
31
43
|
|
|
32
44
|
Html2ApkBridge.ensureNotificationChannel(context);
|
|
33
45
|
|
|
34
|
-
String title = Html2ApkBridge.title(
|
|
35
|
-
String text = Html2ApkBridge.text(
|
|
46
|
+
String title = Html2ApkBridge.title(displayOptions);
|
|
47
|
+
String text = Html2ApkBridge.text(displayOptions);
|
|
36
48
|
JSONObject detail;
|
|
37
49
|
try {
|
|
38
|
-
detail = Html2ApkBridge.detailPayload(
|
|
50
|
+
detail = Html2ApkBridge.detailPayload(displayOptions);
|
|
39
51
|
} catch (Exception error) {
|
|
40
52
|
detail = new JSONObject();
|
|
41
53
|
}
|
|
@@ -49,7 +61,9 @@ public class NotificationReceiver extends BroadcastReceiver {
|
|
|
49
61
|
.setContentIntent(Html2ApkBridge.createContentIntent(context, id, detail))
|
|
50
62
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
|
51
63
|
|
|
64
|
+
Html2ApkBridge.addNotificationActions(builder, context, id, displayOptions);
|
|
52
65
|
NotificationManagerCompat.from(context).notify(id, builder.build());
|
|
66
|
+
Html2ApkBridge.rescheduleRepeatingNotification(context, id, options, Html2ApkBridge.canScheduleExactAlarms(context));
|
|
53
67
|
}
|
|
54
68
|
|
|
55
69
|
static void schedule(Context context, int id, long when, JSONObject options, boolean exactAllowed) {
|
|
@@ -63,7 +63,19 @@ public final class NotificationStore {
|
|
|
63
63
|
int id = item.optInt("id");
|
|
64
64
|
long when = item.optLong("when");
|
|
65
65
|
JSONObject options = item.optJSONObject("options");
|
|
66
|
-
if (options == null
|
|
66
|
+
if (options == null) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (when <= now && Html2ApkBridge.repeatInterval(options) > 0) {
|
|
71
|
+
when = Html2ApkBridge.nextRepeatTime(options, now);
|
|
72
|
+
options = Html2ApkBridge.nextRepeatOptions(options, when);
|
|
73
|
+
options.put("id", id);
|
|
74
|
+
item.put("when", when);
|
|
75
|
+
item.put("options", options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (when <= now) {
|
|
67
79
|
continue;
|
|
68
80
|
}
|
|
69
81
|
|
|
@@ -3,11 +3,55 @@
|
|
|
3
3
|
var exec = require("cordova/exec");
|
|
4
4
|
|
|
5
5
|
var notificationListeners = [];
|
|
6
|
+
var eventListeners = {};
|
|
6
7
|
var initialNotification = null;
|
|
8
|
+
var initialLink = null;
|
|
9
|
+
var scheduledNotificationCounter = 0;
|
|
10
|
+
var deviceReady = typeof document === "undefined";
|
|
11
|
+
var deviceReadyCallbacks = [];
|
|
12
|
+
var eventAliases = {
|
|
13
|
+
"app:ready": "app:pronto",
|
|
14
|
+
"app:paused": "app:pausado",
|
|
15
|
+
"app:closed": "app:fechado",
|
|
16
|
+
"app:resumed": "app:voltou",
|
|
17
|
+
"back:button": "botao:voltar",
|
|
18
|
+
"link:opened": "link:aberto",
|
|
19
|
+
"network:changed": "rede:mudou",
|
|
20
|
+
"battery:changed": "bateria:mudou",
|
|
21
|
+
"notification:received": "notificacao:recebida",
|
|
22
|
+
"notification:clicked": "notificacao:clicada"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function markDeviceReady() {
|
|
26
|
+
if (deviceReady) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
deviceReady = true;
|
|
31
|
+
deviceReadyCallbacks.splice(0).forEach(function (callback) {
|
|
32
|
+
callback();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function whenDeviceReady() {
|
|
37
|
+
if (deviceReady) {
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new Promise(function (resolve) {
|
|
42
|
+
deviceReadyCallbacks.push(resolve);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof document !== "undefined") {
|
|
47
|
+
document.addEventListener("deviceready", markDeviceReady, false);
|
|
48
|
+
}
|
|
7
49
|
|
|
8
50
|
function call(action, args) {
|
|
9
|
-
return
|
|
10
|
-
|
|
51
|
+
return whenDeviceReady().then(function () {
|
|
52
|
+
return new Promise(function (resolve, reject) {
|
|
53
|
+
exec(resolve, reject, "Html2ApkBridge", action, args || []);
|
|
54
|
+
});
|
|
11
55
|
});
|
|
12
56
|
}
|
|
13
57
|
|
|
@@ -31,6 +75,113 @@ function normalizeNotificationOptions(messageOrOptions) {
|
|
|
31
75
|
return options;
|
|
32
76
|
}
|
|
33
77
|
|
|
78
|
+
function normalizeScheduledNotificationOptions(options) {
|
|
79
|
+
var normalized = normalizeNotificationOptions(options || {});
|
|
80
|
+
if (!normalized.id) {
|
|
81
|
+
scheduledNotificationCounter = (scheduledNotificationCounter + 1) % 100000;
|
|
82
|
+
normalized.id = Math.floor(Date.now() % 0x0fffffff) + scheduledNotificationCounter;
|
|
83
|
+
}
|
|
84
|
+
return normalized;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function parseIntervalMs(value) {
|
|
88
|
+
var text;
|
|
89
|
+
var match;
|
|
90
|
+
var amount;
|
|
91
|
+
var unit;
|
|
92
|
+
|
|
93
|
+
if (typeof value === "number" && isFinite(value)) {
|
|
94
|
+
return Math.max(0, Math.round(value));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (value && typeof value === "object") {
|
|
98
|
+
return parseIntervalMs(value.intervalo || value.interval || value.aCada || value.every || value.ms);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
text = String(value || "").trim().toLowerCase();
|
|
102
|
+
match = text.match(/^(\d+(?:\.\d+)?)\s*(ms|s|seg|m|min|h|hr|d|dia|dias)?$/);
|
|
103
|
+
if (!match) {
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
amount = Number(match[1]);
|
|
108
|
+
unit = match[2] || "ms";
|
|
109
|
+
if (unit === "s" || unit === "seg") {
|
|
110
|
+
return Math.round(amount * 1000);
|
|
111
|
+
}
|
|
112
|
+
if (unit === "m" || unit === "min") {
|
|
113
|
+
return Math.round(amount * 60 * 1000);
|
|
114
|
+
}
|
|
115
|
+
if (unit === "h" || unit === "hr") {
|
|
116
|
+
return Math.round(amount * 60 * 60 * 1000);
|
|
117
|
+
}
|
|
118
|
+
if (unit === "d" || unit === "dia" || unit === "dias") {
|
|
119
|
+
return Math.round(amount * 24 * 60 * 60 * 1000);
|
|
120
|
+
}
|
|
121
|
+
return Math.round(amount);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function scheduleNotification(options) {
|
|
125
|
+
return call("scheduleNotification", [normalizeScheduledNotificationOptions(options || {})]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function scheduleNotifications(items) {
|
|
129
|
+
var list = Array.isArray(items) ? items : [];
|
|
130
|
+
return Promise.all(list.map(function (item) {
|
|
131
|
+
return scheduleNotification(item);
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function normalizeNotificationLoop(options) {
|
|
136
|
+
var source = options || {};
|
|
137
|
+
var notifications = source.notificacoes || source.notifications || source.items || [];
|
|
138
|
+
var interval = parseIntervalMs(source.intervalo || source.interval || source.aCada || source.every || source.repeat || source.repetir);
|
|
139
|
+
var normalized;
|
|
140
|
+
|
|
141
|
+
if (!interval) {
|
|
142
|
+
return Promise.reject(new Error("Notification loop interval is required."));
|
|
143
|
+
}
|
|
144
|
+
if (!Array.isArray(notifications) || notifications.length === 0) {
|
|
145
|
+
return Promise.reject(new Error("Notification loop requires at least one notification."));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
normalized = normalizeScheduledNotificationOptions(Object.assign({}, source));
|
|
149
|
+
normalized.intervalo = interval;
|
|
150
|
+
normalized.interval = interval;
|
|
151
|
+
normalized.repeat = true;
|
|
152
|
+
normalized.repetir = true;
|
|
153
|
+
normalized.notificacoes = notifications.map(function (item) {
|
|
154
|
+
return normalizeNotificationOptions(Object.assign({}, item || {}));
|
|
155
|
+
});
|
|
156
|
+
normalized.notifications = normalized.notificacoes;
|
|
157
|
+
normalized.loopIndex = Number(source.loopIndex || source.indiceLoop || 0) || 0;
|
|
158
|
+
normalized.indiceLoop = normalized.loopIndex;
|
|
159
|
+
normalized.quando = normalized.quando || normalized.when || (Date.now() + interval);
|
|
160
|
+
normalized.when = normalized.when || normalized.quando;
|
|
161
|
+
return normalized;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function scheduleNotificationLoop(options) {
|
|
165
|
+
var normalized = normalizeNotificationLoop(options);
|
|
166
|
+
if (normalized && typeof normalized.then === "function") {
|
|
167
|
+
return normalized;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return scheduleNotification(normalized);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function notificationId(input) {
|
|
174
|
+
if (input && typeof input === "object") {
|
|
175
|
+
return input.id || input.notificationId || input.notificacaoId;
|
|
176
|
+
}
|
|
177
|
+
return input;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function normalizeEventType(type) {
|
|
181
|
+
var eventType = String(type || "");
|
|
182
|
+
return eventAliases[eventType] || eventType;
|
|
183
|
+
}
|
|
184
|
+
|
|
34
185
|
function emitNotificationClick(detail) {
|
|
35
186
|
initialNotification = detail || null;
|
|
36
187
|
|
|
@@ -45,12 +196,102 @@ function emitNotificationClick(detail) {
|
|
|
45
196
|
});
|
|
46
197
|
}
|
|
47
198
|
|
|
199
|
+
function emitEvent(type, detail) {
|
|
200
|
+
var eventType = normalizeEventType(type || (detail && detail.type));
|
|
201
|
+
if (!eventType) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
var payload = detail || {};
|
|
206
|
+
payload.type = payload.type || eventType;
|
|
207
|
+
payload.tipo = payload.tipo || eventType;
|
|
208
|
+
payload.timestamp = payload.timestamp || Date.now();
|
|
209
|
+
|
|
210
|
+
(eventListeners[eventType] || []).slice().forEach(function (listener) {
|
|
211
|
+
try {
|
|
212
|
+
listener(payload);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
setTimeout(function () {
|
|
215
|
+
throw error;
|
|
216
|
+
}, 0);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function onEvent(type, listener) {
|
|
222
|
+
if (typeof listener !== "function") {
|
|
223
|
+
throw new TypeError("listener must be a function");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
var eventType = normalizeEventType(type);
|
|
227
|
+
eventListeners[eventType] = eventListeners[eventType] || [];
|
|
228
|
+
eventListeners[eventType].push(listener);
|
|
229
|
+
|
|
230
|
+
return function unsubscribe() {
|
|
231
|
+
eventListeners[eventType] = (eventListeners[eventType] || []).filter(function (item) {
|
|
232
|
+
return item !== listener;
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function firstOrNull(result) {
|
|
238
|
+
return Array.isArray(result) && result.length ? result[0] : null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function openInAppUrl(url, options) {
|
|
242
|
+
var target = String(url || "").trim();
|
|
243
|
+
if (!target) {
|
|
244
|
+
return Promise.reject(new Error("URL is required."));
|
|
245
|
+
}
|
|
246
|
+
if (typeof window === "undefined" || !window.location) {
|
|
247
|
+
return Promise.reject(new Error("window.location is unavailable."));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return new Promise(function (resolve) {
|
|
251
|
+
var replace = Boolean(options && (options.replace || options.substituir));
|
|
252
|
+
resolve({
|
|
253
|
+
url: target,
|
|
254
|
+
target: "app",
|
|
255
|
+
alvo: "app",
|
|
256
|
+
opened: true,
|
|
257
|
+
aberto: true,
|
|
258
|
+
replace: replace,
|
|
259
|
+
substituir: replace
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
setTimeout(function () {
|
|
263
|
+
if (replace) {
|
|
264
|
+
window.location.replace(target);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
window.location.assign(target);
|
|
269
|
+
}, 0);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
48
273
|
var api = {
|
|
49
274
|
notificar: function (messageOrOptions) {
|
|
50
275
|
return call("notify", [normalizeNotificationOptions(messageOrOptions)]);
|
|
51
276
|
},
|
|
52
277
|
agendarNotificacao: function (options) {
|
|
53
|
-
|
|
278
|
+
if (Array.isArray(options)) {
|
|
279
|
+
return scheduleNotifications(options);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return scheduleNotification(options);
|
|
283
|
+
},
|
|
284
|
+
agendarNotificacoes: function (items) {
|
|
285
|
+
return scheduleNotifications(items);
|
|
286
|
+
},
|
|
287
|
+
agendarLoopNotificacoes: function (options) {
|
|
288
|
+
return scheduleNotificationLoop(options);
|
|
289
|
+
},
|
|
290
|
+
cancelarNotificacao: function (id) {
|
|
291
|
+
return call("cancelNotification", [notificationId(id)]);
|
|
292
|
+
},
|
|
293
|
+
cancelarLoopNotificacoes: function (id) {
|
|
294
|
+
return call("cancelNotification", [notificationId(id)]);
|
|
54
295
|
},
|
|
55
296
|
vibrar: function (ms) {
|
|
56
297
|
return call("vibrate", [Number(ms) || 200]);
|
|
@@ -67,15 +308,120 @@ var api = {
|
|
|
67
308
|
brilhoTela: function (value) {
|
|
68
309
|
return call("setScreenBrightness", [Number(value)]);
|
|
69
310
|
},
|
|
311
|
+
definirCorTema: function (optionsOrColor) {
|
|
312
|
+
return call("setSystemBarsColor", [optionsOrColor || "#126fff"]);
|
|
313
|
+
},
|
|
314
|
+
definirCorBarrasSistema: function (optionsOrColor) {
|
|
315
|
+
return call("setSystemBarsColor", [optionsOrColor || "#126fff"]);
|
|
316
|
+
},
|
|
317
|
+
lanterna: function (enabled) {
|
|
318
|
+
return call("flashlight", [Boolean(enabled)]);
|
|
319
|
+
},
|
|
320
|
+
alternarLanterna: function () {
|
|
321
|
+
return call("toggleFlashlight");
|
|
322
|
+
},
|
|
323
|
+
statusLanterna: function () {
|
|
324
|
+
return call("flashlightStatus");
|
|
325
|
+
},
|
|
326
|
+
solicitarPermissaoCamera: function () {
|
|
327
|
+
return call("requestCameraPermission");
|
|
328
|
+
},
|
|
329
|
+
solicitarPermissaoMicrofone: function () {
|
|
330
|
+
return call("requestMicrophonePermission");
|
|
331
|
+
},
|
|
332
|
+
statusMicrofone: function () {
|
|
333
|
+
return call("microphoneStatus");
|
|
334
|
+
},
|
|
335
|
+
ouvirMic: function () {
|
|
336
|
+
return call("startMic");
|
|
337
|
+
},
|
|
338
|
+
pararMic: function () {
|
|
339
|
+
return call("stopMic");
|
|
340
|
+
},
|
|
70
341
|
copiarTexto: function (text) {
|
|
71
342
|
return call("copyText", [String(text || "")]);
|
|
72
343
|
},
|
|
344
|
+
lerTextoCopiado: function () {
|
|
345
|
+
return call("readText");
|
|
346
|
+
},
|
|
73
347
|
compartilharTexto: function (text) {
|
|
74
348
|
return call("shareText", [String(text || "")]);
|
|
75
349
|
},
|
|
350
|
+
compartilhar: function (options) {
|
|
351
|
+
return call("share", [options || {}]);
|
|
352
|
+
},
|
|
76
353
|
abrirUrl: function (url) {
|
|
77
354
|
return call("openUrl", [String(url || "")]);
|
|
78
355
|
},
|
|
356
|
+
abrirUrlExterno: function (url) {
|
|
357
|
+
return call("openUrl", [String(url || "")]);
|
|
358
|
+
},
|
|
359
|
+
abrirForaDoApp: function (url) {
|
|
360
|
+
return call("openUrl", [String(url || "")]);
|
|
361
|
+
},
|
|
362
|
+
abrirNoApp: function (url, options) {
|
|
363
|
+
return openInAppUrl(url, options || {});
|
|
364
|
+
},
|
|
365
|
+
discar: function (phone) {
|
|
366
|
+
return call("dial", [String(phone || "")]);
|
|
367
|
+
},
|
|
368
|
+
abrirMapa: function (query) {
|
|
369
|
+
return call("openMap", [String(query || "")]);
|
|
370
|
+
},
|
|
371
|
+
abrirWhatsapp: function (phone, message) {
|
|
372
|
+
return call("openWhatsapp", [String(phone || ""), String(message || "")]);
|
|
373
|
+
},
|
|
374
|
+
escolherArquivo: function (options) {
|
|
375
|
+
return call("pickFile", [options || {}]).then(firstOrNull);
|
|
376
|
+
},
|
|
377
|
+
escolherArquivos: function (options) {
|
|
378
|
+
var nextOptions = options || {};
|
|
379
|
+
nextOptions.multiplo = nextOptions.multiplo !== false;
|
|
380
|
+
nextOptions.multiple = nextOptions.multiple !== false;
|
|
381
|
+
return call("pickFile", [nextOptions]);
|
|
382
|
+
},
|
|
383
|
+
escolherImagem: function (options) {
|
|
384
|
+
return call("pickFile", [Object.assign({ tipo: "image", kind: "image" }, options || {})]).then(firstOrNull);
|
|
385
|
+
},
|
|
386
|
+
escolherImagens: function (options) {
|
|
387
|
+
return call("pickFile", [Object.assign({ tipo: "image", kind: "image", multiplo: true, multiple: true }, options || {})]);
|
|
388
|
+
},
|
|
389
|
+
escolherVideo: function (options) {
|
|
390
|
+
return call("pickFile", [Object.assign({ tipo: "video", kind: "video" }, options || {})]).then(firstOrNull);
|
|
391
|
+
},
|
|
392
|
+
escolherPasta: function () {
|
|
393
|
+
return call("pickFolder");
|
|
394
|
+
},
|
|
395
|
+
salvarArquivo: function (options) {
|
|
396
|
+
return call("saveFile", [options || {}]);
|
|
397
|
+
},
|
|
398
|
+
infoDispositivo: function () {
|
|
399
|
+
return call("deviceInfo");
|
|
400
|
+
},
|
|
401
|
+
infoRede: function () {
|
|
402
|
+
return call("networkInfo");
|
|
403
|
+
},
|
|
404
|
+
infoBateria: function () {
|
|
405
|
+
return call("batteryInfo");
|
|
406
|
+
},
|
|
407
|
+
infoMemoria: function () {
|
|
408
|
+
return call("memoryInfo");
|
|
409
|
+
},
|
|
410
|
+
infoArmazenamento: function () {
|
|
411
|
+
return call("storageInfo");
|
|
412
|
+
},
|
|
413
|
+
infoDesempenho: function () {
|
|
414
|
+
return call("performanceInfo");
|
|
415
|
+
},
|
|
416
|
+
appsAbertos: function () {
|
|
417
|
+
return call("openAppsMemory");
|
|
418
|
+
},
|
|
419
|
+
infoAppsAbertos: function () {
|
|
420
|
+
return call("openAppsMemory");
|
|
421
|
+
},
|
|
422
|
+
statusPermissoes: function (permissions) {
|
|
423
|
+
return call("permissionStatus", [permissions || []]);
|
|
424
|
+
},
|
|
79
425
|
solicitarPermissaoNotificacoes: function () {
|
|
80
426
|
return call("requestNotificationPermission");
|
|
81
427
|
},
|
|
@@ -109,6 +455,36 @@ var api = {
|
|
|
109
455
|
return initialNotification;
|
|
110
456
|
});
|
|
111
457
|
},
|
|
458
|
+
obterLinkInicial: function () {
|
|
459
|
+
return call("getInitialLink").then(function (link) {
|
|
460
|
+
initialLink = link && link.url ? link : null;
|
|
461
|
+
return initialLink;
|
|
462
|
+
});
|
|
463
|
+
},
|
|
464
|
+
aoEvento: onEvent,
|
|
465
|
+
aoMinimizar: function (listener) {
|
|
466
|
+
return onEvent("app:background", listener);
|
|
467
|
+
},
|
|
468
|
+
aoVoltarParaApp: function (listener) {
|
|
469
|
+
return onEvent("app:voltou", listener);
|
|
470
|
+
},
|
|
471
|
+
aoAbrirLink: function (listener) {
|
|
472
|
+
if (typeof listener !== "function") {
|
|
473
|
+
throw new TypeError("listener must be a function");
|
|
474
|
+
}
|
|
475
|
+
if (initialLink) {
|
|
476
|
+
setTimeout(function () {
|
|
477
|
+
listener(initialLink);
|
|
478
|
+
}, 0);
|
|
479
|
+
}
|
|
480
|
+
return onEvent("link:aberto", listener);
|
|
481
|
+
},
|
|
482
|
+
aoMudarRede: function (listener) {
|
|
483
|
+
return onEvent("rede:mudou", listener);
|
|
484
|
+
},
|
|
485
|
+
aoMudarBateria: function (listener) {
|
|
486
|
+
return onEvent("bateria:mudou", listener);
|
|
487
|
+
},
|
|
112
488
|
aoClicarNotificacao: function (listener) {
|
|
113
489
|
if (typeof listener !== "function") {
|
|
114
490
|
throw new TypeError("listener must be a function");
|
|
@@ -127,9 +503,84 @@ var api = {
|
|
|
127
503
|
},
|
|
128
504
|
__emitNotificationClick: function (detail) {
|
|
129
505
|
emitNotificationClick(detail);
|
|
506
|
+
},
|
|
507
|
+
__emitEvent: function (type, detail) {
|
|
508
|
+
emitEvent(type, detail);
|
|
130
509
|
}
|
|
131
510
|
};
|
|
132
511
|
|
|
512
|
+
Object.assign(api, {
|
|
513
|
+
notify: api.notificar,
|
|
514
|
+
scheduleNotification: api.agendarNotificacao,
|
|
515
|
+
scheduleNotifications: api.agendarNotificacoes,
|
|
516
|
+
scheduleNotificationLoop: api.agendarLoopNotificacoes,
|
|
517
|
+
cancelNotification: api.cancelarNotificacao,
|
|
518
|
+
cancelNotificationLoop: api.cancelarLoopNotificacoes,
|
|
519
|
+
vibrate: api.vibrar,
|
|
520
|
+
manterTelaLigada: api.manterTelaAcordada,
|
|
521
|
+
keepScreenAwake: api.manterTelaAcordada,
|
|
522
|
+
keepScreenOn: api.manterTelaAcordada,
|
|
523
|
+
setScreenBrightness: api.brilhoTela,
|
|
524
|
+
setThemeColor: api.definirCorTema,
|
|
525
|
+
setSystemBarsColor: api.definirCorBarrasSistema,
|
|
526
|
+
flashlight: api.lanterna,
|
|
527
|
+
toggleFlashlight: api.alternarLanterna,
|
|
528
|
+
flashlightStatus: api.statusLanterna,
|
|
529
|
+
requestCameraPermission: api.solicitarPermissaoCamera,
|
|
530
|
+
requestMicrophonePermission: api.solicitarPermissaoMicrofone,
|
|
531
|
+
microphoneStatus: api.statusMicrofone,
|
|
532
|
+
listenMic: api.ouvirMic,
|
|
533
|
+
startMic: api.ouvirMic,
|
|
534
|
+
startMicRecording: api.ouvirMic,
|
|
535
|
+
stopMic: api.pararMic,
|
|
536
|
+
stopMicRecording: api.pararMic,
|
|
537
|
+
copyText: api.copiarTexto,
|
|
538
|
+
readText: api.lerTextoCopiado,
|
|
539
|
+
shareText: api.compartilharTexto,
|
|
540
|
+
share: api.compartilhar,
|
|
541
|
+
openUrl: api.abrirUrl,
|
|
542
|
+
openExternalUrl: api.abrirUrlExterno,
|
|
543
|
+
openOutsideApp: api.abrirForaDoApp,
|
|
544
|
+
openInApp: api.abrirNoApp,
|
|
545
|
+
dial: api.discar,
|
|
546
|
+
openMap: api.abrirMapa,
|
|
547
|
+
openWhatsapp: api.abrirWhatsapp,
|
|
548
|
+
pickFile: api.escolherArquivo,
|
|
549
|
+
pickFiles: api.escolherArquivos,
|
|
550
|
+
pickImage: api.escolherImagem,
|
|
551
|
+
pickImages: api.escolherImagens,
|
|
552
|
+
pickVideo: api.escolherVideo,
|
|
553
|
+
pickFolder: api.escolherPasta,
|
|
554
|
+
saveFile: api.salvarArquivo,
|
|
555
|
+
deviceInfo: api.infoDispositivo,
|
|
556
|
+
networkInfo: api.infoRede,
|
|
557
|
+
batteryInfo: api.infoBateria,
|
|
558
|
+
memoryInfo: api.infoMemoria,
|
|
559
|
+
storageInfo: api.infoArmazenamento,
|
|
560
|
+
performanceInfo: api.infoDesempenho,
|
|
561
|
+
openAppsMemory: api.appsAbertos,
|
|
562
|
+
openAppsInfo: api.infoAppsAbertos,
|
|
563
|
+
permissionStatus: api.statusPermissoes,
|
|
564
|
+
requestNotificationPermission: api.solicitarPermissaoNotificacoes,
|
|
565
|
+
notificationPermissionStatus: api.statusPermissaoNotificacoes,
|
|
566
|
+
canScheduleExactAlarms: api.podeAgendarNotificacaoExata,
|
|
567
|
+
openExactAlarmSettings: api.abrirConfiguracaoAlarmeExato,
|
|
568
|
+
overlayPermissionStatus: api.statusPermissaoSobreposicao,
|
|
569
|
+
requestOverlayPermission: api.solicitarPermissaoSobreposicao,
|
|
570
|
+
openOverlaySettings: api.abrirConfiguracaoSobreposicao,
|
|
571
|
+
startFloatingIcon: api.iniciarIconeFlutuante,
|
|
572
|
+
stopFloatingIcon: api.pararIconeFlutuante,
|
|
573
|
+
getInitialNotification: api.obterNotificacaoInicial,
|
|
574
|
+
getInitialLink: api.obterLinkInicial,
|
|
575
|
+
onEvent: api.aoEvento,
|
|
576
|
+
onMinimize: api.aoMinimizar,
|
|
577
|
+
onAppResume: api.aoVoltarParaApp,
|
|
578
|
+
onOpenLink: api.aoAbrirLink,
|
|
579
|
+
onNetworkChange: api.aoMudarRede,
|
|
580
|
+
onBatteryChange: api.aoMudarBateria,
|
|
581
|
+
onNotificationClick: api.aoClicarNotificacao
|
|
582
|
+
});
|
|
583
|
+
|
|
133
584
|
if (typeof window !== "undefined") {
|
|
134
585
|
window.notificar = api.notificar;
|
|
135
586
|
window.agendarNotificacao = api.agendarNotificacao;
|
|
@@ -137,10 +588,41 @@ if (typeof window !== "undefined") {
|
|
|
137
588
|
window.toast = api.toast;
|
|
138
589
|
window.fullscreen = api.fullscreen;
|
|
139
590
|
window.manterTelaAcordada = api.manterTelaAcordada;
|
|
591
|
+
window.manterTelaLigada = api.manterTelaAcordada;
|
|
140
592
|
window.brilhoTela = api.brilhoTela;
|
|
593
|
+
window.lanterna = api.lanterna;
|
|
594
|
+
window.alternarLanterna = api.alternarLanterna;
|
|
595
|
+
window.statusLanterna = api.statusLanterna;
|
|
596
|
+
window.solicitarPermissaoCamera = api.solicitarPermissaoCamera;
|
|
597
|
+
window.solicitarPermissaoMicrofone = api.solicitarPermissaoMicrofone;
|
|
598
|
+
window.statusMicrofone = api.statusMicrofone;
|
|
599
|
+
window.ouvirMic = api.ouvirMic;
|
|
600
|
+
window.pararMic = api.pararMic;
|
|
141
601
|
window.copiarTexto = api.copiarTexto;
|
|
602
|
+
window.lerTextoCopiado = api.lerTextoCopiado;
|
|
603
|
+
window.compartilhar = api.compartilhar;
|
|
142
604
|
window.compartilharTexto = api.compartilharTexto;
|
|
143
605
|
window.abrirUrl = api.abrirUrl;
|
|
606
|
+
window.abrirUrlExterno = api.abrirUrlExterno;
|
|
607
|
+
window.abrirWhatsapp = api.abrirWhatsapp;
|
|
608
|
+
window.discar = api.discar;
|
|
609
|
+
window.abrirMapa = api.abrirMapa;
|
|
610
|
+
window.escolherArquivo = api.escolherArquivo;
|
|
611
|
+
window.escolherArquivos = api.escolherArquivos;
|
|
612
|
+
window.escolherImagem = api.escolherImagem;
|
|
613
|
+
window.escolherImagens = api.escolherImagens;
|
|
614
|
+
window.escolherVideo = api.escolherVideo;
|
|
615
|
+
window.escolherPasta = api.escolherPasta;
|
|
616
|
+
window.salvarArquivo = api.salvarArquivo;
|
|
617
|
+
window.infoDispositivo = api.infoDispositivo;
|
|
618
|
+
window.infoRede = api.infoRede;
|
|
619
|
+
window.infoBateria = api.infoBateria;
|
|
620
|
+
window.infoMemoria = api.infoMemoria;
|
|
621
|
+
window.infoArmazenamento = api.infoArmazenamento;
|
|
622
|
+
window.infoDesempenho = api.infoDesempenho;
|
|
623
|
+
window.appsAbertos = api.appsAbertos;
|
|
624
|
+
window.infoAppsAbertos = api.infoAppsAbertos;
|
|
625
|
+
window.statusPermissoes = api.statusPermissoes;
|
|
144
626
|
window.solicitarPermissaoNotificacoes = api.solicitarPermissaoNotificacoes;
|
|
145
627
|
window.statusPermissaoNotificacoes = api.statusPermissaoNotificacoes;
|
|
146
628
|
window.podeAgendarNotificacaoExata = api.podeAgendarNotificacaoExata;
|
|
@@ -151,16 +633,47 @@ if (typeof window !== "undefined") {
|
|
|
151
633
|
window.iniciarIconeFlutuante = api.iniciarIconeFlutuante;
|
|
152
634
|
window.pararIconeFlutuante = api.pararIconeFlutuante;
|
|
153
635
|
window.obterNotificacaoInicial = api.obterNotificacaoInicial;
|
|
636
|
+
window.obterLinkInicial = api.obterLinkInicial;
|
|
637
|
+
window.aoEvento = api.aoEvento;
|
|
638
|
+
window.aoMinimizar = api.aoMinimizar;
|
|
639
|
+
window.aoVoltarParaApp = api.aoVoltarParaApp;
|
|
640
|
+
window.aoAbrirLink = api.aoAbrirLink;
|
|
641
|
+
window.aoMudarRede = api.aoMudarRede;
|
|
642
|
+
window.aoMudarBateria = api.aoMudarBateria;
|
|
154
643
|
window.aoClicarNotificacao = api.aoClicarNotificacao;
|
|
155
644
|
|
|
645
|
+
Object.keys(api).forEach(function (key) {
|
|
646
|
+
if (key.indexOf("__") === 0) {
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
window[key] = api[key];
|
|
651
|
+
});
|
|
652
|
+
|
|
156
653
|
window.addEventListener("html2apk:notification", function (event) {
|
|
157
654
|
emitNotificationClick(event.detail);
|
|
158
655
|
});
|
|
159
656
|
|
|
657
|
+
window.addEventListener("html2apk:event", function (event) {
|
|
658
|
+
emitEvent(event.detail && event.detail.type, event.detail);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
document.addEventListener("backbutton", function () {
|
|
662
|
+
emitEvent("botao:voltar", { type: "botao:voltar", timestamp: Date.now() });
|
|
663
|
+
}, false);
|
|
664
|
+
|
|
160
665
|
document.addEventListener("deviceready", function () {
|
|
666
|
+
emitEvent("app:pronto", { type: "app:pronto", timestamp: Date.now() });
|
|
161
667
|
api.obterNotificacaoInicial().then(function (notification) {
|
|
162
668
|
if (notification) {
|
|
163
669
|
emitNotificationClick(notification);
|
|
670
|
+
emitEvent("notificacao:clicada", notification);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
api.obterLinkInicial().then(function (link) {
|
|
674
|
+
if (link) {
|
|
675
|
+
initialLink = link;
|
|
676
|
+
emitEvent("link:aberto", link);
|
|
164
677
|
}
|
|
165
678
|
});
|
|
166
679
|
}, false);
|