Skip to content

Commit

Permalink
feat(DisplayRequest): WASM support
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jun 27, 2020
1 parent 6dffb1a commit 91d3300
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/Uno.UI.Wasm/ts/Windows/System/Display/DisplayRequest.ts
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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.System.Display
{
#if false || false || NET461 || __WASM__ || false
#if false || false || NET461 || false || false
[global::Uno.NotImplemented]
#endif
public partial class DisplayRequest
{
#if false || false || NET461 || __WASM__ || false
#if false || false || NET461 || false || false
[global::Uno.NotImplemented]
public DisplayRequest()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.System.Display.DisplayRequest", "DisplayRequest.DisplayRequest()");
}
#endif
// Forced skipping of method Windows.System.Display.DisplayRequest.DisplayRequest()
#if false || false || NET461 || __WASM__ || false
#if false || false || NET461 || false || false
[global::Uno.NotImplemented]
public void RequestActive()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.System.Display.DisplayRequest", "void DisplayRequest.RequestActive()");
}
#endif
#if false || false || NET461 || __WASM__ || false
#if false || false || NET461 || false || false
[global::Uno.NotImplemented]
public void RequestRelease()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/System/Display/DisplayRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if __ANDROID__ || __IOS__ || __MACOS__
#if __ANDROID__ || __IOS__ || __MACOS__ || __WASM__
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
26 changes: 26 additions & 0 deletions src/Uno.UWP/System/Display/DisplayRequest.wasm.cs
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);
}
}
}

0 comments on commit 91d3300

Please sign in to comment.