-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dffb1a
commit 91d3300
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/Uno.UI.Wasm/ts/Windows/System/Display/DisplayRequest.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,33 @@ | ||
interface Navigator { | ||
wakeLock : WakeLock; | ||
} | ||
|
||
enum WakeLockType { "screen" }; | ||
|
||
interface WakeLock { | ||
request(type: WakeLockType): Promise<WakeLockSentinel>; | ||
}; | ||
|
||
interface WakeLockSentinel { | ||
release(): Promise<void>; | ||
}; | ||
|
||
namespace Windows.System.Display { | ||
|
||
export class DisplayRequest { | ||
private static activeScreenLockPromise: Promise<WakeLockSentinel>; | ||
|
||
public static activateScreenLock() { | ||
if (navigator.wakeLock) { | ||
DisplayRequest.activeScreenLockPromise = navigator.wakeLock.request(WakeLockType.screen); | ||
} | ||
} | ||
|
||
public static deactivateScreenLock() { | ||
if (DisplayRequest.activeScreenLockPromise) { | ||
DisplayRequest.activeScreenLockPromise.then(sentinel => sentinel.release()); | ||
DisplayRequest.activeScreenLockPromise = null; | ||
} | ||
} | ||
} | ||
} |
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,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Uno.Foundation; | ||
|
||
namespace Windows.System.Display | ||
{ | ||
public partial class DisplayRequest | ||
{ | ||
private const string JsType = "Windows.System.Display.DisplayRequest"; | ||
|
||
partial void ActivateScreenLock() | ||
{ | ||
var command = $"{JsType}.activateScreenLock()"; | ||
WebAssemblyRuntime.InvokeJS(command); | ||
} | ||
|
||
partial void DeactivateScreenLock() | ||
{ | ||
var command = $"{JsType}.deactivateScreenLock()"; | ||
WebAssemblyRuntime.InvokeJS(command); | ||
} | ||
} | ||
} |