mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[chore] remove unused functions
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import path from "path";
|
||||
import { app, BrowserWindow } from "electron";
|
||||
import { IpcResponse } from "shared/models/ipc";
|
||||
import log from "electron-log";
|
||||
import { app } from "electron";
|
||||
|
||||
// TODO : REFACTOR
|
||||
|
||||
@@ -44,12 +42,4 @@ export class UtilsService {
|
||||
public getBuildPath(filepath: string): string {
|
||||
return path.join(this.buildPath, filepath);
|
||||
}
|
||||
|
||||
public ipcSend<T = unknown>(channel: string, response: IpcResponse<T>): void {
|
||||
try {
|
||||
BrowserWindow.getAllWindows().forEach(window => window?.webContents?.send(channel, response));
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { defaultIfEmpty, share } from "rxjs/operators";
|
||||
import { Observable, ReplaySubject, identity } from "rxjs";
|
||||
import { IpcRequest, IpcResponse } from "shared/models/ipc";
|
||||
import { IpcRequest } from "shared/models/ipc";
|
||||
import { deserializeError } from 'serialize-error';
|
||||
import { IpcCompleteChannel, IpcErrorChannel, IpcTearDownChannel } from "shared/models/ipc/ipc-response.interface";
|
||||
import { IpcChannels, IpcRequestType, IpcResponseType } from "shared/models/ipc/ipc-routes";
|
||||
@@ -8,8 +8,6 @@ import { IpcChannels, IpcRequestType, IpcResponseType } from "shared/models/ipc/
|
||||
export class IpcService {
|
||||
private static instance: IpcService;
|
||||
|
||||
private readonly channelObservables: Map<string, Observable<unknown>>;
|
||||
|
||||
public static getInstance(): IpcService {
|
||||
if (!IpcService.instance) {
|
||||
IpcService.instance = new IpcService();
|
||||
@@ -17,53 +15,12 @@ export class IpcService {
|
||||
return IpcService.instance;
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
this.channelObservables = new Map<string, Observable<IpcResponse<unknown>>>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use sendV2 instead
|
||||
*/
|
||||
public send<T, U = unknown>(channel: string, request?: IpcRequest<U>): Promise<IpcResponse<T>> {
|
||||
if (!request) {
|
||||
request = { args: null, responceChannel: null };
|
||||
}
|
||||
if (!request.responceChannel) {
|
||||
request.responceChannel = `${channel}_responce_${new Date().getTime()}`;
|
||||
}
|
||||
|
||||
const promise = new Promise<IpcResponse<T>>(resolve => {
|
||||
window.electron.ipcRenderer.once(request.responceChannel, (response: IpcResponse<T>) => resolve(response));
|
||||
});
|
||||
|
||||
window.electron.ipcRenderer.sendMessage(channel, request);
|
||||
|
||||
return promise;
|
||||
}
|
||||
private constructor() {}
|
||||
|
||||
public sendLazy<T = unknown>(channel: string, request?: IpcRequest<T>): void {
|
||||
window.electron.ipcRenderer.sendMessage(channel, request);
|
||||
}
|
||||
|
||||
// Also need a rework
|
||||
public watch<T>(channel: string): Observable<T> {
|
||||
if (this.channelObservables.has(channel)) {
|
||||
return this.channelObservables.get(channel) as Observable<T>;
|
||||
}
|
||||
|
||||
const obs = new Observable<T>(observer => {
|
||||
window.electron.ipcRenderer.on(channel, (res) => {
|
||||
observer.next(res);
|
||||
});
|
||||
});
|
||||
|
||||
this.channelObservables.set(channel, obs);
|
||||
|
||||
return obs;
|
||||
}
|
||||
|
||||
// TODO : Convert all IPCs calls to V2
|
||||
|
||||
public sendV2<C extends IpcChannels>(channel: C, data?: IpcRequestType<C>, defaultValue?: IpcResponseType<C>): Observable<IpcResponseType<C>> {
|
||||
|
||||
const request: IpcRequest<IpcRequestType<C>> = {
|
||||
|
||||
Reference in New Issue
Block a user