Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorstenHans committed Jan 9, 2019
2 parents 732d8b3 + 325c9ed commit 48f4b78
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ Thumbs.db
Desktop.ini
# Mac crap
.DS_Store
dist
20 changes: 20 additions & 0 deletions projects/ngx-electron/src/lib/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ export class ElectronService {
return !!window.navigator.userAgent.match(/Electron/);
}

public get isMacOS(): boolean {
return this.isElectronApp && process.platform === 'darwin';
}

public get isWindows(): boolean {
return this.isElectronApp && process.platform === 'win32';
}

public get isLinux(): boolean {
return this.isElectronApp && process.platform === 'linux';
}

public get isX86(): boolean {
return this.isElectronApp && process.arch === 'ia32';
}

public get isX64(): boolean {
return this.isElectronApp && process.arch === 'x64';
}

public get desktopCapturer(): Electron.DesktopCapturer {
return this.electron ? this.electron.desktopCapturer : null;
}
Expand Down
8 changes: 4 additions & 4 deletions projects/ngx-electron/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NgModule } from '@angular/core';
import { ElectronService } from "./lib/electron.service";
import { ElectronServiceRef } from "./lib/electron.service.ref";
import { ElectronService } from './lib/electron.service';
import { ElectronServiceRef } from './lib/electron.service.ref';

export * from "./lib/electron.service";
export * from "./lib/electron.service.ref";
export * from './lib/electron.service';
export * from './lib/electron.service.ref';

@NgModule({
declarations: [],
Expand Down
236 changes: 232 additions & 4 deletions projects/ngx-electron/tests/electron.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Injector} from '@angular/core';
import {getTestBed, TestBed} from '@angular/core/testing';
import {} from 'jasmine';
import { Injector } from '@angular/core';
import { getTestBed, TestBed } from '@angular/core/testing';
import { } from 'jasmine';
import { ElectronService } from '../src/lib/electron.service';
import { NgxElectronModule } from '../src/public_api';
import { ElectronServiceRef } from '../src/lib/electron.service.ref';
Expand Down Expand Up @@ -65,6 +65,234 @@ describe('ElectronService', () => {
});
});

describe('isWindows', () => {

it('should provide isElectronApp as an instance-property', () => {
expect(_electronService).hasOwnProperty('isWindows');
});

it('should return a boolean', () => {
expect(typeof _electronService.isWindows).toEqual('boolean');
});


it('should return false if isElectronApp is false', () => {
expect(_electronService.isWindows).toBeFalsy();
});

it('should return true if running in electron', () => {
let originalPlatform = process.platform;
let originalUserAgent = navigator.userAgent;
(<any>navigator).__defineGetter__('userAgent', (): string => {
return 'foo Electron';
});
(<any>process).__defineGetter__('platform', (): string => {
return 'win32';
});

expect(_electronService.isWindows).toBeTruthy();

(<any>process).__defineGetter__('platform', (): string => {
return originalPlatform;
});

(<any>navigator).__defineGetter__('userAgent', (): string => {
return originalUserAgent;
});
});
});

describe('isLinux', () => {

it('should provide isLinux as an instance-property', () => {
expect(_electronService).hasOwnProperty('isLinux');
});

it('should return a boolean', () => {
expect(typeof _electronService.isLinux).toEqual('boolean');
});


it('should return false if isElectronApp is false', () => {
expect(_electronService.isLinux).toBeFalsy();
});

it('should return true if running in electron', () => {
let originalPlatform = process.platform;
let originalUserAgent = navigator.userAgent;
(<any>navigator).__defineGetter__('userAgent', (): string => {
return 'foo Electron';
});
(<any>process).__defineGetter__('platform', (): string => {
return 'linux';
});

expect(_electronService.isLinux).toBeTruthy();

(<any>process).__defineGetter__('platform', (): string => {
return originalPlatform;
});

(<any>navigator).__defineGetter__('userAgent', (): string => {
return originalUserAgent;
});
});
});

