Skip to content

Commit

Permalink
feat(tsconfig): update paths and throwError
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonatanMedeiros committed May 24, 2020
1 parent d67ddd6 commit 8360704
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/app/core/core-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Routes, RouterModule } from '@angular/router';

// Components Imports
import { CoreComponent } from './core.component';
import { ManageAppListComponent } from '@app/core/pages';
import { ManageAppListComponent } from '@core/pages';

const routes: Routes = [
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { DataTableModule } from '@projects/data-table';

// Components Imports
import { CoreComponent } from './core.component';
import { ManageAppListComponent } from '@app/core/pages';
import { ManageAppListComponent } from '@core/pages';
import { ModalFormAppComponent } from './components';

// Services Imports
import { ManageAppService } from '@app/core/services';
import { ManageAppService } from '@core/services';

@NgModule({
declarations: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ export class ManageAppListComponent implements OnInit, OnDestroy {
}

private openUrl(url: string): void {
this.electronService.ipcRenderer.invoke('url-channel', { url })
.then((result) => {
console.log(result);
});
this.manageAppService.openManageAPP(url)
.pipe(takeUntil(this.ngUnSubscribe))
.subscribe();
}

private openModal(item?: IManageApp): void {
Expand Down
73 changes: 42 additions & 31 deletions src/app/core/services/manage-app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,85 @@ import { Injectable } from '@angular/core';
import { IpcRenderer } from 'electron';

// External Libs
import { Observable, of } from 'rxjs';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';

// Models Imports
import { IManageApp } from '@app/core/models';

// Services Imports
import { ElectronService } from '@app/services';

// DB Keys Imports
import { __STORE_KEY_CREATE__, __STORE_KEY_DELETE__, __STORE_KEY_LIST__, __STORE_KEY_UPDATE__ } from '../../../../main-process/store/keys';

@Injectable()
export class ManageAppService {

private ipcRenderer: IpcRenderer;
private readonly ipcRenderer: IpcRenderer;

constructor(private electronService: ElectronService) {
this.ipcRenderer = this.electronService.ipcRenderer;
console.log('[ipcRenderer]', this.ipcRenderer);
}

list(): Observable<IManageApp[]> {
return new Observable<IManageApp[]>((obs) => {
this.ipcRenderer.invoke(__STORE_KEY_LIST__, null)
.then((result) => {
obs.next(result);
})
.catch(reason => {
obs.error(reason);
})
.then((result) => obs.next(result))
.catch(reason => obs.error(reason))
.finally(() => obs.complete());
});
}).pipe(catchError(this.handleError));
}

create(manageApp: IManageApp): Observable<IManageApp> {
return new Observable<IManageApp>((obs) => {
this.ipcRenderer.invoke(__STORE_KEY_CREATE__, manageApp)
.then((result) => {
obs.next(result);
})
.catch(reason => {
obs.error(reason);
})
.then((result) => obs.next(result))
.catch(reason => obs.error(reason))
.finally(() => obs.complete());
});
}).pipe(catchError(this.handleError));
}

update(manageApp: IManageApp): Observable<IManageApp> {
return new Observable<IManageApp>((obs) => {
this.ipcRenderer.invoke(__STORE_KEY_UPDATE__, manageApp)
.then((result) => {
obs.next(result);
})
.catch(reason => {
obs.error(reason);
})
.then((result) => obs.next(result))
.catch(reason => obs.error(reason))
.finally(() => obs.complete());
});
}).pipe(catchError(this.handleError));
}

delete(id: string): Observable<IManageApp> {
return new Observable<IManageApp>((obs) => {
this.ipcRenderer.invoke(__STORE_KEY_DELETE__, id)
.then((result) => {
obs.next(result);
})
.catch(reason => {
obs.error(reason);
})
.then((result) => obs.next(result))
.catch(reason => obs.error(reason))
.finally(() => obs.complete());
}).pipe(catchError(this.handleError));
}

openManageAPP(url: string): Observable<any> {
return new Observable<any>((obs) => {
this.ipcRenderer.invoke('url-channel', { url })
.then((result) => obs.next(result))
.finally(() => obs.complete());
});
}).pipe(catchError(this.handleError));
}

private handleError(error): Observable<any> {
const isElectron = (this.electronService && this.electronService.isElectron);

let errorMessage = '';
if (!isElectron) {
errorMessage = 'Error: Not Electron APP';
} else if (error.error instanceof ErrorEvent) {
// client-side error
errorMessage = `Error: ${error.error.message}`;
} else {
// server-side error
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
}

return throwError(errorMessage);
}
}
7 changes: 5 additions & 2 deletions src/app/services/electron.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Angular Imports
import { Injectable } from '@angular/core';
// If you import a module but never use any of the imported values other than as TypeScript types,
// the resulting javascript file will look as if you never imported the module at all.

// Electron Import
import { IpcRenderer, WebFrame, Remote } from 'electron';

// External Imports
import { ChildProcess } from 'child_process';
import * as fs from 'fs';

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"paths": {
"@projects/*": ["./projects/*"],
"@data-table/*": ["./projects/data-table/*"],
"@app/*": ["./src/app/*"]
"@app/*": ["./src/app/*"],
"@services/*": ["./src/app/services/*"],
"@core/*": ["./src/app/core/*"]
}
},
"angularCompilerOptions": {
Expand Down

0 comments on commit 8360704

Please sign in to comment.