Skip to content

Commit 6c0f22a

Browse files
committed
feat(user): implement lazy loading for user module
Added lazy loading functionality to the UserModule, enabling initialization on demand. Updated IPC hooks to handle user initialization and send user data accordingly. Updated package version and dependencies to support new features.
1 parent d9dc548 commit 6c0f22a

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "electron-modular-boilerplate",
33
"private": true,
4-
"version": "0.1.6",
4+
"version": "1.0.0",
55
"type": "module",
66
"main": "dist-main/app.js",
77
"author": "traeop",
@@ -30,7 +30,7 @@
3030
"build:linux:publish": "npm run transpile:electron && npm run build && electron-builder --publish always --linux --x64"
3131
},
3232
"dependencies": {
33-
"@devisfuture/electron-modular": "^1.1.11",
33+
"@devisfuture/electron-modular": "^1.2.20",
3434
"axios": "^1.10.0",
3535
"clsx": "^2.1.1",
3636
"compare-versions": "^6.1.1",
@@ -46,6 +46,7 @@
4646
"react-router-dom": "^7.4.1",
4747
"react-virtualized-auto-sizer": "^2.0.2",
4848
"react-window": "^2.2.4",
49+
"reflect-metadata": "^0.2.2",
4950
"tailwind-merge": "^3.4.0"
5051
},
5152
"devDependencies": {

src/main/user/module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ import type { TAuthProvider, TUserRestApiProvider } from "./types.js";
3131
inject: [AuthService],
3232
},
3333
],
34+
lazy: {
35+
enabled: true,
36+
trigger: "init-user-lazy",
37+
},
3438
})
3539
export class UserModule {}

src/renderer/conceptions/User/hooks/useIpc.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import { useEffect } from "react";
1+
import { useCallback, useEffect } from "react";
22

33
import { useSetUserDispatch } from "../context/useSelectors";
44

55
export const useIpc = () => {
66
const setUser = useSetUserDispatch();
77

8-
useEffect(() => {
9-
window.electron.send("user");
8+
const initUserModule = useCallback(async (successfulCallback: () => void) => {
9+
const data = await window.electron.invoke("init-user-lazy");
10+
const { initialized, error } = data;
11+
12+
if (initialized && error === undefined) {
13+
successfulCallback();
14+
}
1015
}, []);
1116

1217
useEffect(() => {
18+
initUserModule(() => {
19+
window.electron.send("user");
20+
});
21+
}, [initUserModule]);
22+
23+
useEffect(() => {
24+
window.electron.send("user");
25+
1326
const unSub = window.electron.receive("user", (data) => {
1427
if (data === undefined) {
1528
return;

types/invokes.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
type TEventPayloadInvoke = {
22
getVersion: string;
3+
"init-user-lazy": TInitDataLazy;
34
confirmData?: {
45
success: boolean;
56
};
67
};
78

89
type TEventSendInvoke = {
910
getVersion: string;
11+
"init-user-lazy": undefined;
1012
confirmData: {
1113
message: string;
1214
};

types/lazy.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type TInitDataLazy = {
2+
initialized: boolean;
3+
name: string;
4+
error?: {
5+
message: string;
6+
};
7+
};

0 commit comments

Comments
 (0)