refactor: remove ElectronService and related files, updating DataFactory for environment checks

This commit is contained in:
4gray committed 2024-12-01 14:02:18 +01:00
1 parent 138e8a3027
commit 823212ad7b
4 files changed
-100

No files matched your search

-4
View File
@@ -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();
}
-12
View File
@@ -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();
});
});
-32
View File
@@ -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';
}
}
-52
View File
@@ -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';
}
}