diff --git a/package-lock.json b/package-lock.json index 01403c534..ea5db59fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7152,6 +7152,11 @@ "dragula": "^3.7.2" } }, + "ngx-electron": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/ngx-electron/-/ngx-electron-1.0.4.tgz", + "integrity": "sha512-dKSizgs6EUE5lvXq/kxQQSvrPEqamHlMje2xSTwUFHZq1krNjVPJv1mwnDPfVswI6gFheidLrV998F9aPbYRYg==" + }, "ngx-markdown": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/ngx-markdown/-/ngx-markdown-6.2.1.tgz", diff --git a/package.json b/package.json index a0b751374..45c2b1bd3 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "@ngx-formly/material": "^4.7.2", "core-js": "^2.5.4", "ng2-dragula": "^2.1.0", + "ngx-electron": "^1.0.4", "ngx-markdown": "^6.2.1", "rxjs": "^6.2.2", "rxjs-compat": "^6.2.2", diff --git a/src/app/app.constants.ts b/src/app/app.constants.ts index 4d8c26f10..f9caaafc1 100644 --- a/src/app/app.constants.ts +++ b/src/app/app.constants.ts @@ -1,3 +1,3 @@ export const LS_PREFIX = 'SUP_'; export const WORKLOG_DATE_STR_FORMAT = 'YYYY-MM-DD'; -export const IS_ELECTRON = (typeof window.ipcRenderer !== 'undefined'); +export const IS_ELECTRON = (navigator.userAgent.toLowerCase().indexOf(' electron/') > -1); diff --git a/src/app/issue/jira/jira-api.service.ts b/src/app/issue/jira/jira-api.service.ts index 9b7a3cb32..3a8dfe337 100644 --- a/src/app/issue/jira/jira-api.service.ts +++ b/src/app/issue/jira/jira-api.service.ts @@ -11,10 +11,10 @@ import { } from './jira.const'; import { ProjectService } from '../../project/project.service'; import { mapIssueResponse, mapIssuesResponse, mapResponse } from './jira-issue/jira-issue-map.util'; -import { IS_ELECTRON } from '../../app.constants'; import { JiraOriginalStatus, JiraOriginalUser } from './jira-api-responses'; import { JiraIssue } from './jira-issue/jira-issue.model'; import { JiraCfg } from './jira'; +import { ElectronService } from 'ngx-electron'; @Injectable({ @@ -26,15 +26,18 @@ export class JiraApiService { isExtension = false; cfg: any = {}; - constructor(private _chromeExtensionInterface: ChromeExtensionInterfaceService, - private _projectService: ProjectService) { + constructor( + private _chromeExtensionInterface: ChromeExtensionInterfaceService, + private _projectService: ProjectService, + private _electronService: ElectronService, + ) { this._projectService.currentJiraCfg$.subscribe((cfg) => { this.cfg = cfg; }); // set up callback listener for electron - if (IS_ELECTRON) { - window.ipcRenderer.on(IPC_JIRA_CB_EVENT, (ev, res) => { + if (this._electronService.isElectronApp) { + this._electronService.ipcRenderer.on(IPC_JIRA_CB_EVENT, (ev, res) => { this._handleResponse(res); }); } @@ -72,8 +75,6 @@ export class JiraApiService { } getCurrentUser(cfg?: JiraCfg): Promise { - console.log(cfg); - return this._sendRequest({ apiMethod: 'getCurrentUser', transform: mapResponse, @@ -96,8 +97,6 @@ export class JiraApiService { // TODO refactor data madness of request and add types for everything private _sendRequest(request, cfg = this.cfg): Promise { - console.log(cfg); - if (!this._isMinimalSettings(cfg)) { console.error('Not enough Jira settings. This should not happen!!!'); return Promise.reject(new Error('Insufficient Settings for Jira')); @@ -133,8 +132,8 @@ export class JiraApiService { }; // send to electron - if (IS_ELECTRON) { - window.ipcRenderer.send(IPC_JIRA_MAKE_REQUEST_EVENT, request); + if (this._electronService.isElectronApp) { + this._electronService.ipcRenderer.send(IPC_JIRA_MAKE_REQUEST_EVENT, request); } else if (this.isExtension) { this._chromeExtensionInterface.dispatchEvent('SP_JIRA_REQUEST', { requestId: request.requestId, diff --git a/src/app/issue/jira/jira.module.ts b/src/app/issue/jira/jira.module.ts index ae273ba52..bda932e06 100644 --- a/src/app/issue/jira/jira.module.ts +++ b/src/app/issue/jira/jira.module.ts @@ -3,12 +3,14 @@ import { CommonModule } from '@angular/common'; import { JiraCfgStepperComponent } from './jira-cfg-stepper/jira-cfg-stepper.component'; import { UiModule } from '../../ui/ui.module'; import { CoreModule } from '../../core/core.module'; +import { NgxElectronModule } from 'ngx-electron'; @NgModule({ imports: [ CommonModule, CoreModule, UiModule, + NgxElectronModule, ], declarations: [JiraCfgStepperComponent], exports: [JiraCfgStepperComponent],