From 823212ad7b5621cdafed45f21a6e3446715a287a Mon Sep 17 00:00:00 2001 From: 4gray Date: Sun, 1 Dec 2024 14:02:18 +0100 Subject: [PATCH] refactor: remove ElectronService and related files, updating DataFactory for environment checks --- src/app/app.module.ts | 4 -- src/app/services/electron.service.spec.ts | 12 ------ src/app/services/electron.service.stub.ts | 32 -------------- src/app/services/electron.service.ts | 52 ----------------------- 4 files changed, 100 deletions(-) delete mode 100644 src/app/services/electron.service.spec.ts delete mode 100644 src/app/services/electron.service.stub.ts delete mode 100644 src/app/services/electron.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e570de0ca..7642881f5 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,7 +23,6 @@ import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { dbConfig } from './indexed-db.config'; import { DataService } from './services/data.service'; -import { ElectronService } from './services/electron.service'; import { PwaService } from './services/pwa.service'; import { TauriService } from './services/tauri.service'; import { PlaylistEffects } from './state/effects'; @@ -49,9 +48,6 @@ function isTauri() { * Conditionally imports the necessary service based on the current environment */ export function DataFactory() { - if (isElectron()) { - return new ElectronService(); - } if (isTauri()) { return new TauriService(); } diff --git a/src/app/services/electron.service.spec.ts b/src/app/services/electron.service.spec.ts deleted file mode 100644 index 6e95b0af9..000000000 --- a/src/app/services/electron.service.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { ElectronService } from './electron.service'; - -describe('ElectronService', () => { - beforeEach(() => TestBed.configureTestingModule({})); - - it('should be created', () => { - const service: ElectronService = TestBed.get(ElectronService); - expect(service).toBeTruthy(); - }); -}); diff --git a/src/app/services/electron.service.stub.ts b/src/app/services/electron.service.stub.ts deleted file mode 100644 index eee603144..000000000 --- a/src/app/services/electron.service.stub.ts +++ /dev/null @@ -1,32 +0,0 @@ -export class ElectronServiceStub { - ipcRenderer = { - send: jest.fn(), - on: jest.fn(), - removeAllListeners: jest.fn(), - }; - remote = { - process: { - platform: 'linux', - argv: [0, 1], - }, - app: { - getVersion: jest.fn(() => '1.0.0'), - }, - }; - - isElectron = true; - - removeAllListeners(type: string) {} - - getAppVersion() { - return this.remote.app.getVersion(); - } - - sendIpcEvent() {} - - listenOn() {} - - getAppEnvironment() { - return 'electron'; - } -} diff --git a/src/app/services/electron.service.ts b/src/app/services/electron.service.ts deleted file mode 100644 index 8e73e9918..000000000 --- a/src/app/services/electron.service.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Injectable } from '@angular/core'; -import { DataService } from './data.service'; - -@Injectable({ - providedIn: 'root', -}) -export class ElectronService extends DataService { - /** - * Creates an instance of ElectronService. - */ - constructor() { - super(); - console.log('Electron service initialized...'); - } - - /** - * Returns the current version of the application - */ - getAppVersion(): string { - return this.remote.app.getVersion(); - } - - /** - * Sends an IPC event from render to the main process - * @param type event type - * @param payload data payload - */ - sendIpcEvent(type: string, payload?: unknown): void { - this.ipcRenderer.send(type, payload); - } - - /** - * Removes all IPC listeners - * @param type command name - */ - removeAllListeners(type: string): void { - this.ipcRenderer.removeAllListeners(type); - } - - /** - * Listens on an IPC event from the main process - * @param command command name - * @param callback callback function - */ - listenOn(command: string, callback: (...args: any[]) => void): void { - this.ipcRenderer.on(command, callback); - } - - getAppEnvironment(): string { - return 'electron'; - } -}