@proteinjs/app-version-ui 1.0.22 → 1.1.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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/dist/src/useVersionChecker.d.ts +4 -0
- package/dist/src/useVersionChecker.d.ts.map +1 -1
- package/dist/src/useVersionChecker.js +27 -0
- package/dist/src/useVersionChecker.js.map +1 -1
- package/package.json +5 -4
- package/src/useVersionChecker.tsx +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.1.0](https://github.com/proteinjs/notifications/compare/@proteinjs/app-version-ui@1.0.23...@proteinjs/app-version-ui@1.1.0) (2026-04-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* auto-reload on window refocus after 30s when update is pending ([ac4900c](https://github.com/proteinjs/notifications/commit/ac4900c7d15c21f0e20c428939cde2f15d4528f8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [1.0.2](https://github.com/proteinjs/notifications/compare/@proteinjs/app-version-ui@1.0.1...@proteinjs/app-version-ui@1.0.2) (2024-08-02)
|
|
7
18
|
|
|
8
19
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Brent Bahry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -8,6 +8,10 @@ import { Socket } from 'socket.io-client';
|
|
|
8
8
|
* This hook will check with the server if the client should update when the socket
|
|
9
9
|
* receives a `connect` event.
|
|
10
10
|
*
|
|
11
|
+
* When `needToUpdate` is `true`, the hook will also automatically reload the page
|
|
12
|
+
* when the tab regains focus after being hidden for at least 30 seconds. This
|
|
13
|
+
* ensures background tabs pick up new versions without user interaction.
|
|
14
|
+
*
|
|
11
15
|
* Reason:
|
|
12
16
|
*
|
|
13
17
|
* When a new version is deployed, the server process will terminate. The socket will always
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVersionChecker.d.ts","sourceRoot":"","sources":["../../src/useVersionChecker.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"useVersionChecker.d.ts","sourceRoot":"","sources":["../../src/useVersionChecker.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,iBAAiB,mBAAoB,MAAM,UAAU,MAAM,GAAG,IAAI;;CAgE9E,CAAC"}
|
|
@@ -13,6 +13,7 @@ exports.useVersionChecker = void 0;
|
|
|
13
13
|
const react_1 = require("react");
|
|
14
14
|
const app_version_common_1 = require("@proteinjs/app-version-common");
|
|
15
15
|
const util_1 = require("@proteinjs/util");
|
|
16
|
+
const VISIBILITY_CHANGE_THRESHOLD_MS = 30000;
|
|
16
17
|
/**
|
|
17
18
|
* A hook that exposes `needToUpdate`, which indicates whether or not the client's
|
|
18
19
|
* bundle is stale and the new version has been marked as significant enough to
|
|
@@ -22,6 +23,10 @@ const util_1 = require("@proteinjs/util");
|
|
|
22
23
|
* This hook will check with the server if the client should update when the socket
|
|
23
24
|
* receives a `connect` event.
|
|
24
25
|
*
|
|
26
|
+
* When `needToUpdate` is `true`, the hook will also automatically reload the page
|
|
27
|
+
* when the tab regains focus after being hidden for at least 30 seconds. This
|
|
28
|
+
* ensures background tabs pick up new versions without user interaction.
|
|
29
|
+
*
|
|
25
30
|
* Reason:
|
|
26
31
|
*
|
|
27
32
|
* When a new version is deployed, the server process will terminate. The socket will always
|
|
@@ -36,6 +41,7 @@ const useVersionChecker = (currentVersion, socket) => {
|
|
|
36
41
|
const [needToUpdate, setNeedToUpdate] = (0, react_1.useState)(false);
|
|
37
42
|
const debouncerRef = (0, react_1.useRef)(new util_1.Debouncer(1000));
|
|
38
43
|
const needToUpdateRef = (0, react_1.useRef)(needToUpdate); // having `needToUpdate` in the `checkVersion` dep array was causing double checks, despite debouncer
|
|
44
|
+
const hiddenAtRef = (0, react_1.useRef)(null);
|
|
39
45
|
(0, react_1.useEffect)(() => {
|
|
40
46
|
needToUpdateRef.current = needToUpdate;
|
|
41
47
|
}, [needToUpdate]);
|
|
@@ -62,6 +68,27 @@ const useVersionChecker = (currentVersion, socket) => {
|
|
|
62
68
|
socket.off('connect', handleConnect);
|
|
63
69
|
};
|
|
64
70
|
}, [socket, checkVersion]);
|
|
71
|
+
// Auto-reload when the window regains focus after being blurred for 30s+.
|
|
72
|
+
// Uses window blur/focus rather than document visibilitychange so that
|
|
73
|
+
// switching to another desktop app (not just another browser tab) is detected.
|
|
74
|
+
(0, react_1.useEffect)(() => {
|
|
75
|
+
const handleBlur = () => {
|
|
76
|
+
hiddenAtRef.current = Date.now();
|
|
77
|
+
};
|
|
78
|
+
const handleFocus = () => {
|
|
79
|
+
if (needToUpdateRef.current &&
|
|
80
|
+
hiddenAtRef.current &&
|
|
81
|
+
Date.now() - hiddenAtRef.current > VISIBILITY_CHANGE_THRESHOLD_MS) {
|
|
82
|
+
window.location.reload();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
window.addEventListener('blur', handleBlur);
|
|
86
|
+
window.addEventListener('focus', handleFocus);
|
|
87
|
+
return () => {
|
|
88
|
+
window.removeEventListener('blur', handleBlur);
|
|
89
|
+
window.removeEventListener('focus', handleFocus);
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
65
92
|
return { needToUpdate };
|
|
66
93
|
};
|
|
67
94
|
exports.useVersionChecker = useVersionChecker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVersionChecker.js","sourceRoot":"","sources":["../../src/useVersionChecker.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiE;AACjE,sEAAyE;AAEzE,0CAA4C;AAE5C
|
|
1
|
+
{"version":3,"file":"useVersionChecker.js","sourceRoot":"","sources":["../../src/useVersionChecker.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiE;AACjE,sEAAyE;AAEzE,0CAA4C;AAE5C,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACI,MAAM,iBAAiB,GAAG,CAAC,cAAsB,EAAE,MAAqB,EAAE,EAAE;IACjF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ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+EAA+E;IAC/E,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,UAAU,GAAG,GAAG,EAAE;YACtB,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACnC,CAAC,CAAC;QAEF,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,IACE,eAAe,CAAC,OAAO;gBACvB,WAAW,CAAC,OAAO;gBACnB,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,OAAO,GAAG,8BAA8B,EACjE;gBACA,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;aAC1B;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAC5C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC9C,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YAC/C,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACnD,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC,CAAC;AAhEW,QAAA,iBAAiB,qBAgE5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/app-version-ui",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "App version ui components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@emotion/styled": "11.11.0",
|
|
26
26
|
"@mui/icons-material": "5.14.11",
|
|
27
27
|
"@mui/material": "5.14.11",
|
|
28
|
-
"@proteinjs/app-version-common": "^1.0
|
|
29
|
-
"@proteinjs/util": "1.
|
|
28
|
+
"@proteinjs/app-version-common": "^1.1.0",
|
|
29
|
+
"@proteinjs/util": "^1.6.0",
|
|
30
30
|
"react": "18.2.0",
|
|
31
31
|
"react-dom": "18.2.0",
|
|
32
32
|
"socket.io-client": "4.7.5"
|
|
@@ -45,5 +45,6 @@
|
|
|
45
45
|
"typescript": "5.2.2"
|
|
46
46
|
},
|
|
47
47
|
"main": "./dist/index.js",
|
|
48
|
-
"types": "./dist/index.d.ts"
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"gitHead": "49080ab46d73cfda8c5893e3964d7a594fa973ea"
|
|
49
50
|
}
|
|
@@ -3,6 +3,8 @@ import { getVersionCheckerService } from '@proteinjs/app-version-common';
|
|
|
3
3
|
import { Socket } from 'socket.io-client';
|
|
4
4
|
import { Debouncer } from '@proteinjs/util';
|
|
5
5
|
|
|
6
|
+
const VISIBILITY_CHANGE_THRESHOLD_MS = 30000;
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* A hook that exposes `needToUpdate`, which indicates whether or not the client's
|
|
8
10
|
* bundle is stale and the new version has been marked as significant enough to
|
|
@@ -12,6 +14,10 @@ import { Debouncer } from '@proteinjs/util';
|
|
|
12
14
|
* This hook will check with the server if the client should update when the socket
|
|
13
15
|
* receives a `connect` event.
|
|
14
16
|
*
|
|
17
|
+
* When `needToUpdate` is `true`, the hook will also automatically reload the page
|
|
18
|
+
* when the tab regains focus after being hidden for at least 30 seconds. This
|
|
19
|
+
* ensures background tabs pick up new versions without user interaction.
|
|
20
|
+
*
|
|
15
21
|
* Reason:
|
|
16
22
|
*
|
|
17
23
|
* When a new version is deployed, the server process will terminate. The socket will always
|
|
@@ -26,6 +32,7 @@ export const useVersionChecker = (currentVersion: string, socket: Socket | null)
|
|
|
26
32
|
const [needToUpdate, setNeedToUpdate] = useState(false);
|
|
27
33
|
const debouncerRef = useRef<Debouncer>(new Debouncer(1000));
|
|
28
34
|
const needToUpdateRef = useRef(needToUpdate); // having `needToUpdate` in the `checkVersion` dep array was causing double checks, despite debouncer
|
|
35
|
+
const hiddenAtRef = useRef<number | null>(null);
|
|
29
36
|
|
|
30
37
|
useEffect(() => {
|
|
31
38
|
needToUpdateRef.current = needToUpdate;
|
|
@@ -58,5 +65,31 @@ export const useVersionChecker = (currentVersion: string, socket: Socket | null)
|
|
|
58
65
|
};
|
|
59
66
|
}, [socket, checkVersion]);
|
|
60
67
|
|
|
68
|
+
// Auto-reload when the window regains focus after being blurred for 30s+.
|
|
69
|
+
// Uses window blur/focus rather than document visibilitychange so that
|
|
70
|
+
// switching to another desktop app (not just another browser tab) is detected.
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const handleBlur = () => {
|
|
73
|
+
hiddenAtRef.current = Date.now();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleFocus = () => {
|
|
77
|
+
if (
|
|
78
|
+
needToUpdateRef.current &&
|
|
79
|
+
hiddenAtRef.current &&
|
|
80
|
+
Date.now() - hiddenAtRef.current > VISIBILITY_CHANGE_THRESHOLD_MS
|
|
81
|
+
) {
|
|
82
|
+
window.location.reload();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
window.addEventListener('blur', handleBlur);
|
|
87
|
+
window.addEventListener('focus', handleFocus);
|
|
88
|
+
return () => {
|
|
89
|
+
window.removeEventListener('blur', handleBlur);
|
|
90
|
+
window.removeEventListener('focus', handleFocus);
|
|
91
|
+
};
|
|
92
|
+
}, []);
|
|
93
|
+
|
|
61
94
|
return { needToUpdate };
|
|
62
95
|
};
|