-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wakeLockApi): button to prevent the screen lock (#1036)
* feat(wakeLockApi): button to prevent the screen lock * refactor(wakeLock): disable wakelock on blur for non supported browser * i18n(geo): typo * wip
- Loading branch information
Showing
17 changed files
with
149 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
igo-map-browser { | ||
width: 100%; | ||
height: 300px; | ||
height: 350px; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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 @@ | ||
export * from './wake-lock-button.component'; |
12 changes: 12 additions & 0 deletions
12
packages/geo/src/lib/map/wake-lock-button/wake-lock-button.component.html
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 @@ | ||
<div *ngIf="visible" class="igo-wake-lock-button-container"> | ||
<div> | ||
<button | ||
[color]="color" | ||
mat-icon-button | ||
[matTooltip]="enabled ? ('igo.geo.mapButtons.preventSreenLock' | translate): ('igo.geo.mapButtons.letScreenLock' | translate)" | ||
matTooltipPosition="left" | ||
(click)="toggleWakeLock()"> | ||
<mat-icon svgIcon="{{icon$ | async}}"></mat-icon> | ||
</button> | ||
</div> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
packages/geo/src/lib/map/wake-lock-button/wake-lock-button.component.scss
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,14 @@ | ||
@import '../../../../../core/src/style/partial/core.variables'; | ||
|
||
.igo-wake-lock-button-container { | ||
width: $igo-icon-size; | ||
background-color: #fff; | ||
&:hover { | ||
background-color: #efefef; | ||
} | ||
} | ||
|
||
button, | ||
:host ::ng-deep button .mat-button-ripple-round { | ||
border-radius: 0; | ||
} |
91 changes: 91 additions & 0 deletions
91
packages/geo/src/lib/map/wake-lock-button/wake-lock-button.component.ts
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,91 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { ConfigService, StorageService } from '@igo2/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import NoSleep from 'nosleep.js'; | ||
import { IgoMap } from '../shared/map'; | ||
import { userAgent } from '@igo2/utils'; | ||
|
||
@Component({ | ||
selector: 'igo-wake-lock-button', | ||
templateUrl: './wake-lock-button.component.html', | ||
styleUrls: ['./wake-lock-button.component.scss'] | ||
}) | ||
|
||
/** | ||
* Prevent display sleep and enable wake lock in all Android and iOS web browsers. | ||
* On iOS, the Wake Lock API is not supported | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API | ||
* On not supported browser, a fake video is used to keep the screen open. | ||
* | ||
* TODO: When the API will be supported by every browser, We should remove the NoSleep.js dependency | ||
* and replace it by a WakeLock API implementation. | ||
*/ | ||
export class WakeLockButtonComponent { | ||
|
||
@Input() color: string = 'primary'; | ||
@Input() map: IgoMap; | ||
@Input() | ||
get enabled(): boolean { | ||
return this.storageService.get('wakeLockEnabled') as boolean; | ||
} | ||
set enabled(value: boolean) { | ||
this.storageService.set('wakeLockEnabled', value); | ||
} | ||
|
||
private noSleep: NoSleep; | ||
readonly icon$: BehaviorSubject<string> = new BehaviorSubject('sleep'); | ||
public visible = false; | ||
|
||
constructor( | ||
private config: ConfigService, | ||
private storageService: StorageService | ||
) { | ||
this.visible = this.config.getConfig('wakeLockApiButton') ? true : false; | ||
this.noSleep = new NoSleep(); | ||
const nonWakeLockApiBrowser = userAgent.satisfies({ | ||
ie: '>0', | ||
edge: '<84', | ||
chrome: '<84', | ||
firefox: '>0', | ||
opera: '<70', | ||
safari: '>0' | ||
}); | ||
if (nonWakeLockApiBrowser) { | ||
this.disableWakeLock(); | ||
this.enabled = false; | ||
window.onblur = () => { | ||
this.disableWakeLock(); | ||
this.enabled = false; | ||
}; | ||
} | ||
this.enabled ? this.enableWakeLock() : this.disableWakeLock(); | ||
} | ||
|
||
/** | ||
* Prevent display sleep and enable wake lock in all Android and iOS web browsers. | ||
* On iOS, the Wake Lock API is not supported | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API | ||
* On not supported browser, a fake video is used to keep the screen open. | ||
*/ | ||
private enableWakeLock() { | ||
this.noSleep.enable(); | ||
this.enabled = true; | ||
this.icon$.next('sleep-off'); | ||
} | ||
/** | ||
* Let display sleep | ||
*/ | ||
private disableWakeLock() { | ||
this.noSleep.disable(); | ||
this.enabled = false; | ||
this.icon$.next('sleep'); | ||
} | ||
|
||
toggleWakeLock() { | ||
if (this.enabled) { | ||
this.disableWakeLock(); | ||
} else { | ||
this.enableWakeLock(); | ||
} | ||
} | ||
} |
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