Skip to content

Commit

Permalink
chore!: removed old platform code & lint cleanup (#519)
Browse files Browse the repository at this point in the history
* style: apply lint fix
* test: remove old windows related platform code
* test: remove old blackberry related platform code
* test: remove old amazon-fireos related platform code
* style: remove eslint-disable-line no-undef & add globals
* chore!: remove old windows8 code
* chore!: remove old windowsphone code
  • Loading branch information
erisu authored Mar 30, 2022
1 parent e97fe90 commit f85373b
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 38 deletions.
10 changes: 8 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ root: true
extends: '@cordova/eslint-config/browser'
globals:
cordova: true
LocalFileSystem: true
FileError: true
DirectoryEntry: true
FileWriter: true
Flags: true
Metadata: true
FileSystem: true
resolveLocalFileSystemURL: true

overrides:
- files: [tests/**/*.js]
extends: '@cordova/eslint-config/node-tests'
globals:
cordova: true
17 changes: 6 additions & 11 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.defineAutoTests = function () {
var isIE = isBrowser && (window.msIndexedDB);
var isIndexedDBShim = isBrowser && !isChrome; // Firefox and IE for example

var isWindows = (cordova.platformId === 'windows' || cordova.platformId === 'windows8');
var isWindows = cordova.platformId === 'windows';
/* eslint-enable no-undef */
var MEDIUM_TIMEOUT = 15000;

Expand Down Expand Up @@ -417,7 +417,7 @@ exports.defineAutoTests = function () {
});

it('file.spec.11 should error (NOT_FOUND_ERR) when resolving (non-existent) invalid file name', function (done) {
var fileName = cordova.platformId === 'windowsphone' ? root.toURL() + '/' + 'this.is.not.a.valid.file.txt' : joinURL(root.toURL(), 'this.is.not.a.valid.file.txt'); // eslint-disable-line no-undef
var fileName = joinURL(root.toURL(), 'this.is.not.a.valid.file.txt');
var fail = function (error) {
expect(error).toBeDefined();
if (isChrome) {
Expand Down Expand Up @@ -2453,7 +2453,7 @@ exports.defineAutoTests = function () {
// FileReader
describe('Read method', function () {
it('file.spec.82 should error out on non-existent file', function (done) {
var fileName = cordova.platformId === 'windowsphone' ? root.toURL() + '/' + 'somefile.txt' : 'somefile.txt'; // eslint-disable-line no-undef
var fileName = 'somefile.txt';
var verifier = function (evt) {
expect(evt).toBeDefined();
if (isChrome) {
Expand Down Expand Up @@ -3440,8 +3440,6 @@ exports.defineAutoTests = function () {
if (cordova.platformId === 'android') {
// Starting from Cordova-Android 10.x, the app content is served from the https scheme
pathExpect = 'https://';
} else if (cordova.platformId === 'windowsphone') {
pathExpect = '//nativ';
} else if (isChrome) {
pathExpect = 'filesystem:http://';
}
Expand Down Expand Up @@ -3788,14 +3786,12 @@ exports.defineAutoTests = function () {
it('file.spec.129 cordova.file.*Directory are set', function () {
var expectedPaths = ['applicationDirectory', 'applicationStorageDirectory', 'dataDirectory', 'cacheDirectory'];
/* eslint-disable no-undef */
if (cordova.platformId === 'android' || cordova.platformId === 'amazon-fireos') {
if (cordova.platformId === 'android') {
if (cordova.file.externalApplicationStorageDirectory !== null) {
// https://issues.apache.org/jira/browse/CB-10411
// If external storage can't be mounted, the cordova.file.external* properties are null.
expectedPaths.push('externalApplicationStorageDirectory', 'externalRootDirectory', 'externalCacheDirectory', 'externalDataDirectory');
}
} else if (cordova.platformId === 'blackberry10') {
expectedPaths.push('externalRootDirectory', 'sharedDirectory');
} else if (cordova.platformId === 'ios') {
expectedPaths.push('syncedDataDirectory', 'documentsDirectory', 'tempDirectory');
} else if (cordova.platformId === 'osx') {
Expand All @@ -3817,10 +3813,10 @@ exports.defineAutoTests = function () {
var cdvfileApplicationDirectoryFsRootNameURL;
if (cordova.platformId === 'android') {
cdvfileApplicationDirectoryFsRootName = 'assets';
cdvfileApplicationDirectoryFsRootNameURL = 'https://localhost/__cdvfile_' + cdvfileApplicationDirectoryFsRootName + '__/'
cdvfileApplicationDirectoryFsRootNameURL = 'https://localhost/__cdvfile_' + cdvfileApplicationDirectoryFsRootName + '__/';
} else if (cordova.platformId === 'ios') {
cdvfileApplicationDirectoryFsRootName = 'bundle';
cdvfileApplicationDirectoryFsRootNameURL = 'cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName + '/'
cdvfileApplicationDirectoryFsRootNameURL = 'cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName + '/';
} else {
pending();
}
Expand Down Expand Up @@ -4206,7 +4202,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
ios: 'library,library-nosync,documents,documents-nosync,cache,bundle,root,private',
osx: 'library,library-nosync,documents,documents-nosync,cache,bundle,root,private',
android: 'files,files-external,documents,sdcard,cache,cache-external,assets,root',
'amazon-fireos': 'files,files-external,documents,sdcard,cache,cache-external,root',
windows: 'temporary,persistent'
};

Expand Down
4 changes: 2 additions & 2 deletions www/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Entry.prototype.moveTo = function (parent, newName, successCallback, errorCallba
if (successCallback) {
// create appropriate Entry object
var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' }); // eslint-disable-line no-undef
var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' });
var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
successCallback(result);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ Entry.prototype.copyTo = function (parent, newName, successCallback, errorCallba
if (successCallback) {
// create appropriate Entry object
var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' }); // eslint-disable-line no-undef
var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' });
var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
successCallback(result);
}
Expand Down
2 changes: 1 addition & 1 deletion www/FileReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function readSuccessCallback (readType, encoding, offset, totalSize, accumulate,
if (readType === 'readAsDataURL') {
// Windows proxy does not support reading file slices as Data URLs
// so read the whole file at once.
CHUNK_SIZE = cordova.platformId === 'windows' ? totalSize // eslint-disable-line no-undef
CHUNK_SIZE = cordova.platformId === 'windows' ? totalSize
: (
// Calculate new chunk size for data URLs to be multiply of 3
// Otherwise concatenated base64 chunks won't be valid base64 data
Expand Down
6 changes: 1 addition & 5 deletions www/FileWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ FileWriter.prototype.write = function (data, isPendingBlobReadResult) {
var that = this;
var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
/* eslint-disable no-undef */
var isProxySupportBlobNatively = (cordova.platformId === 'windows8' || cordova.platformId === 'windows');
var isProxySupportBlobNatively = cordova.platformId === 'windows';
var isBinary;

// Check to see if the incoming data is a blob
Expand Down Expand Up @@ -154,10 +154,6 @@ FileWriter.prototype.write = function (data, isPendingBlobReadResult) {

// Mark data type for safer transport over the binary bridge
isBinary = supportsBinary && (data instanceof ArrayBuffer);
if (isBinary && cordova.platformId === 'windowsphone') { // eslint-disable-line no-undef
// create a plain array, using the keys from the Uint8Array view so that we can serialize it
data = Array.apply(null, new Uint8Array(data));
}

// Throw an exception if we are already writing a file
if (this.readyState === FileWriter.WRITING && !isPendingBlobReadResult) {
Expand Down
12 changes: 6 additions & 6 deletions www/android/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*/

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();
}
toURL: function () {
return window.location.origin.includes('file://')
? this.nativeURL
: this.toInternalURL();
}
};
2 changes: 1 addition & 1 deletion www/android/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
// doesn't match the string for which permission was originally granted.
path = nativeUrl.substring(contentUrlMatch[0].length - 1);
} else {
path = FileSystem.encodeURIPath(fullPath); // eslint-disable-line no-undef
path = FileSystem.encodeURIPath(fullPath);
if (!/^\//.test(path)) {
path = '/' + path;
}
Expand Down
2 changes: 1 addition & 1 deletion www/browser/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ FILESYSTEM_PREFIX = 'file:///';

module.exports = {
__format__: function (fullPath) {
return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : '/') + FileSystem.encodeURIPath(fullPath)); // eslint-disable-line no-undef
return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : '/') + FileSystem.encodeURIPath(fullPath));
}
};
10 changes: 5 additions & 5 deletions www/browser/Preparing.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
var channel = require('cordova/channel');
var FileError = require('./FileError');
var PERSISTENT_FS_QUOTA = 5 * 1024 * 1024;
var filePluginIsReadyEvent = new Event('filePluginIsReady'); // eslint-disable-line no-undef
var filePluginIsReadyEvent = new Event('filePluginIsReady');

var entryFunctionsCreated = false;
var quotaWasRequested = false;
Expand Down Expand Up @@ -75,8 +75,8 @@
For example, filesystem:file:///persistent/somefile.txt,
filesystem:http://localhost:8080/persistent/somefile.txt. */
var prefix = 'filesystem:file:///';
if (location.protocol !== 'file:') { // eslint-disable-line no-undef
prefix = 'filesystem:' + location.origin + '/'; // eslint-disable-line no-undef
if (location.protocol !== 'file:') {
prefix = 'filesystem:' + location.origin + '/';
}

var result;
Expand Down Expand Up @@ -146,10 +146,10 @@
var originalWrite = writer.write;
var writerProto = Object.getPrototypeOf(writer);
writerProto.write = function (blob) {
if (blob instanceof Blob) { // eslint-disable-line no-undef
if (blob instanceof Blob) {
originalWrite.apply(this, [blob]);
} else {
var realBlob = new Blob([blob]); // eslint-disable-line no-undef
var realBlob = new Blob([blob]);
originalWrite.apply(this, [realBlob]);
}
};
Expand Down
2 changes: 1 addition & 1 deletion www/requestFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(function () {
// For browser platform: not all browsers use this file.
function checkBrowser () {
if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
if (cordova.platformId === 'browser' && require('./isChrome')()) {
module.exports = window.requestFileSystem || window.webkitRequestFileSystem;
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions www/resolveLocalFileSystemURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(function () {
// For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
function checkBrowser () {
if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
if (cordova.platformId === 'browser' && require('./isChrome')()) {
module.exports.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
return true;
}
Expand Down Expand Up @@ -65,11 +65,11 @@
if (entry) {
if (successCallback) {
// create appropriate Entry object
var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem === window.PERSISTENT ? 'persistent' : 'temporary'); // eslint-disable-line no-undef
var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem === window.PERSISTENT ? 'persistent' : 'temporary');
fileSystems.getFs(fsName, function (fs) {
// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
if (!fs) {
fs = new FileSystem(fsName, { name: '', fullPath: '/' }); // eslint-disable-line no-undef
fs = new FileSystem(fsName, { name: '', fullPath: '/' });
}
var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs, entry.nativeURL) : new FileEntry(entry.name, entry.fullPath, fs, entry.nativeURL);
successCallback(result);
Expand Down

0 comments on commit f85373b

Please sign in to comment.