describe('isMacOS', () => {

it('should provide isMacOS as an instance-property', () => {
expect(_electronService).hasOwnProperty('isMacOS');
});

it('should return a boolean', () => {
expect(typeof _electronService.isMacOS).toEqual('boolean');
});


it('should return false if isElectronApp is false', () => {
expect(_electronService.isMacOS).toBeFalsy();
});

it('should return true if running in electron', () => {
let originalPlatform = process.platform;
let originalUserAgent = navigator.userAgent;
(<any>navigator).__defineGetter__('userAgent', (): string => {
return 'foo Electron';
});
(<any>process).__defineGetter__('platform', (): string => {
return 'darwin';
});

expect(_electronService.isMacOS).toBeTruthy();

(<any>process).__defineGetter__('platform', (): string => {
return originalPlatform;
});

(<any>navigator).__defineGetter__('userAgent', (): string => {
return originalUserAgent;
});
});
});

describe('isX86', () => {

it('should provide isX86 as an instance-property', () => {
expect(_electronService).hasOwnProperty('isX86');
});

it('should return a boolean', () => {
expect(typeof _electronService.isX86).toEqual('boolean');
});


it('should return false if isElectronApp is false', () => {
expect(_electronService.isX86).toBeFalsy();
});

it('should return true if running in electron with 32bit arch', () => {
let originalArch = process.arch;
let originalUserAgent = navigator.userAgent;
(<any>navigator).__defineGetter__('userAgent', (): string => {
return 'foo Electron';
});
(<any>process).__defineGetter__('arch', (): string => {
return 'ia32';
});

expect(_electronService.isX86).toBeTruthy();

(<any>process).__defineGetter__('arch', (): string => {
return originalArch;
});

(<any>navigator).__defineGetter__('userAgent', (): string => {
return originalUserAgent;
});
});

it('should return false if running in electron with x64 arch', () => {
let originalArch = process.arch;
let originalUserAgent = navigator.userAgent;
(<any>navigator).__defineGetter__('userAgent', (): string => {
return 'foo Electron';
});
(<any>process).__defineGetter__('arch', (): string => {
return 'x64';
});

expect(_electronService.isX86).toBeFalsy();

(<any>process).__defineGetter__('arch', (): string => {
return originalArch;
});

(<any>navigator).__defineGetter__('userAgent', (): string => {
return originalUserAgent;
});
});
});

describe('isX64', () => {

it('should provide isX64 as an instance-property', () => {
expect(_electronService).hasOwnProperty('isX64');
});

it('should return a boolean', () => {
expect(typeof _electronService.isX64).toEqual('boolean');
});


it('should return false if isElectronApp is false', () => {
expect(_electronService.isX64).toBeFalsy();
});

it('should return true if running in electron with x64 arch', () => {
let originalArch = process.arch;
let originalUserAgent = navigator.userAgent;
(<any>navigator).__defineGetter__('userAgent', (): string => {
return 'foo Electron';
});
(<any>process).__defineGetter__('arch', (): string => {
return 'x64';
});

expect(_electronService.isX64).toBeTruthy();

(<any>process).__defineGetter__('arch', (): string => {
return originalArch;
});

(<any>navigator).__defineGetter__('userAgent', (): string => {
return originalUserAgent;
});
});

it('should return false if running in electron with 32bit arch', () => {
let originalArch = process.arch;
let originalUserAgent = navigator.userAgent;
(<any>navigator).__defineGetter__('userAgent', (): string => {
return 'foo Electron';
});
(<any>process).__defineGetter__('arch', (): string => {
return 'ia32';
});

expect(_electronService.isX64).toBeFalsy();

(<any>process).__defineGetter__('arch', (): string => {
return originalArch;
});

(<any>navigator).__defineGetter__('userAgent', (): string => {
return originalUserAgent;
});
});

});

describe('api', () => {

it('should expose desktopCapturer', () => {
Expand Down Expand Up @@ -108,7 +336,7 @@ describe('ElectronService', () => {
});

it('should expose nativeImage', () => {
expect(_electronService.hasOwnProperty('nativeImage'));
expect(_electronService.hasOwnProperty('nativeImage'));
});

});
Expand Down

0 comments on commit 48f4b78

Please sign in to comment.