-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): using Inject(WINDOW) and new ServiceWorker
- Loading branch information
Showing
24 changed files
with
1,131 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"port": 4200 | ||
"port": 4200, | ||
"files": ["dist/apps/webapp/*.{html,htm,css,js,json,png}"], | ||
"server": { "baseDir": "dist/apps/webapp" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { FeatureService } from './feature.service'; | ||
|
||
describe('FeatureService', () => { | ||
beforeEach(() => TestBed.configureTestingModule({})); | ||
|
||
it('should be created', () => { | ||
const service: FeatureService = TestBed.get(FeatureService); | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { WINDOW } from './window.token'; | ||
|
||
export enum BrowserFeatureKey { | ||
ServiceWorker = 'Service Worker', | ||
Cache = 'Offline Capabilities', | ||
PushAPI = 'Push data', | ||
NotificationsAPI = 'Notifications', | ||
BeforeInstallPromptEvent = 'Add to Homescreen', | ||
BackgroundSync = 'Background sync', | ||
NavigationPreloadManager = 'Navigation Preload', | ||
BudgetAPI = 'Budget API', | ||
StorageEstimation = 'Storage Estimation', | ||
PersistentStorage = 'Persistent Storage', | ||
WebShareAPI = 'Web Share', | ||
MediaSessionAPI = 'Media Session', | ||
MediaCapabilities = 'Media Capabilities', | ||
DeviceMemory = 'Device Memory', | ||
RelatedApps = 'Getting Installed Related Apps', | ||
PaymentRequestAPI = 'Payment Request', | ||
CredentialManagement = 'Credential Management', | ||
WebBluetoothAPI = 'Web Bluetooth', | ||
SpeechSynthesis = 'Speech Synthesis', | ||
SpeechRecognition = 'Speech Recognition', | ||
} | ||
|
||
export class BrowserFeature { | ||
constructor(public key: string, public supported: boolean) {} | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class FeatureService { | ||
private readonly navigator: Navigator; | ||
private readonly features: any; | ||
|
||
constructor(@Inject(WINDOW) private window: Window) { | ||
this.navigator = this.window.navigator; | ||
|
||
this.features = { | ||
[BrowserFeatureKey.ServiceWorker]: 'serviceWorker' in this.window.navigator, | ||
[BrowserFeatureKey.Cache]: 'caches' in this.window, | ||
[BrowserFeatureKey.PushAPI]: 'PushManager' in this.window, | ||
[BrowserFeatureKey.NotificationsAPI]: 'Notification' in this.window, | ||
[BrowserFeatureKey.BeforeInstallPromptEvent]: 'BeforeInstallPromptEvent' in this.window, | ||
[BrowserFeatureKey.BackgroundSync]: 'SyncManager' in this.window, | ||
[BrowserFeatureKey.NavigationPreloadManager]: 'NavigationPreloadManager' in this.window, | ||
[BrowserFeatureKey.BudgetAPI]: 'budget' in this.navigator && 'reserve' in (<any>this.navigator).budget, | ||
[BrowserFeatureKey.StorageEstimation]: 'storage' in this.navigator && 'estimate' in (<any>this.navigator).storage, | ||
[BrowserFeatureKey.PersistentStorage]: 'storage' in this.navigator && 'persist' in (<any>this.navigator).storage, | ||
[BrowserFeatureKey.WebShareAPI]: 'share' in this.navigator, | ||
[BrowserFeatureKey.MediaSessionAPI]: 'mediaSession' in this.navigator, | ||
[BrowserFeatureKey.MediaCapabilities]: 'mediaCapabilities' in this.navigator, | ||
[BrowserFeatureKey.DeviceMemory]: 'deviceMemory' in this.navigator, | ||
[BrowserFeatureKey.RelatedApps]: 'getInstalledRelatedApps' in this.navigator, | ||
[BrowserFeatureKey.PaymentRequestAPI]: 'PaymentRequest' in this.window, | ||
[BrowserFeatureKey.CredentialManagement]: 'credentials' in this.navigator, | ||
[BrowserFeatureKey.WebBluetoothAPI]: 'bluetooth' in this.navigator, | ||
[BrowserFeatureKey.SpeechSynthesis]: 'speechSynthesis' in this.window, | ||
[BrowserFeatureKey.SpeechRecognition]: | ||
'webkitSpeechRecognition' in this.window || | ||
'mozSpeechRecognition' in this.window || | ||
'msSpeechRecognition' in this.window || | ||
'oSpeechRecognition' in this.window, | ||
}; | ||
} | ||
|
||
detectFeatures(): Array<BrowserFeature> { | ||
return Object.keys(this.features).map(key => new BrowserFeature(key, this.features[key])); | ||
} | ||
|
||
detectFeature(feature: BrowserFeatureKey): BrowserFeature { | ||
return new BrowserFeature(feature, this.features[feature]); | ||
} | ||
|
||
isMobileAndroid(): boolean { | ||
return this.window.navigator.userAgent.toLowerCase().indexOf('android') > -1; | ||
} | ||
} |
Oops, something went wrong.