Fix bug where Services instance seemed to get dropped
This commit is contained in:
parent
9f45b2c788
commit
8d745693b7
@ -1,8 +1,5 @@
|
||||
import Services from './services/service';
|
||||
// import { WebSocketClient } from './websockets';
|
||||
|
||||
// const wsurl = `ws://74.234.68.175:8091`;
|
||||
const wsurl = `wss://localhost/ws/`;
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
try {
|
||||
|
||||
@ -14,7 +11,6 @@ try {
|
||||
} else {
|
||||
await services.restoreDevice(device)
|
||||
}
|
||||
await services.addWebsocketConnection(wsurl);
|
||||
await services.recoverInjectHtml();
|
||||
await services.restoreProcesses();
|
||||
await services.restoreMessages();
|
||||
|
@ -17,8 +17,10 @@ type ProcessesCache = {
|
||||
};
|
||||
|
||||
const U32_MAX = 4294967295;
|
||||
const wsurl = `ws://localhost:8090`;
|
||||
|
||||
export default class Services {
|
||||
private static initializing: Promise<Services> | null = null;
|
||||
private static instance: Services;
|
||||
private current_process: string | null = null;
|
||||
private sdkClient: any;
|
||||
@ -32,25 +34,35 @@ export default class Services {
|
||||
|
||||
// Method to access the singleton instance of Services
|
||||
public static async getInstance(): Promise<Services> {
|
||||
if (!Services.instance) {
|
||||
Services.instance = new Services();
|
||||
await Services.instance.init();
|
||||
if (Services.instance) {
|
||||
return Services.instance;
|
||||
}
|
||||
|
||||
if (!Services.initializing) {
|
||||
Services.initializing = (async () => {
|
||||
const instance = new Services();
|
||||
await instance.init();
|
||||
return instance;
|
||||
})();
|
||||
}
|
||||
|
||||
Services.instance = await Services.initializing;
|
||||
Services.initializing = null; // Reset for potential future use
|
||||
return Services.instance;
|
||||
}
|
||||
|
||||
public async init(): Promise<void> {
|
||||
this.notifications = this.getNotifications();
|
||||
this.sdkClient = await import("../../dist/pkg/sdk_client");
|
||||
// this.database = Database.getInstance()
|
||||
await this.addWebsocketConnection(wsurl);
|
||||
}
|
||||
|
||||
|
||||
public async addWebsocketConnection(url: string): Promise<void> {
|
||||
const services = await Services.getInstance();
|
||||
const newClient = new WebSocketClient(url, services);
|
||||
if (!services.websocketConnection) {
|
||||
services.websocketConnection = newClient;
|
||||
// const services = await Services.getInstance();
|
||||
if (!this.websocketConnection) {
|
||||
console.log('Opening new websocket connection');
|
||||
const newClient = new WebSocketClient(url, this);
|
||||
this.websocketConnection = newClient;
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,9 +85,6 @@ export default class Services {
|
||||
if(btn) {
|
||||
this.addSubscription(btn, 'click', 'injectProcessListPage')
|
||||
}
|
||||
// const url = location.href
|
||||
|
||||
const services = await Services.getInstance();
|
||||
const localAddress = await this.getDeviceAddress();
|
||||
|
||||
this.generateQRCode(localAddress || '')
|
||||
|
Loading…
x
Reference in New Issue
Block a user