-
Notifications
You must be signed in to change notification settings - Fork 76
fix: add support for non-root base-href #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
holzgeist
wants to merge
23
commits into
fluttercommunity:main
Choose a base branch
from
holzgeist:fix-support-non-root-base-href
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8892812
fix: add support for non-root base-href
holzgeist 31526ae
Moved no_sleep.js to lib/assets.
diegotori 606ade6
Added web alias to all package:web calls in import_js_library.dart.
diegotori b4114a9
Added more simplified library URL method in import_js_library.dart.
diegotori e948054
WakelockPlusWebPlugin now lazily loads no_sleep.js on demand as oppos…
diegotori 9e1fd5b
Got the WakelockPlusWebPlugin tests passing.
diegotori 39f6598
Fixed example app web-related depreactions.
diegotori f2542bd
Added straggler from previous commit.
diegotori b8d0b58
Added correct script tag error handling by checking if the target is …
diegotori bd3e7a7
Upgraded flutter_lints to latest version.
diegotori 4900aaf
Revamped the no_sleep.js script to use a Promise-based Completer so t…
diegotori ac4e069
Fixed a dart lint issue due to HTML in the documentation of _importJS…
diegotori a7ddb22
Added minor comments to no_sleep.js.
diegotori 897dca4
Merge branch 'main' into fix-support-non-root-base-href
diegotori f5d5bc4
Fixed a pubspec straggler from the previous commit.
diegotori 8f38c22
Update wakelock_plus/lib/assets/no_sleep.js due to typo
diegotori bb3d4ca
chore: apply suggestions
holzgeist be5d5f5
Merge branch 'main' into fix-support-non-root-base-href
diegotori bb5d60d
Moved no_sleep.js copyright notice to the top of the file.
diegotori 12cd725
fix: don't perform any work after completing future
holzgeist 8f1ed7a
Merge branch 'main' into fix-support-non-root-base-href
diegotori 3886996
Merge branch 'main' into fix-support-non-root-base-href
diegotori 27f6d07
Merge branch 'main' into fix-support-non-root-base-href
diegotori File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
holzgeist marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,30 @@ | ||
| class PromiseCompleter { | ||
| _promise; | ||
| _resolve; | ||
| _reject; | ||
| constructor() { | ||
| this._promise = new Promise((resolve, reject) => { | ||
| this._resolve = resolve; | ||
| this._reject = reject; | ||
| }); | ||
| } | ||
|
|
||
| isCompleted = false; | ||
|
|
||
| get future() { | ||
| return this._promise; | ||
| } | ||
|
|
||
| complete(value) { | ||
| this.isCompleted = true; | ||
| this._resolve(value); | ||
| } | ||
|
|
||
| completeError(error) { | ||
| this._reject(error); | ||
| } | ||
| } | ||
|
|
||
| var webm = | ||
| 'data:video/webm;base64,GkXfo0AgQoaBAUL3gQFC8oEEQvOBCEKCQAR3ZWJtQoeBAkKFgQIYU4BnQI0VSalmQCgq17FAAw9CQE2AQAZ3aGFtbXlXQUAGd2hhbW15RIlACECPQAAAAAAAFlSua0AxrkAu14EBY8WBAZyBACK1nEADdW5khkAFVl9WUDglhohAA1ZQOIOBAeBABrCBCLqBCB9DtnVAIueBAKNAHIEAAIAwAQCdASoIAAgAAUAmJaQAA3AA/vz0AAA=' | ||
| var mp4 = | ||
|
|
@@ -46,21 +73,19 @@ var oldIOS = | |
| var nativeWakeLock = 'wakeLock' in navigator | ||
|
|
||
| var NoSleep = (function () { | ||
| var _releasedNative = true | ||
| var _nativeRequestInProgress = false | ||
| var _nativeEnabledCompleter; | ||
| var _playVideoCompleter; | ||
|
|
||
| function NoSleep() { | ||
| var _this = this | ||
|
|
||
| _classCallCheck(this, NoSleep) | ||
|
|
||
| this.nativeEnabled = false | ||
| if (nativeWakeLock) { | ||
| this._wakeLock = null | ||
| var handleVisibilityChange = function handleVisibilityChange() { | ||
| if ( | ||
| _this._wakeLock !== null && | ||
| document.visibilityState === 'visible' | ||
| ) { | ||
| if (_this._wakeLock !== null && document.visibilityState === 'visible') { | ||
| _this.enable() | ||
| } | ||
| } | ||
|
|
@@ -106,27 +131,39 @@ var NoSleep = (function () { | |
| }, | ||
| { | ||
| key: 'enable', | ||
| value: function enable() { | ||
| value: async function enable() { | ||
| var _this2 = this | ||
|
|
||
| if (nativeWakeLock) { | ||
| _nativeRequestInProgress = true | ||
| // Disalbe any previously held wakelocks. | ||
diegotori marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await this.disable() | ||
| if (_nativeEnabledCompleter == null) { | ||
| _nativeEnabledCompleter = new PromiseCompleter() | ||
| } | ||
| navigator.wakeLock | ||
| .request('screen') | ||
| .then(function (wakeLock) { | ||
| _releasedNative = false | ||
| _nativeRequestInProgress = false | ||
|
|
||
| _this2._wakeLock = wakeLock | ||
| _this2.nativeEnabled = true | ||
| _nativeEnabledCompleter.complete() | ||
| _nativeEnabledCompleter = null | ||
| // We now have a wakelock. Notify all of the existing callers. | ||
| console.log("Wake Lock active."); | ||
| _this2._wakeLock.addEventListener('release', function () { | ||
| _releasedNative = true | ||
| _this2.nativeEnabled = false | ||
| _this2._wakeLock = null | ||
| console.log("Wake Lock released."); | ||
| }) | ||
| }) | ||
| .catch(function (err) { | ||
| _nativeRequestInProgress = false | ||
| console.error(err.name + ', ' + err.message) | ||
| _this2.nativeEnabled = false | ||
| var errorMessage = err.name + ', ' + err.message | ||
| console.error(errorMessage) | ||
diegotori marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _nativeEnabledCompleter.completeError(errorMessage) | ||
| _nativeEnabledCompleter = null | ||
| }) | ||
| // We then wait for screen to be made available. | ||
| return _nativeEnabledCompleter.future | ||
| } else if (oldIOS) { | ||
holzgeist marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.disable() | ||
| console.warn( | ||
|
|
@@ -138,17 +175,35 @@ var NoSleep = (function () { | |
| window.setTimeout(window.stop, 0) | ||
| } | ||
| }, 15000) | ||
| return Promise.resolve() | ||
| } else { | ||
| this.noSleepVideo.play() | ||
| if (_playVideoCompleter == null) { | ||
| _playVideoCompleter = new PromiseCompleter() | ||
| } | ||
| var playPromise = this.noSleepVideo.play() | ||
| playPromise.then(function (res) { | ||
| _playVideoCompleter.complete() | ||
| _playVideoCompleter = null | ||
| }).catch(function (err) { | ||
| var errorMessage = err.name + ', ' + err.message | ||
| console.error(errorMessage) | ||
| _playVideoCompleter.completeError(errorMessage) | ||
| _playVideoCompleter = null | ||
| }); | ||
| return _playVideoCompleter.future | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| key: 'disable', | ||
| value: function disable() { | ||
| value: async function disable() { | ||
| if (nativeWakeLock) { | ||
| // If we're still trying to enable the wakelock, wait for it to be enabled | ||
| if (_nativeEnabledCompleter != null) { | ||
| await _nativeEnabledCompleter.future | ||
| } | ||
| if (this._wakeLock != null) { | ||
| _releasedNative = true | ||
| this.nativeEnabled = false | ||
| this._wakeLock.release() | ||
| } | ||
|
|
||
|
|
@@ -162,34 +217,30 @@ var NoSleep = (function () { | |
| this.noSleepTimer = null | ||
| } | ||
| } else { | ||
| if (_playVideoCompleter != null) { | ||
| await _playVideoCompleter.future | ||
| } | ||
| this.noSleepVideo.pause() | ||
| } | ||
| return Promise.resolve(); | ||
| }, | ||
| }, | ||
| { | ||
| key: 'enabled', | ||
| value: async function enabled() { | ||
| key: 'isEnabled', | ||
| value: async function isEnabled() { | ||
| if (nativeWakeLock) { | ||
| if (_nativeRequestInProgress == true) { | ||
| // Wait until the request is done. | ||
| while (true) { | ||
| // Wait for 42 milliseconds. | ||
| await new Promise((resolve, reject) => setTimeout(resolve, 42)) | ||
| if (_nativeRequestInProgress == false) { | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // todo: use WakeLockSentinel.released when that is available (https://developer.mozilla.org/en-US/docs/Web/API/WakeLockSentinel/released) | ||
| if (_releasedNative != false) { | ||
| return false | ||
| // If we're still trying to enable the wakelock, wait for it to be enabled | ||
| if (_nativeEnabledCompleter != null) { | ||
| await _nativeEnabledCompleter.future | ||
| } | ||
|
|
||
| return true | ||
| return this.nativeEnabled | ||
| } else if (oldIOS) { | ||
| return this.noSleepTimer != null | ||
| } else { | ||
| if (_playVideoCompleter != null) { | ||
| await _playVideoCompleter.future | ||
| } | ||
| if (this.noSleepVideo == undefined) { | ||
| return false | ||
| } | ||
|
|
@@ -208,17 +259,22 @@ var noSleep = new NoSleep() | |
| var Wakelock = { | ||
| enabled: async function () { | ||
| try { | ||
| return noSleep.enabled() | ||
| return noSleep.isEnabled() | ||
| } catch (e) { | ||
| return false | ||
| } | ||
| }, | ||
| toggle: async function (enable) { | ||
| if (enable) { | ||
| noSleep.enable() | ||
| } else { | ||
| noSleep.disable() | ||
| try { | ||
| if (enable) { | ||
| await noSleep.enable() | ||
| } else { | ||
| await noSleep.disable() | ||
| } | ||
| } catch (e) { | ||
| throw e | ||
|
||
| } | ||
| return Promise.resolve() | ||
| }, | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.