refactor(service): integrate Service Worker Controller initialization into Services class, enhancing service setup and clarity

This commit is contained in:
NicolasCantu 2025-12-03 20:20:18 +01:00
parent 0ae251a1bd
commit 633fd57793

View File

@ -13,6 +13,7 @@ import { BackUp } from "../types/index";
import { APP_CONFIG } from "../config/constants"; import { APP_CONFIG } from "../config/constants";
import { NetworkService } from "./core/network.service"; import { NetworkService } from "./core/network.service";
import type { CoreBackend } from "../workers/core.worker"; import type { CoreBackend } from "../workers/core.worker";
import { SWController } from "./sw-controller.service";
import Database from "./database.service"; import Database from "./database.service";
export default class Services { export default class Services {
@ -55,21 +56,27 @@ export default class Services {
// 1. Initialiser le Core Worker // 1. Initialiser le Core Worker
await this.coreWorker.init(); await this.coreWorker.init();
// 2. Initialiser la Database ici (Main Thread) pour lancer le SW
// 2. Initialiser la Database (Main Thread)
await Database.getInstance(); await Database.getInstance();
// 3. Configurer les Callbacks (Le worker pilote le main thread pour le réseau)
// 3. Initialiser le Service Worker Controller
const swController = await SWController.getInstance();
await swController.init();
// 4. Configurer les Callbacks
await this.coreWorker.setCallbacks( await this.coreWorker.setCallbacks(
Comlink.proxy(this.handleWorkerNotification.bind(this)), // notifier Comlink.proxy(this.handleWorkerNotification.bind(this)),
Comlink.proxy(this.handleWorkerNetworkSend.bind(this)), // networkSender Comlink.proxy(this.handleWorkerNetworkSend.bind(this)),
Comlink.proxy(this.handleWorkerRelayUpdate.bind(this)), // relayUpdater Comlink.proxy(this.handleWorkerRelayUpdate.bind(this)),
Comlink.proxy(this.handleWorkerRelayRequest.bind(this)) // relayGetter Comlink.proxy(this.handleWorkerRelayRequest.bind(this))
); );
// 3. Initialiser le Réseau (Network Worker via Proxy) // 5. Initialiser le Réseau
await this.networkService.initRelays(); await this.networkService.initRelays();
console.log( console.log(
"[Services] ✅ Proxy connecté au CoreWorker et NetworkService." "[Services] ✅ Proxy connecté au CoreWorker, SWController et NetworkService."
); );
} }