jcinfo-utils 1.0.7 → 1.0.9
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/index.js +5 -1
- package/package.json +2 -1
- package/update.css +68 -0
- package/update.js +55 -0
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import checkUpdate from './update.js'
|
|
2
|
+
|
|
1
3
|
// ===================================================== LOGS
|
|
2
4
|
|
|
3
5
|
function addLog({ ...args }) {
|
|
@@ -287,7 +289,7 @@ function formatValor(valor = 0, decimalScale = 2, money = true) {
|
|
|
287
289
|
}).format(valor)
|
|
288
290
|
}
|
|
289
291
|
|
|
290
|
-
|
|
292
|
+
export {
|
|
291
293
|
addLog,
|
|
292
294
|
addUserSelectNoneInMobile,
|
|
293
295
|
calcularIdade,
|
|
@@ -303,4 +305,6 @@ module.exports = {
|
|
|
303
305
|
isMobile,
|
|
304
306
|
random,
|
|
305
307
|
trunc,
|
|
308
|
+
// funções externas
|
|
309
|
+
checkUpdate,
|
|
306
310
|
}
|
package/package.json
CHANGED
package/update.css
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--margin-up: 15px;
|
|
3
|
+
--margin-down: -120px;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
@keyframes c-update-entrada {
|
|
7
|
+
0% {
|
|
8
|
+
opacity: 0;
|
|
9
|
+
bottom: var(--margin-down);
|
|
10
|
+
}
|
|
11
|
+
100% {
|
|
12
|
+
opacity: 1;
|
|
13
|
+
bottom: var(--margin-up);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.c-update {
|
|
18
|
+
position: fixed;
|
|
19
|
+
right: 20px;
|
|
20
|
+
bottom: var(--margin-up);
|
|
21
|
+
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
gap: 8px;
|
|
25
|
+
|
|
26
|
+
background-color: #d6f5ff;
|
|
27
|
+
color: #333;
|
|
28
|
+
padding: 15px 20px;
|
|
29
|
+
border: 1px solid var(--bs-info);
|
|
30
|
+
border-radius: 4px;
|
|
31
|
+
box-shadow: var(--sombra-login);
|
|
32
|
+
|
|
33
|
+
font-family: 'Segoe UI', Geneva, Verdana, sans-serif;
|
|
34
|
+
font-size: 0.9rem;
|
|
35
|
+
width: auto;
|
|
36
|
+
white-space: nowrap;
|
|
37
|
+
user-select: none;
|
|
38
|
+
animation: c-update-entrada 1s both;
|
|
39
|
+
z-index: 9999991;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.c-update i {
|
|
43
|
+
color: var(--bs-info);
|
|
44
|
+
font-size: 1.3rem;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.c-line {
|
|
48
|
+
position: absolute;
|
|
49
|
+
min-height: 85%;
|
|
50
|
+
border-left: 3px solid var(--bs-info);
|
|
51
|
+
left: 4px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@media (max-width: 575px) {
|
|
55
|
+
:root {
|
|
56
|
+
--margin-up: 5px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.c-update {
|
|
60
|
+
max-width: 95vw;
|
|
61
|
+
width: 95vw;
|
|
62
|
+
white-space: unset;
|
|
63
|
+
right: initial;
|
|
64
|
+
left: 50%;
|
|
65
|
+
transform: translateX(-50%);
|
|
66
|
+
border-radius: 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/update.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
import './update.css'
|
|
3
|
+
|
|
4
|
+
const cMessagUpdating =
|
|
5
|
+
'<div class="c-line"></div>' +
|
|
6
|
+
'<i class="fas fa-info-circle"></i>' +
|
|
7
|
+
'Nova versão disponível! Atualizando...'
|
|
8
|
+
|
|
9
|
+
let divUpdate = document.querySelector('#update')
|
|
10
|
+
|
|
11
|
+
if (!divUpdate) {
|
|
12
|
+
divUpdate = document.createElement('div')
|
|
13
|
+
divUpdate.id = 'update'
|
|
14
|
+
document.body.appendChild(divUpdate)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function showMessage(isTest = false, closeAfterShow = false) {
|
|
18
|
+
divUpdate.innerHTML = cMessagUpdating
|
|
19
|
+
divUpdate.classList.add('c-update')
|
|
20
|
+
console.info('Mostrando msg...')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default function checkUpdate() {
|
|
24
|
+
console.info('Versão:', process.env.REACT_APP_VERSION)
|
|
25
|
+
console.info('Server:', process.env.REACT_APP_BASEURL)
|
|
26
|
+
console.info('App:', window.location.origin)
|
|
27
|
+
if ('serviceWorker' in navigator && window.location.origin.startsWith('http')) {
|
|
28
|
+
console.log('Procurando atualizações...')
|
|
29
|
+
navigator.serviceWorker
|
|
30
|
+
.getRegistration()
|
|
31
|
+
.then((registration) => {
|
|
32
|
+
if (!registration) {
|
|
33
|
+
console.info('Sem Service Worker!')
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
console.info('=> Service Worker encontrado:', registration)
|
|
37
|
+
registration.addEventListener('updatefound', () => {
|
|
38
|
+
showMessage()
|
|
39
|
+
const installingWorker = registration.installing
|
|
40
|
+
installingWorker.addEventListener('statechange', () => {
|
|
41
|
+
if (installingWorker.state === 'installed') {
|
|
42
|
+
if (navigator.serviceWorker.controller) {
|
|
43
|
+
window.location.reload(true)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
.catch((error) => {
|
|
50
|
+
console.error('=> Service Worker não encontrado:', error)
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
showMessage(true, true)
|