Skip to content

Commit c0df862

Browse files
North McCormickjgw96
authored andcommitted
feat(platform): add electron as a platform (#10868)
* feat(platform): add the handler electron platform ready * + Added UA test * (fix)platform: add core superset to electron definition
1 parent e423e08 commit c0df862

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/platform/platform-registry.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { OpaqueToken } from '@angular/core';
22

33
import { Platform, PlatformConfig } from './platform';
4-
import { isCordova, isIos, isIosUIWebView } from './platform-utils';
4+
import { isCordova, isElectron, isIos, isIosUIWebView } from './platform-utils';
55

66

77
export const PLATFORM_CONFIGS: { [key: string]: PlatformConfig } = {
@@ -219,6 +219,24 @@ export const PLATFORM_CONFIGS: { [key: string]: PlatformConfig } = {
219219
isMatch(plt: Platform): boolean {
220220
return isCordova(plt);
221221
}
222+
},
223+
224+
/**
225+
* electron
226+
*/
227+
'electron': {
228+
superset: 'core',
229+
initialize: function(plt: Platform) {
230+
plt.prepareReady = function() {
231+
// 1) ionic bootstrapped
232+
plt.windowLoad(function() {
233+
plt.triggerReady('electron');
234+
});
235+
};
236+
},
237+
isMatch(plt: Platform): boolean {
238+
return isElectron(plt);
239+
}
222240
}
223241
};
224242

src/platform/platform-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export function isCordova(plt: Platform): boolean {
66
return !!(win['cordova'] || win['PhoneGap'] || win['phonegap']);
77
}
88

9+
export function isElectron(plt: Platform): boolean {
10+
return plt.testUserAgent('Electron');
11+
}
12+
913
export function isIos(plt: Platform): boolean {
1014
// shortcut function to be reused internally
1115
// checks navigator.platform to see if it's an actual iOS device

src/platform/test/platform.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,22 @@ describe('Platform', () => {
444444
expect(plt.is('tablet')).toEqual(true);
445445
});
446446

447+
it('should set electron via user agent', () => {
448+
plt.setQueryParams('');
449+
plt.setDefault('core');
450+
plt.setUserAgent(OSX_10_ELECTRON_1_4_15_UA);
451+
plt.init();
452+
453+
expect(plt.is('core')).toEqual(false);
454+
expect(plt.is('mobile')).toEqual(false);
455+
expect(plt.is('windows')).toEqual(false);
456+
expect(plt.is('android')).toEqual(false);
457+
expect(plt.is('ios')).toEqual(false);
458+
expect(plt.is('ipad')).toEqual(false);
459+
expect(plt.is('tablet')).toEqual(false);
460+
expect(plt.is('electron')).toEqual(true);
461+
})
462+
447463
it('should set core platform for osx desktop firefox', () => {
448464
plt.setQueryParams('');
449465
plt.setDefault('core');
@@ -549,6 +565,7 @@ describe('Platform', () => {
549565
const OSX_10_FIREFOX_43_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0';
550566
const OSX_10_SAFARI_9_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4';
551567
const OSX_10_CHROME_49_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36';
568+
const OSX_10_ELECTRON_1_4_15_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) ionic-hello-world/1.4.15 Chrome/53.0.2785.143 Electron/1.4.15 Safari/537.36';
552569

553570
const WINDOWS_10_CHROME_40_UA = 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36';
554571
const WINDOWS_10_EDGE_12_UA = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
@@ -564,4 +581,4 @@ const ANDROID_7_1_1_UA = 'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26
564581
const IPHONE_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4';
565582
const IPHONE_10_2_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Mobile/14C89 (140564782665216)';
566583
const IPAD_UA = 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53';
567-
const IPAD_10_2_UA = 'Mozilla/5.0 (iPad; CPU OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Mobile/14C89 (140342232906320)';
584+
const IPAD_10_2_UA = 'Mozilla/5.0 (iPad; CPU OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Mobile/14C89 (140342232906320)';

0 commit comments

Comments
 (0)