html2apk 0.2.0 → 0.3.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.
@@ -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 options = parseOptions(intent);
29
- int id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, Html2ApkBridge.notificationId(options));
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(options);
35
- String text = Html2ApkBridge.text(options);
46
+ String title = Html2ApkBridge.title(displayOptions);
47
+ String text = Html2ApkBridge.text(displayOptions);
36
48
  JSONObject detail;
37
49
  try {
38
- detail = Html2ApkBridge.detailPayload(options);
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 || when <= now) {
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,7 +3,22 @@
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 eventAliases = {
11
+ "app:ready": "app:pronto",
12
+ "app:paused": "app:pausado",
13
+ "app:closed": "app:fechado",
14
+ "app:resumed": "app:voltou",
15
+ "back:button": "botao:voltar",
16
+ "link:opened": "link:aberto",
17
+ "network:changed": "rede:mudou",
18
+ "battery:changed": "bateria:mudou",
19
+ "notification:received": "notificacao:recebida",
20
+ "notification:clicked": "notificacao:clicada"
21
+ };
7
22
 
8
23
  function call(action, args) {
9
24
  return new Promise(function (resolve, reject) {
@@ -31,6 +46,113 @@ function normalizeNotificationOptions(messageOrOptions) {
31
46
  return options;
32
47
  }
33
48
 
49
+ function normalizeScheduledNotificationOptions(options) {
50
+ var normalized = normalizeNotificationOptions(options || {});
51
+ if (!normalized.id) {
52
+ scheduledNotificationCounter = (scheduledNotificationCounter + 1) % 100000;
53
+ normalized.id = Math.floor(Date.now() % 0x0fffffff) + scheduledNotificationCounter;
54
+ }
55
+ return normalized;
56
+ }
57
+
58
+ function parseIntervalMs(value) {
59
+ var text;
60
+ var match;
61
+ var amount;
62
+ var unit;
63
+
64
+ if (typeof value === "number" && isFinite(value)) {
65
+ return Math.max(0, Math.round(value));
66
+ }
67
+
68
+ if (value && typeof value === "object") {
69
+ return parseIntervalMs(value.intervalo || value.interval || value.aCada || value.every || value.ms);
70
+ }
71
+
72
+ text = String(value || "").trim().toLowerCase();
73
+ match = text.match(/^(\d+(?:\.\d+)?)\s*(ms|s|seg|m|min|h|hr|d|dia|dias)?$/);
74
+ if (!match) {
75
+ return 0;
76
+ }
77
+
78
+ amount = Number(match[1]);
79
+ unit = match[2] || "ms";
80
+ if (unit === "s" || unit === "seg") {
81
+ return Math.round(amount * 1000);
82
+ }
83
+ if (unit === "m" || unit === "min") {
84
+ return Math.round(amount * 60 * 1000);
85
+ }
86
+ if (unit === "h" || unit === "hr") {
87
+ return Math.round(amount * 60 * 60 * 1000);
88
+ }
89
+ if (unit === "d" || unit === "dia" || unit === "dias") {
90
+ return Math.round(amount * 24 * 60 * 60 * 1000);
91
+ }
92
+ return Math.round(amount);
93
+ }
94
+
95
+ function scheduleNotification(options) {
96
+ return call("scheduleNotification", [normalizeScheduledNotificationOptions(options || {})]);
97
+ }
98
+
99
+ function scheduleNotifications(items) {
100
+ var list = Array.isArray(items) ? items : [];
101
+ return Promise.all(list.map(function (item) {
102
+ return scheduleNotification(item);
103
+ }));
104
+ }
105
+
106
+ function normalizeNotificationLoop(options) {
107
+ var source = options || {};
108
+ var notifications = source.notificacoes || source.notifications || source.items || [];
109
+ var interval = parseIntervalMs(source.intervalo || source.interval || source.aCada || source.every || source.repeat || source.repetir);
110
+ var normalized;
111
+
112
+ if (!interval) {
113
+ return Promise.reject(new Error("Notification loop interval is required."));
114
+ }
115
+ if (!Array.isArray(notifications) || notifications.length === 0) {
116
+ return Promise.reject(new Error("Notification loop requires at least one notification."));
117
+ }
118
+
119
+ normalized = normalizeScheduledNotificationOptions(Object.assign({}, source));
120
+ normalized.intervalo = interval;
121
+ normalized.interval = interval;
122
+ normalized.repeat = true;
123
+ normalized.repetir = true;
124
+ normalized.notificacoes = notifications.map(function (item) {
125
+ return normalizeNotificationOptions(Object.assign({}, item || {}));
126
+ });
127
+ normalized.notifications = normalized.notificacoes;
128
+ normalized.loopIndex = Number(source.loopIndex || source.indiceLoop || 0) || 0;
129
+ normalized.indiceLoop = normalized.loopIndex;
130
+ normalized.quando = normalized.quando || normalized.when || (Date.now() + interval);
131
+ normalized.when = normalized.when || normalized.quando;
132
+ return normalized;
133
+ }
134
+
135
+ function scheduleNotificationLoop(options) {
136
+ var normalized = normalizeNotificationLoop(options);
137
+ if (normalized && typeof normalized.then === "function") {
138
+ return normalized;
139
+ }
140
+
141
+ return scheduleNotification(normalized);
142
+ }
143
+
144
+ function notificationId(input) {
145
+ if (input && typeof input === "object") {
146
+ return input.id || input.notificationId || input.notificacaoId;
147
+ }
148
+ return input;
149
+ }
150
+
151
+ function normalizeEventType(type) {
152
+ var eventType = String(type || "");
153
+ return eventAliases[eventType] || eventType;
154
+ }
155
+
34
156
  function emitNotificationClick(detail) {
35
157
  initialNotification = detail || null;
36
158
 
@@ -45,12 +167,102 @@ function emitNotificationClick(detail) {
45
167
  });
46
168
  }
47
169
 
170
+ function emitEvent(type, detail) {
171
+ var eventType = normalizeEventType(type || (detail && detail.type));
172
+ if (!eventType) {
173
+ return;
174
+ }
175
+
176
+ var payload = detail || {};
177
+ payload.type = payload.type || eventType;
178
+ payload.tipo = payload.tipo || eventType;
179
+ payload.timestamp = payload.timestamp || Date.now();
180
+
181
+ (eventListeners[eventType] || []).slice().forEach(function (listener) {
182
+ try {
183
+ listener(payload);
184
+ } catch (error) {
185
+ setTimeout(function () {
186
+ throw error;
187
+ }, 0);
188
+ }
189
+ });
190
+ }
191
+
192
+ function onEvent(type, listener) {
193
+ if (typeof listener !== "function") {
194
+ throw new TypeError("listener must be a function");
195
+ }
196
+
197
+ var eventType = normalizeEventType(type);
198
+ eventListeners[eventType] = eventListeners[eventType] || [];
199
+ eventListeners[eventType].push(listener);
200
+
201
+ return function unsubscribe() {
202
+ eventListeners[eventType] = (eventListeners[eventType] || []).filter(function (item) {
203
+ return item !== listener;
204
+ });
205
+ };
206
+ }
207
+
208
+ function firstOrNull(result) {
209
+ return Array.isArray(result) && result.length ? result[0] : null;
210
+ }
211
+
212
+ function openInAppUrl(url, options) {
213
+ var target = String(url || "").trim();
214
+ if (!target) {
215
+ return Promise.reject(new Error("URL is required."));
216
+ }
217
+ if (typeof window === "undefined" || !window.location) {
218
+ return Promise.reject(new Error("window.location is unavailable."));
219
+ }
220
+
221
+ return new Promise(function (resolve) {
222
+ var replace = Boolean(options && (options.replace || options.substituir));
223
+ resolve({
224
+ url: target,
225
+ target: "app",
226
+ alvo: "app",
227
+ opened: true,
228
+ aberto: true,
229
+ replace: replace,
230
+ substituir: replace
231
+ });
232
+
233
+ setTimeout(function () {
234
+ if (replace) {
235
+ window.location.replace(target);
236
+ return;
237
+ }
238
+
239
+ window.location.assign(target);
240
+ }, 0);
241
+ });
242
+ }
243
+
48
244
  var api = {
49
245
  notificar: function (messageOrOptions) {
50
246
  return call("notify", [normalizeNotificationOptions(messageOrOptions)]);
51
247
  },
52
248
  agendarNotificacao: function (options) {
53
- return call("scheduleNotification", [normalizeNotificationOptions(options || {})]);
249
+ if (Array.isArray(options)) {
250
+ return scheduleNotifications(options);
251
+ }
252
+
253
+ return scheduleNotification(options);
254
+ },
255
+ agendarNotificacoes: function (items) {
256
+ return scheduleNotifications(items);
257
+ },
258
+ agendarLoopNotificacoes: function (options) {
259
+ return scheduleNotificationLoop(options);
260
+ },
261
+ cancelarNotificacao: function (id) {
262
+ return call("cancelNotification", [notificationId(id)]);
263
+ },
264
+ cancelarLoopNotificacoes: function (id) {
265
+ return call("cancelNotification", [notificationId(id)]);
54
266
  },
55
267
  vibrar: function (ms) {
56
268
  return call("vibrate", [Number(ms) || 200]);
@@ -67,15 +279,120 @@ var api = {
67
279
  brilhoTela: function (value) {
68
280
  return call("setScreenBrightness", [Number(value)]);
69
281
  },
282
+ definirCorTema: function (optionsOrColor) {
283
+ return call("setSystemBarsColor", [optionsOrColor || "#126fff"]);
284
+ },
285
+ definirCorBarrasSistema: function (optionsOrColor) {
286
+ return call("setSystemBarsColor", [optionsOrColor || "#126fff"]);
287
+ },
288
+ lanterna: function (enabled) {
289
+ return call("flashlight", [Boolean(enabled)]);
290
+ },
291
+ alternarLanterna: function () {
292
+ return call("toggleFlashlight");
293
+ },
294
+ statusLanterna: function () {
295
+ return call("flashlightStatus");
296
+ },
297
+ solicitarPermissaoCamera: function () {
298
+ return call("requestCameraPermission");
299
+ },
300
+ solicitarPermissaoMicrofone: function () {
301
+ return call("requestMicrophonePermission");
302
+ },
303
+ statusMicrofone: function () {
304
+ return call("microphoneStatus");
305
+ },
306
+ ouvirMic: function () {
307
+ return call("startMic");
308
+ },
309
+ pararMic: function () {
310
+ return call("stopMic");
311
+ },
70
312
  copiarTexto: function (text) {
71
313
  return call("copyText", [String(text || "")]);
72
314
  },
315
+ lerTextoCopiado: function () {
316
+ return call("readText");
317
+ },
73
318
  compartilharTexto: function (text) {
74
319
  return call("shareText", [String(text || "")]);
75
320
  },
321
+ compartilhar: function (options) {
322
+ return call("share", [options || {}]);
323
+ },
76
324
  abrirUrl: function (url) {
77
325
  return call("openUrl", [String(url || "")]);
78
326
  },
327
+ abrirUrlExterno: function (url) {
328
+ return call("openUrl", [String(url || "")]);
329
+ },
330
+ abrirForaDoApp: function (url) {
331
+ return call("openUrl", [String(url || "")]);
332
+ },
333
+ abrirNoApp: function (url, options) {
334
+ return openInAppUrl(url, options || {});
335
+ },
336
+ discar: function (phone) {
337
+ return call("dial", [String(phone || "")]);
338
+ },
339
+ abrirMapa: function (query) {
340
+ return call("openMap", [String(query || "")]);
341
+ },
342
+ abrirWhatsapp: function (phone, message) {
343
+ return call("openWhatsapp", [String(phone || ""), String(message || "")]);
344
+ },
345
+ escolherArquivo: function (options) {
346
+ return call("pickFile", [options || {}]).then(firstOrNull);
347
+ },
348
+ escolherArquivos: function (options) {
349
+ var nextOptions = options || {};
350
+ nextOptions.multiplo = nextOptions.multiplo !== false;
351
+ nextOptions.multiple = nextOptions.multiple !== false;
352
+ return call("pickFile", [nextOptions]);
353
+ },
354
+ escolherImagem: function (options) {
355
+ return call("pickFile", [Object.assign({ tipo: "image", kind: "image" }, options || {})]).then(firstOrNull);
356
+ },
357
+ escolherImagens: function (options) {
358
+ return call("pickFile", [Object.assign({ tipo: "image", kind: "image", multiplo: true, multiple: true }, options || {})]);
359
+ },
360
+ escolherVideo: function (options) {
361
+ return call("pickFile", [Object.assign({ tipo: "video", kind: "video" }, options || {})]).then(firstOrNull);
362
+ },
363
+ escolherPasta: function () {
364
+ return call("pickFolder");
365
+ },
366
+ salvarArquivo: function (options) {
367
+ return call("saveFile", [options || {}]);
368
+ },
369
+ infoDispositivo: function () {
370
+ return call("deviceInfo");
371
+ },
372
+ infoRede: function () {
373
+ return call("networkInfo");
374
+ },
375
+ infoBateria: function () {
376
+ return call("batteryInfo");
377
+ },
378
+ infoMemoria: function () {
379
+ return call("memoryInfo");
380
+ },
381
+ infoArmazenamento: function () {
382
+ return call("storageInfo");
383
+ },
384
+ infoDesempenho: function () {
385
+ return call("performanceInfo");
386
+ },
387
+ appsAbertos: function () {
388
+ return call("openAppsMemory");
389
+ },
390
+ infoAppsAbertos: function () {
391
+ return call("openAppsMemory");
392
+ },
393
+ statusPermissoes: function (permissions) {
394
+ return call("permissionStatus", [permissions || []]);
395
+ },
79
396
  solicitarPermissaoNotificacoes: function () {
80
397
  return call("requestNotificationPermission");
81
398
  },
@@ -109,6 +426,36 @@ var api = {
109
426
  return initialNotification;
110
427
  });
111
428
  },
429
+ obterLinkInicial: function () {
430
+ return call("getInitialLink").then(function (link) {
431
+ initialLink = link && link.url ? link : null;
432
+ return initialLink;
433
+ });
434
+ },
435
+ aoEvento: onEvent,
436
+ aoMinimizar: function (listener) {
437
+ return onEvent("app:background", listener);
438
+ },
439
+ aoVoltarParaApp: function (listener) {
440
+ return onEvent("app:voltou", listener);
441
+ },
442
+ aoAbrirLink: function (listener) {
443
+ if (typeof listener !== "function") {
444
+ throw new TypeError("listener must be a function");
445
+ }
446
+ if (initialLink) {
447
+ setTimeout(function () {
448
+ listener(initialLink);
449
+ }, 0);
450
+ }
451
+ return onEvent("link:aberto", listener);
452
+ },
453
+ aoMudarRede: function (listener) {
454
+ return onEvent("rede:mudou", listener);
455
+ },
456
+ aoMudarBateria: function (listener) {
457
+ return onEvent("bateria:mudou", listener);
458
+ },
112
459
  aoClicarNotificacao: function (listener) {
113
460
  if (typeof listener !== "function") {
114
461
  throw new TypeError("listener must be a function");
@@ -127,9 +474,84 @@ var api = {
127
474
  },
128
475
  __emitNotificationClick: function (detail) {
129
476
  emitNotificationClick(detail);
477
+ },
478
+ __emitEvent: function (type, detail) {
479
+ emitEvent(type, detail);
130
480
  }
131
481
  };
132
482
 
483
+ Object.assign(api, {
484
+ notify: api.notificar,
485
+ scheduleNotification: api.agendarNotificacao,
486
+ scheduleNotifications: api.agendarNotificacoes,
487
+ scheduleNotificationLoop: api.agendarLoopNotificacoes,
488
+ cancelNotification: api.cancelarNotificacao,
489
+ cancelNotificationLoop: api.cancelarLoopNotificacoes,
490
+ vibrate: api.vibrar,
491
+ manterTelaLigada: api.manterTelaAcordada,
492
+ keepScreenAwake: api.manterTelaAcordada,
493
+ keepScreenOn: api.manterTelaAcordada,
494
+ setScreenBrightness: api.brilhoTela,
495
+ setThemeColor: api.definirCorTema,
496
+ setSystemBarsColor: api.definirCorBarrasSistema,
497
+ flashlight: api.lanterna,
498
+ toggleFlashlight: api.alternarLanterna,
499
+ flashlightStatus: api.statusLanterna,
500
+ requestCameraPermission: api.solicitarPermissaoCamera,
501
+ requestMicrophonePermission: api.solicitarPermissaoMicrofone,
502
+ microphoneStatus: api.statusMicrofone,
503
+ listenMic: api.ouvirMic,
504
+ startMic: api.ouvirMic,
505
+ startMicRecording: api.ouvirMic,
506
+ stopMic: api.pararMic,
507
+ stopMicRecording: api.pararMic,
508
+ copyText: api.copiarTexto,
509
+ readText: api.lerTextoCopiado,
510
+ shareText: api.compartilharTexto,
511
+ share: api.compartilhar,
512
+ openUrl: api.abrirUrl,
513
+ openExternalUrl: api.abrirUrlExterno,
514
+ openOutsideApp: api.abrirForaDoApp,
515
+ openInApp: api.abrirNoApp,
516
+ dial: api.discar,
517
+ openMap: api.abrirMapa,
518
+ openWhatsapp: api.abrirWhatsapp,
519
+ pickFile: api.escolherArquivo,
520
+ pickFiles: api.escolherArquivos,
521
+ pickImage: api.escolherImagem,
522
+ pickImages: api.escolherImagens,
523
+ pickVideo: api.escolherVideo,
524
+ pickFolder: api.escolherPasta,
525
+ saveFile: api.salvarArquivo,
526
+ deviceInfo: api.infoDispositivo,
527
+ networkInfo: api.infoRede,
528
+ batteryInfo: api.infoBateria,
529
+ memoryInfo: api.infoMemoria,
530
+ storageInfo: api.infoArmazenamento,
531
+ performanceInfo: api.infoDesempenho,
532
+ openAppsMemory: api.appsAbertos,
533
+ openAppsInfo: api.infoAppsAbertos,
534
+ permissionStatus: api.statusPermissoes,
535
+ requestNotificationPermission: api.solicitarPermissaoNotificacoes,
536
+ notificationPermissionStatus: api.statusPermissaoNotificacoes,
537
+ canScheduleExactAlarms: api.podeAgendarNotificacaoExata,
538
+ openExactAlarmSettings: api.abrirConfiguracaoAlarmeExato,
539
+ overlayPermissionStatus: api.statusPermissaoSobreposicao,
540
+ requestOverlayPermission: api.solicitarPermissaoSobreposicao,
541
+ openOverlaySettings: api.abrirConfiguracaoSobreposicao,
542
+ startFloatingIcon: api.iniciarIconeFlutuante,
543
+ stopFloatingIcon: api.pararIconeFlutuante,
544
+ getInitialNotification: api.obterNotificacaoInicial,
545
+ getInitialLink: api.obterLinkInicial,
546
+ onEvent: api.aoEvento,
547
+ onMinimize: api.aoMinimizar,
548
+ onAppResume: api.aoVoltarParaApp,
549
+ onOpenLink: api.aoAbrirLink,
550
+ onNetworkChange: api.aoMudarRede,
551
+ onBatteryChange: api.aoMudarBateria,
552
+ onNotificationClick: api.aoClicarNotificacao
553
+ });
554
+
133
555
  if (typeof window !== "undefined") {
134
556
  window.notificar = api.notificar;
135
557
  window.agendarNotificacao = api.agendarNotificacao;
@@ -137,10 +559,41 @@ if (typeof window !== "undefined") {
137
559
  window.toast = api.toast;
138
560
  window.fullscreen = api.fullscreen;
139
561
  window.manterTelaAcordada = api.manterTelaAcordada;
562
+ window.manterTelaLigada = api.manterTelaAcordada;
140
563
  window.brilhoTela = api.brilhoTela;
564
+ window.lanterna = api.lanterna;
565
+ window.alternarLanterna = api.alternarLanterna;
566
+ window.statusLanterna = api.statusLanterna;
567
+ window.solicitarPermissaoCamera = api.solicitarPermissaoCamera;
568
+ window.solicitarPermissaoMicrofone = api.solicitarPermissaoMicrofone;
569
+ window.statusMicrofone = api.statusMicrofone;
570
+ window.ouvirMic = api.ouvirMic;
571
+ window.pararMic = api.pararMic;
141
572
  window.copiarTexto = api.copiarTexto;
573
+ window.lerTextoCopiado = api.lerTextoCopiado;
574
+ window.compartilhar = api.compartilhar;
142
575
  window.compartilharTexto = api.compartilharTexto;
143
576
  window.abrirUrl = api.abrirUrl;
577
+ window.abrirUrlExterno = api.abrirUrlExterno;
578
+ window.abrirWhatsapp = api.abrirWhatsapp;
579
+ window.discar = api.discar;
580
+ window.abrirMapa = api.abrirMapa;
581
+ window.escolherArquivo = api.escolherArquivo;
582
+ window.escolherArquivos = api.escolherArquivos;
583
+ window.escolherImagem = api.escolherImagem;
584
+ window.escolherImagens = api.escolherImagens;
585
+ window.escolherVideo = api.escolherVideo;
586
+ window.escolherPasta = api.escolherPasta;
587
+ window.salvarArquivo = api.salvarArquivo;
588
+ window.infoDispositivo = api.infoDispositivo;
589
+ window.infoRede = api.infoRede;
590
+ window.infoBateria = api.infoBateria;
591
+ window.infoMemoria = api.infoMemoria;
592
+ window.infoArmazenamento = api.infoArmazenamento;
593
+ window.infoDesempenho = api.infoDesempenho;
594
+ window.appsAbertos = api.appsAbertos;
595
+ window.infoAppsAbertos = api.infoAppsAbertos;
596
+ window.statusPermissoes = api.statusPermissoes;
144
597
  window.solicitarPermissaoNotificacoes = api.solicitarPermissaoNotificacoes;
145
598
  window.statusPermissaoNotificacoes = api.statusPermissaoNotificacoes;
146
599
  window.podeAgendarNotificacaoExata = api.podeAgendarNotificacaoExata;
@@ -151,16 +604,47 @@ if (typeof window !== "undefined") {
151
604
  window.iniciarIconeFlutuante = api.iniciarIconeFlutuante;
152
605
  window.pararIconeFlutuante = api.pararIconeFlutuante;
153
606
  window.obterNotificacaoInicial = api.obterNotificacaoInicial;
607
+ window.obterLinkInicial = api.obterLinkInicial;
608
+ window.aoEvento = api.aoEvento;
609
+ window.aoMinimizar = api.aoMinimizar;
610
+ window.aoVoltarParaApp = api.aoVoltarParaApp;
611
+ window.aoAbrirLink = api.aoAbrirLink;
612
+ window.aoMudarRede = api.aoMudarRede;
613
+ window.aoMudarBateria = api.aoMudarBateria;
154
614
  window.aoClicarNotificacao = api.aoClicarNotificacao;
155
615
 
616
+ Object.keys(api).forEach(function (key) {
617
+ if (key.indexOf("__") === 0) {
618
+ return;
619
+ }
620
+
621
+ window[key] = api[key];
622
+ });
623
+
156
624
  window.addEventListener("html2apk:notification", function (event) {
157
625
  emitNotificationClick(event.detail);
158
626
  });
159
627
 
628
+ window.addEventListener("html2apk:event", function (event) {
629
+ emitEvent(event.detail && event.detail.type, event.detail);
630
+ });
631
+
632
+ document.addEventListener("backbutton", function () {
633
+ emitEvent("botao:voltar", { type: "botao:voltar", timestamp: Date.now() });
634
+ }, false);
635
+
160
636
  document.addEventListener("deviceready", function () {
637
+ emitEvent("app:pronto", { type: "app:pronto", timestamp: Date.now() });
161
638
  api.obterNotificacaoInicial().then(function (notification) {
162
639
  if (notification) {
163
640
  emitNotificationClick(notification);
641
+ emitEvent("notificacao:clicada", notification);
642
+ }
643
+ });
644
+ api.obterLinkInicial().then(function (link) {
645
+ if (link) {
646
+ initialLink = link;
647
+ emitEvent("link:aberto", link);
164
648
  }
165
649
  });
166
650
  }, false);