html2apk 0.3.0 → 0.5.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.
@@ -0,0 +1,860 @@
1
+ "use strict";
2
+
3
+ (function () {
4
+ if (typeof window === "undefined" || window.Html2ApkEarlyBridge) {
5
+ return;
6
+ }
7
+
8
+ var deviceReady = typeof document === "undefined";
9
+ var readyCallbacks = [];
10
+ var scheduledNotificationCounter = 0;
11
+ var notificationActionCounter = 0;
12
+ var notificationActionCallbacks = {};
13
+ var eventAliases = {
14
+ "app:ready": "app:pronto",
15
+ "app:paused": "app:pausado",
16
+ "app:closed": "app:fechado",
17
+ "app:resumed": "app:voltou",
18
+ "back:button": "botao:voltar",
19
+ "link:opened": "link:aberto",
20
+ "network:changed": "rede:mudou",
21
+ "battery:changed": "bateria:mudou",
22
+ "notification:received": "notificacao:recebida",
23
+ "notification:clicked": "notificacao:clicada"
24
+ };
25
+ var eventListeners = {};
26
+ var notificationListeners = [];
27
+ var initialNotification = null;
28
+ var initialLink = null;
29
+
30
+ function markReady() {
31
+ if (deviceReady) {
32
+ return;
33
+ }
34
+ deviceReady = true;
35
+ readyCallbacks.splice(0).forEach(function (callback) {
36
+ callback();
37
+ });
38
+ }
39
+
40
+ function whenReady() {
41
+ if (deviceReady) {
42
+ return Promise.resolve();
43
+ }
44
+ return new Promise(function (resolve) {
45
+ readyCallbacks.push(resolve);
46
+ });
47
+ }
48
+
49
+ if (typeof document !== "undefined") {
50
+ document.addEventListener("deviceready", markReady, false);
51
+ }
52
+
53
+ function call(action, args) {
54
+ return whenCordovaBridgeReady().then(function (exec) {
55
+ return new Promise(function (resolve, reject) {
56
+ try {
57
+ exec(resolve, reject, "Html2ApkBridge", action, args || []);
58
+ } catch (error) {
59
+ reject(error);
60
+ }
61
+ });
62
+ });
63
+ }
64
+
65
+ function whenCordovaBridgeReady() {
66
+ var startedAt;
67
+
68
+ if (isCordovaBridgeReady()) {
69
+ return Promise.resolve(window.cordova.exec);
70
+ }
71
+
72
+ startedAt = Date.now();
73
+ return new Promise(function (resolve, reject) {
74
+ var timer = setInterval(function () {
75
+ if (isCordovaBridgeReady()) {
76
+ clearInterval(timer);
77
+ resolve(window.cordova.exec);
78
+ return;
79
+ }
80
+ if (Date.now() - startedAt > 10000) {
81
+ clearInterval(timer);
82
+ reject(new Error("html2apk native bridge is not ready. Make sure cordova.js finished loading."));
83
+ }
84
+ }, 25);
85
+ });
86
+ }
87
+
88
+ function isCordovaBridgeReady() {
89
+ var channel = cordovaChannel();
90
+ return Boolean(
91
+ window.cordova &&
92
+ typeof window.cordova.exec === "function" &&
93
+ channel &&
94
+ channel.onCordovaReady &&
95
+ channel.onCordovaReady.state === 2
96
+ );
97
+ }
98
+
99
+ function cordovaChannel() {
100
+ try {
101
+ if (window.cordova && typeof window.cordova.require === "function") {
102
+ return window.cordova.require("cordova/channel");
103
+ }
104
+ } catch (error) {
105
+ return null;
106
+ }
107
+ return null;
108
+ }
109
+
110
+ function asyncThrow(error) {
111
+ setTimeout(function () {
112
+ throw error;
113
+ }, 0);
114
+ }
115
+
116
+ function cloneSerializable(value) {
117
+ var output;
118
+
119
+ if (typeof value === "function" || typeof value === "undefined") {
120
+ return undefined;
121
+ }
122
+ if (value === null || typeof value !== "object") {
123
+ return value;
124
+ }
125
+ if (Array.isArray(value)) {
126
+ output = [];
127
+ value.forEach(function (item) {
128
+ var cloned = cloneSerializable(item);
129
+ if (typeof cloned !== "undefined") {
130
+ output.push(cloned);
131
+ }
132
+ });
133
+ return output;
134
+ }
135
+ if (value instanceof Date) {
136
+ return value.toISOString();
137
+ }
138
+
139
+ output = {};
140
+ Object.keys(value).forEach(function (key) {
141
+ var cloned = cloneSerializable(value[key]);
142
+ if (typeof cloned !== "undefined") {
143
+ output[key] = cloned;
144
+ }
145
+ });
146
+ return output;
147
+ }
148
+
149
+ function registerNotificationAction(handler, source) {
150
+ var id = "html2apk-click-" + Date.now() + "-" + (++notificationActionCounter);
151
+ notificationActionCallbacks[id] = function (detail) {
152
+ return handler(detail, source || {});
153
+ };
154
+ return id;
155
+ }
156
+
157
+ function normalizeNotificationClick(click) {
158
+ var normalized;
159
+ var callbackId;
160
+ var actionHandler;
161
+ var functionName;
162
+
163
+ if (typeof click === "function") {
164
+ callbackId = registerNotificationAction(click);
165
+ return {
166
+ action: "run-function",
167
+ acao: "executar-funcao",
168
+ callbackId: callbackId
169
+ };
170
+ }
171
+
172
+ if (!click || typeof click !== "object") {
173
+ return {
174
+ action: "open-app",
175
+ acao: "abrir-app"
176
+ };
177
+ }
178
+
179
+ normalized = cloneSerializable(click) || {};
180
+ actionHandler = click.acao || click.action;
181
+ if (typeof actionHandler === "function") {
182
+ callbackId = registerNotificationAction(actionHandler, click);
183
+ normalized.callbackId = callbackId;
184
+ normalized.action = normalized.action || "run-function";
185
+ normalized.acao = normalized.acao || "executar-funcao";
186
+ }
187
+
188
+ functionName = normalized.funcao || normalized.functionName || normalized.function || normalized.fn || normalized.nomeFuncao;
189
+ if (typeof functionName === "string" && functionName.trim()) {
190
+ normalized.funcao = functionName.trim();
191
+ normalized.functionName = normalized.funcao;
192
+ normalized.action = normalized.action || "run-function";
193
+ normalized.acao = normalized.acao || "executar-funcao";
194
+ }
195
+
196
+ if (normalized.action && !normalized.acao) {
197
+ normalized.acao = normalized.action;
198
+ }
199
+ if (normalized.acao && !normalized.action) {
200
+ normalized.action = normalized.acao;
201
+ }
202
+
203
+ return normalized;
204
+ }
205
+
206
+ function notificationOpenValue(source) {
207
+ if (!source || typeof source !== "object") {
208
+ return undefined;
209
+ }
210
+ if (Object.prototype.hasOwnProperty.call(source, "open")) {
211
+ return source.open !== false;
212
+ }
213
+ if (Object.prototype.hasOwnProperty.call(source, "abrir")) {
214
+ return source.abrir !== false;
215
+ }
216
+ if (Object.prototype.hasOwnProperty.call(source, "abrirApp")) {
217
+ return source.abrirApp !== false;
218
+ }
219
+ if (Object.prototype.hasOwnProperty.call(source, "openApp")) {
220
+ return source.openApp !== false;
221
+ }
222
+ return undefined;
223
+ }
224
+
225
+ function normalizeNotificationActions(actions) {
226
+ if (!Array.isArray(actions)) {
227
+ return actions;
228
+ }
229
+
230
+ return actions.map(function (action) {
231
+ var normalized = cloneSerializable(action) || {};
232
+ var click = action && (action.aoClicar || action.onClick);
233
+ if (!click && action && (
234
+ typeof action.funcao === "string" ||
235
+ typeof action.functionName === "string" ||
236
+ typeof action.fn === "string"
237
+ )) {
238
+ click = action;
239
+ }
240
+ if (click) {
241
+ normalized.aoClicar = normalizeNotificationClick(click);
242
+ normalized.onClick = normalized.aoClicar;
243
+ }
244
+ if (typeof notificationOpenValue(action) !== "undefined") {
245
+ normalized.open = notificationOpenValue(action);
246
+ if (normalized.aoClicar && typeof normalized.aoClicar.open === "undefined") {
247
+ normalized.aoClicar.open = normalized.open;
248
+ normalized.onClick = normalized.aoClicar;
249
+ }
250
+ }
251
+ return normalized;
252
+ });
253
+ }
254
+
255
+ function normalizeNotificationOptions(messageOrOptions) {
256
+ var options;
257
+ var click;
258
+ var actions;
259
+
260
+ if (typeof messageOrOptions === "string") {
261
+ return {
262
+ title: "Notificacao",
263
+ titulo: "Notificacao",
264
+ text: messageOrOptions,
265
+ texto: messageOrOptions,
266
+ onClick: { action: "open-app" }
267
+ };
268
+ }
269
+
270
+ options = cloneSerializable(messageOrOptions || {}) || {};
271
+ click = messageOrOptions && (messageOrOptions.aoClicar || messageOrOptions.onClick);
272
+ options.onClick = normalizeNotificationClick(click);
273
+ options.aoClicar = options.onClick;
274
+ if (typeof notificationOpenValue(messageOrOptions) !== "undefined") {
275
+ options.open = notificationOpenValue(messageOrOptions);
276
+ options.abrir = options.open;
277
+ options.onClick.open = options.open;
278
+ options.aoClicar.open = options.open;
279
+ }
280
+
281
+ actions = normalizeNotificationActions(messageOrOptions && (messageOrOptions.acoes || messageOrOptions.actions));
282
+ if (Array.isArray(actions)) {
283
+ options.acoes = actions;
284
+ options.actions = actions;
285
+ }
286
+
287
+ return options;
288
+ }
289
+
290
+ function notificationId(input) {
291
+ if (input && typeof input === "object") {
292
+ return input.id || input.notificationId || input.notificacaoId;
293
+ }
294
+ return input;
295
+ }
296
+
297
+ function normalizeScheduledNotificationOptions(options) {
298
+ var normalized = normalizeNotificationOptions(options || {});
299
+ if (!normalized.id) {
300
+ scheduledNotificationCounter = (scheduledNotificationCounter + 1) % 100000;
301
+ normalized.id = Math.floor(Date.now() % 0x0fffffff) + scheduledNotificationCounter;
302
+ }
303
+ return normalized;
304
+ }
305
+
306
+ function parseIntervalMs(value) {
307
+ var text;
308
+ var match;
309
+ var amount;
310
+ var unit;
311
+
312
+ if (typeof value === "number" && isFinite(value)) {
313
+ return Math.max(0, Math.round(value));
314
+ }
315
+ if (value && typeof value === "object") {
316
+ return parseIntervalMs(value.intervalo || value.interval || value.aCada || value.every || value.ms);
317
+ }
318
+
319
+ text = String(value || "").trim().toLowerCase();
320
+ match = text.match(/^(\d+(?:\.\d+)?)\s*(ms|s|seg|m|min|h|hr|d|dia|dias)?$/);
321
+ if (!match) {
322
+ return 0;
323
+ }
324
+
325
+ amount = Number(match[1]);
326
+ unit = match[2] || "ms";
327
+ if (unit === "s" || unit === "seg") {
328
+ return Math.round(amount * 1000);
329
+ }
330
+ if (unit === "m" || unit === "min") {
331
+ return Math.round(amount * 60 * 1000);
332
+ }
333
+ if (unit === "h" || unit === "hr") {
334
+ return Math.round(amount * 60 * 60 * 1000);
335
+ }
336
+ if (unit === "d" || unit === "dia" || unit === "dias") {
337
+ return Math.round(amount * 24 * 60 * 60 * 1000);
338
+ }
339
+ return Math.round(amount);
340
+ }
341
+
342
+ function scheduleNotification(options) {
343
+ return call("scheduleNotification", [normalizeScheduledNotificationOptions(options || {})]);
344
+ }
345
+
346
+ function scheduleNotifications(items) {
347
+ var list = Array.isArray(items) ? items : [];
348
+ return Promise.all(list.map(function (item) {
349
+ return scheduleNotification(item);
350
+ }));
351
+ }
352
+
353
+ function scheduleNotificationLoop(options) {
354
+ var source = options || {};
355
+ var notifications = source.notificacoes || source.notifications || source.items || [];
356
+ var interval = parseIntervalMs(source.intervalo || source.interval || source.aCada || source.every || source.repeat || source.repetir);
357
+ var normalized;
358
+
359
+ if (!interval) {
360
+ return Promise.reject(new Error("Notification loop interval is required."));
361
+ }
362
+ if (!Array.isArray(notifications) || notifications.length === 0) {
363
+ return Promise.reject(new Error("Notification loop requires at least one notification."));
364
+ }
365
+
366
+ normalized = normalizeScheduledNotificationOptions(Object.assign({}, source));
367
+ normalized.intervalo = interval;
368
+ normalized.interval = interval;
369
+ normalized.repeat = true;
370
+ normalized.repetir = true;
371
+ normalized.notificacoes = notifications.map(function (item) {
372
+ return normalizeNotificationOptions(Object.assign({}, item || {}));
373
+ });
374
+ normalized.notifications = normalized.notificacoes;
375
+ normalized.loopIndex = Number(source.loopIndex || source.indiceLoop || 0) || 0;
376
+ normalized.indiceLoop = normalized.loopIndex;
377
+ normalized.quando = normalized.quando || normalized.when || (Date.now() + interval);
378
+ normalized.when = normalized.when || normalized.quando;
379
+ return scheduleNotification(normalized);
380
+ }
381
+
382
+ function firstOrNull(result) {
383
+ return Array.isArray(result) && result.length ? result[0] : null;
384
+ }
385
+
386
+ function openInAppUrl(url, options) {
387
+ var target = String(url || "").trim();
388
+ if (!target) {
389
+ return Promise.reject(new Error("URL is required."));
390
+ }
391
+ return Promise.resolve({
392
+ url: target,
393
+ target: "app",
394
+ alvo: "app",
395
+ opened: true,
396
+ aberto: true
397
+ }).then(function (result) {
398
+ setTimeout(function () {
399
+ if (options && (options.replace || options.substituir)) {
400
+ window.location.replace(target);
401
+ return;
402
+ }
403
+ window.location.assign(target);
404
+ }, 0);
405
+ return result;
406
+ });
407
+ }
408
+
409
+ function normalizeEventType(type) {
410
+ var eventType = String(type || "");
411
+ return eventAliases[eventType] || eventType;
412
+ }
413
+
414
+ function emitEvent(type, detail) {
415
+ var eventType = normalizeEventType(type || (detail && detail.type));
416
+ var payload = detail || {};
417
+ if (!eventType) {
418
+ return;
419
+ }
420
+ payload.type = payload.type || eventType;
421
+ payload.tipo = payload.tipo || eventType;
422
+ payload.timestamp = payload.timestamp || Date.now();
423
+ (eventListeners[eventType] || []).slice().forEach(function (listener) {
424
+ listener(payload);
425
+ });
426
+ }
427
+
428
+ function onEvent(type, listener) {
429
+ if (typeof listener !== "function") {
430
+ throw new TypeError("listener must be a function");
431
+ }
432
+ var eventType = normalizeEventType(type);
433
+ eventListeners[eventType] = eventListeners[eventType] || [];
434
+ eventListeners[eventType].push(listener);
435
+ return function unsubscribe() {
436
+ eventListeners[eventType] = (eventListeners[eventType] || []).filter(function (item) {
437
+ return item !== listener;
438
+ });
439
+ };
440
+ }
441
+
442
+ function emitNotificationClick(detail) {
443
+ var notification = detail || null;
444
+ initialNotification = notification;
445
+ notificationListeners.slice().forEach(function (listener) {
446
+ try {
447
+ listener(notification);
448
+ } catch (error) {
449
+ asyncThrow(error);
450
+ }
451
+ });
452
+ executeNotificationClickAction(notification);
453
+ }
454
+
455
+ function notificationActionFromDetail(detail) {
456
+ var action;
457
+
458
+ if (!detail || typeof detail !== "object") {
459
+ return null;
460
+ }
461
+
462
+ action = detail.action || detail.acao;
463
+ if (action && typeof action === "object") {
464
+ if (action.callbackId || action.functionName || action.funcao || action.fn || action.nomeFuncao) {
465
+ return action;
466
+ }
467
+ if (action.aoClicar || action.onClick) {
468
+ return action.aoClicar || action.onClick;
469
+ }
470
+ }
471
+
472
+ return detail.aoClicar || detail.onClick || null;
473
+ }
474
+
475
+ function notificationActionArgs(action, detail) {
476
+ var args = action && (
477
+ action.argumentos ||
478
+ action.args ||
479
+ action.parametros ||
480
+ action.params ||
481
+ action.parameters
482
+ );
483
+
484
+ if (typeof args === "undefined") {
485
+ return action && (action.passarEvento === false || action.passEvent === false) ? [] : [detail];
486
+ }
487
+
488
+ return Array.isArray(args) ? args : [args];
489
+ }
490
+
491
+ function handleActionResult(result) {
492
+ if (result && typeof result.then === "function") {
493
+ result.catch(asyncThrow);
494
+ }
495
+ }
496
+
497
+ function executeNotificationClickAction(detail) {
498
+ var action = notificationActionFromDetail(detail);
499
+ var callbackId = action && (action.callbackId || action.idCallback || action.callback);
500
+ var functionName;
501
+ var handler;
502
+ var args;
503
+
504
+ if (!action || typeof action !== "object") {
505
+ return;
506
+ }
507
+ if (detail && detail.__html2apkActionHandled) {
508
+ return;
509
+ }
510
+
511
+ if (callbackId && notificationActionCallbacks[callbackId]) {
512
+ detail.__html2apkActionHandled = true;
513
+ handleActionResult(notificationActionCallbacks[callbackId](detail));
514
+ return;
515
+ }
516
+
517
+ functionName = action.funcao || action.functionName || action.function || action.fn || action.nomeFuncao;
518
+ if (!functionName) {
519
+ return;
520
+ }
521
+
522
+ handler = api && api[functionName];
523
+ if (typeof handler !== "function") {
524
+ handler = window[functionName];
525
+ }
526
+ if (typeof handler !== "function") {
527
+ return;
528
+ }
529
+
530
+ args = notificationActionArgs(action, detail);
531
+ detail.__html2apkActionHandled = true;
532
+ handleActionResult(handler.apply(window, args));
533
+ }
534
+
535
+ var api = {
536
+ notificar: function (messageOrOptions) {
537
+ return call("notify", [normalizeNotificationOptions(messageOrOptions)]);
538
+ },
539
+ agendarNotificacao: function (options) {
540
+ return Array.isArray(options) ? scheduleNotifications(options) : scheduleNotification(options);
541
+ },
542
+ agendarNotificacoes: scheduleNotifications,
543
+ agendarLoopNotificacoes: scheduleNotificationLoop,
544
+ cancelarNotificacao: function (id) {
545
+ return call("cancelNotification", [notificationId(id)]);
546
+ },
547
+ cancelarLoopNotificacoes: function (id) {
548
+ return call("cancelNotification", [notificationId(id)]);
549
+ },
550
+ vibrar: function (ms) {
551
+ return call("vibrate", [Number(ms) || 200]);
552
+ },
553
+ toast: function (message) {
554
+ return call("toast", [String(message || "")]);
555
+ },
556
+ fullscreen: function (enabled) {
557
+ return call("fullscreen", [Boolean(enabled)]);
558
+ },
559
+ manterTelaAcordada: function (enabled) {
560
+ return call("keepScreenAwake", [Boolean(enabled)]);
561
+ },
562
+ brilhoTela: function (value) {
563
+ return call("setScreenBrightness", [Number(value)]);
564
+ },
565
+ definirCorTema: function (optionsOrColor) {
566
+ return call("setSystemBarsColor", [optionsOrColor || "#126fff"]);
567
+ },
568
+ definirCorBarrasSistema: function (optionsOrColor) {
569
+ return call("setSystemBarsColor", [optionsOrColor || "#126fff"]);
570
+ },
571
+ lanterna: function (enabled) {
572
+ return call("flashlight", [Boolean(enabled)]);
573
+ },
574
+ alternarLanterna: function () {
575
+ return call("toggleFlashlight");
576
+ },
577
+ statusLanterna: function () {
578
+ return call("flashlightStatus");
579
+ },
580
+ solicitarPermissaoCamera: function () {
581
+ return call("requestCameraPermission");
582
+ },
583
+ solicitarPermissaoMicrofone: function () {
584
+ return call("requestMicrophonePermission");
585
+ },
586
+ statusMicrofone: function () {
587
+ return call("microphoneStatus");
588
+ },
589
+ ouvirMic: function () {
590
+ return call("startMic");
591
+ },
592
+ pararMic: function () {
593
+ return call("stopMic");
594
+ },
595
+ copiarTexto: function (text) {
596
+ return call("copyText", [String(text || "")]);
597
+ },
598
+ lerTextoCopiado: function () {
599
+ return call("readText");
600
+ },
601
+ compartilharTexto: function (text) {
602
+ return call("shareText", [String(text || "")]);
603
+ },
604
+ compartilhar: function (options) {
605
+ return call("share", [options || {}]);
606
+ },
607
+ abrirUrl: function (url) {
608
+ return call("openUrl", [String(url || "")]);
609
+ },
610
+ abrirNoApp: function (url, options) {
611
+ return openInAppUrl(url, options || {});
612
+ },
613
+ discar: function (phone) {
614
+ return call("dial", [String(phone || "")]);
615
+ },
616
+ abrirMapa: function (query) {
617
+ return call("openMap", [String(query || "")]);
618
+ },
619
+ abrirWhatsapp: function (phone, message) {
620
+ return call("openWhatsapp", [String(phone || ""), String(message || "")]);
621
+ },
622
+ escolherArquivo: function (options) {
623
+ return call("pickFile", [options || {}]).then(firstOrNull);
624
+ },
625
+ escolherArquivos: function (options) {
626
+ var nextOptions = options || {};
627
+ nextOptions.multiplo = nextOptions.multiplo !== false;
628
+ nextOptions.multiple = nextOptions.multiple !== false;
629
+ return call("pickFile", [nextOptions]);
630
+ },
631
+ escolherImagem: function (options) {
632
+ return call("pickFile", [Object.assign({ tipo: "image", kind: "image" }, options || {})]).then(firstOrNull);
633
+ },
634
+ escolherImagens: function (options) {
635
+ return call("pickFile", [Object.assign({ tipo: "image", kind: "image", multiplo: true, multiple: true }, options || {})]);
636
+ },
637
+ escolherVideo: function (options) {
638
+ return call("pickFile", [Object.assign({ tipo: "video", kind: "video" }, options || {})]).then(firstOrNull);
639
+ },
640
+ escolherPasta: function () {
641
+ return call("pickFolder");
642
+ },
643
+ salvarArquivo: function (options) {
644
+ return call("saveFile", [options || {}]);
645
+ },
646
+ infoDispositivo: function () {
647
+ return call("deviceInfo");
648
+ },
649
+ infoRede: function () {
650
+ return call("networkInfo");
651
+ },
652
+ infoBateria: function () {
653
+ return call("batteryInfo");
654
+ },
655
+ infoMemoria: function () {
656
+ return call("memoryInfo");
657
+ },
658
+ infoArmazenamento: function () {
659
+ return call("storageInfo");
660
+ },
661
+ infoDesempenho: function () {
662
+ return call("performanceInfo");
663
+ },
664
+ appsAbertos: function () {
665
+ return call("openAppsMemory");
666
+ },
667
+ infoAppsAbertos: function () {
668
+ return call("openAppsMemory");
669
+ },
670
+ statusPermissoes: function (permissions) {
671
+ return call("permissionStatus", [permissions || []]);
672
+ },
673
+ solicitarPermissaoNotificacoes: function () {
674
+ return call("requestNotificationPermission");
675
+ },
676
+ statusPermissaoNotificacoes: function () {
677
+ return call("notificationPermissionStatus");
678
+ },
679
+ podeAgendarNotificacaoExata: function () {
680
+ return call("canScheduleExactAlarms");
681
+ },
682
+ abrirConfiguracaoAlarmeExato: function () {
683
+ return call("openExactAlarmSettings");
684
+ },
685
+ statusPermissaoSobreposicao: function () {
686
+ return call("overlayPermissionStatus");
687
+ },
688
+ solicitarPermissaoSobreposicao: function () {
689
+ return call("requestOverlayPermission");
690
+ },
691
+ abrirConfiguracaoSobreposicao: function () {
692
+ return call("openOverlaySettings");
693
+ },
694
+ iniciarIconeFlutuante: function () {
695
+ return call("startFloatingIcon");
696
+ },
697
+ pararIconeFlutuante: function () {
698
+ return call("stopFloatingIcon");
699
+ },
700
+ obterNotificacaoInicial: function () {
701
+ return call("getInitialNotification").then(function (notification) {
702
+ initialNotification = notification && notification.id ? notification : null;
703
+ return initialNotification;
704
+ });
705
+ },
706
+ obterLinkInicial: function () {
707
+ return call("getInitialLink").then(function (link) {
708
+ initialLink = link && link.url ? link : null;
709
+ return initialLink;
710
+ });
711
+ },
712
+ aoEvento: onEvent,
713
+ aoMinimizar: function (listener) {
714
+ return onEvent("app:background", listener);
715
+ },
716
+ aoVoltarParaApp: function (listener) {
717
+ return onEvent("app:voltou", listener);
718
+ },
719
+ aoAbrirLink: function (listener) {
720
+ if (initialLink) {
721
+ setTimeout(function () {
722
+ listener(initialLink);
723
+ }, 0);
724
+ }
725
+ return onEvent("link:aberto", listener);
726
+ },
727
+ aoMudarRede: function (listener) {
728
+ return onEvent("rede:mudou", listener);
729
+ },
730
+ aoMudarBateria: function (listener) {
731
+ return onEvent("bateria:mudou", listener);
732
+ },
733
+ aoClicarNotificacao: function (listener) {
734
+ if (typeof listener !== "function") {
735
+ throw new TypeError("listener must be a function");
736
+ }
737
+ notificationListeners.push(listener);
738
+ if (initialNotification) {
739
+ listener(initialNotification);
740
+ }
741
+ return function unsubscribe() {
742
+ notificationListeners = notificationListeners.filter(function (item) {
743
+ return item !== listener;
744
+ });
745
+ };
746
+ }
747
+ };
748
+
749
+ Object.assign(api, {
750
+ notify: api.notificar,
751
+ scheduleNotification: api.agendarNotificacao,
752
+ scheduleNotifications: api.agendarNotificacoes,
753
+ scheduleNotificationLoop: api.agendarLoopNotificacoes,
754
+ cancelNotification: api.cancelarNotificacao,
755
+ cancelNotificationLoop: api.cancelarLoopNotificacoes,
756
+ vibrate: api.vibrar,
757
+ manterTelaLigada: api.manterTelaAcordada,
758
+ keepScreenAwake: api.manterTelaAcordada,
759
+ keepScreenOn: api.manterTelaAcordada,
760
+ setScreenBrightness: api.brilhoTela,
761
+ setThemeColor: api.definirCorTema,
762
+ setSystemBarsColor: api.definirCorBarrasSistema,
763
+ flashlight: api.lanterna,
764
+ toggleFlashlight: api.alternarLanterna,
765
+ flashlightStatus: api.statusLanterna,
766
+ requestCameraPermission: api.solicitarPermissaoCamera,
767
+ requestMicrophonePermission: api.solicitarPermissaoMicrofone,
768
+ microphoneStatus: api.statusMicrofone,
769
+ listenMic: api.ouvirMic,
770
+ startMic: api.ouvirMic,
771
+ startMicRecording: api.ouvirMic,
772
+ stopMic: api.pararMic,
773
+ stopMicRecording: api.pararMic,
774
+ copyText: api.copiarTexto,
775
+ readText: api.lerTextoCopiado,
776
+ shareText: api.compartilharTexto,
777
+ share: api.compartilhar,
778
+ openUrl: api.abrirUrl,
779
+ openExternalUrl: api.abrirUrl,
780
+ abrirUrlExterno: api.abrirUrl,
781
+ openOutsideApp: api.abrirUrl,
782
+ abrirForaDoApp: api.abrirUrl,
783
+ openInApp: api.abrirNoApp,
784
+ dial: api.discar,
785
+ openMap: api.abrirMapa,
786
+ openWhatsapp: api.abrirWhatsapp,
787
+ pickFile: api.escolherArquivo,
788
+ pickFiles: api.escolherArquivos,
789
+ pickImage: api.escolherImagem,
790
+ pickImages: api.escolherImagens,
791
+ pickVideo: api.escolherVideo,
792
+ pickFolder: api.escolherPasta,
793
+ saveFile: api.salvarArquivo,
794
+ deviceInfo: api.infoDispositivo,
795
+ networkInfo: api.infoRede,
796
+ batteryInfo: api.infoBateria,
797
+ memoryInfo: api.infoMemoria,
798
+ storageInfo: api.infoArmazenamento,
799
+ performanceInfo: api.infoDesempenho,
800
+ openAppsMemory: api.appsAbertos,
801
+ openAppsInfo: api.infoAppsAbertos,
802
+ permissionStatus: api.statusPermissoes,
803
+ requestNotificationPermission: api.solicitarPermissaoNotificacoes,
804
+ notificationPermissionStatus: api.statusPermissaoNotificacoes,
805
+ canScheduleExactAlarms: api.podeAgendarNotificacaoExata,
806
+ openExactAlarmSettings: api.abrirConfiguracaoAlarmeExato,
807
+ overlayPermissionStatus: api.statusPermissaoSobreposicao,
808
+ requestOverlayPermission: api.solicitarPermissaoSobreposicao,
809
+ openOverlaySettings: api.abrirConfiguracaoSobreposicao,
810
+ startFloatingIcon: api.iniciarIconeFlutuante,
811
+ stopFloatingIcon: api.pararIconeFlutuante,
812
+ getInitialNotification: api.obterNotificacaoInicial,
813
+ getInitialLink: api.obterLinkInicial,
814
+ onEvent: api.aoEvento,
815
+ onMinimize: api.aoMinimizar,
816
+ onAppResume: api.aoVoltarParaApp,
817
+ onOpenLink: api.aoAbrirLink,
818
+ onNetworkChange: api.aoMudarRede,
819
+ onBatteryChange: api.aoMudarBateria,
820
+ onNotificationClick: api.aoClicarNotificacao
821
+ });
822
+
823
+ Object.keys(api).forEach(function (key) {
824
+ if (typeof window[key] !== "function") {
825
+ window[key] = api[key];
826
+ }
827
+ });
828
+
829
+ window.Html2ApkEarlyBridge = api;
830
+
831
+ window.addEventListener("html2apk:notification", function (event) {
832
+ emitNotificationClick(event.detail);
833
+ });
834
+
835
+ window.addEventListener("html2apk:event", function (event) {
836
+ emitEvent(event.detail && event.detail.type, event.detail);
837
+ });
838
+
839
+ if (typeof document !== "undefined") {
840
+ document.addEventListener("backbutton", function () {
841
+ emitEvent("botao:voltar", { type: "botao:voltar", timestamp: Date.now() });
842
+ }, false);
843
+
844
+ document.addEventListener("deviceready", function () {
845
+ emitEvent("app:pronto", { type: "app:pronto", timestamp: Date.now() });
846
+ api.obterNotificacaoInicial().then(function (notification) {
847
+ if (notification) {
848
+ emitNotificationClick(notification);
849
+ emitEvent("notificacao:clicada", notification);
850
+ }
851
+ });
852
+ api.obterLinkInicial().then(function (link) {
853
+ if (link) {
854
+ initialLink = link;
855
+ emitEvent("link:aberto", link);
856
+ }
857
+ });
858
+ }, false);
859
+ }
860
+ })();