Skip to content

Commit

Permalink
fix(android): create toURL override to preserve other platforms (apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu authored and pmcquay committed Sep 2, 2022
1 parent d296cfd commit 0fe72d5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ to config.xml in order for the application to find previously stored files.
<framework src="androidx.webkit:webkit:$ANDROIDX_WEBKIT_VERSION" />

<!-- android specific file apis -->
<js-module src="www/android/Entry.js" name="androidEntry">
<merges target="Entry" />
</js-module>
<js-module src="www/android/FileSystem.js" name="androidFileSystem">
<merges target="FileSystem" />
</js-module>
Expand Down
11 changes: 7 additions & 4 deletions www/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ Entry.prototype.toInternalURL = function () {
/**
* Return a URL that can be used to identify this entry.
* Use a URL that can be used to as the src attribute of a <video> or
* <audio> tag. If that is not possible, construct a http(s)://(localhost) URL.
* <audio> tag. If that is not possible, construct a cdvfile:// URL.
*/
Entry.prototype.toURL = function () {
return window.location.origin.includes('file://')
? this.nativeURL
: this.toInternalURL();
if (this.nativeURL) {
return this.nativeURL;
}
// fullPath attribute may contain the full URL in the case that
// toInternalURL fails.
return this.toInternalURL() || 'file://localhost' + this.fullPath;
};

/**
Expand Down
33 changes: 33 additions & 0 deletions www/android/Entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

module.exports = {
/**
* Return a URL that can be used to identify this entry.
* Use a URL that can be used to as the src attribute of a <video> or
* <audio> tag. If that is not possible, construct a http(s)://(localhost) URL.
*/
toURL: function () {
return window.location.origin.includes('file://')
? this.nativeURL
: this.toInternalURL();
}
};

0 comments on commit 0fe72d5

Please sign in to comment.