TagSpaces is an offline, open source, document manager with tagging support
fixes cordova-io
Stanimir Marinov2f980ce46da4
diff --git a/.gitignore b/.gitignoreindex 7293cffa5..7591e8e98 100644--- a/.gitignore+++ b/.gitignore@@ -42,6 +42,7 @@ main.js.mappackage-lock.json.idea+*.imlnpm-debug.log.*# Cordova filesdiff --git a/app/reducers/app.js b/app/reducers/app.jsindex 6b291b988..e15c669fc 100644--- a/app/reducers/app.js+++ b/app/reducers/app.js@@ -1223,7 +1223,9 @@ function prepareDirectoryContent(dispatch(actions.showNotification('Generating thumbnails failed', 'warning', true));}+ let genPromices = false;if (tmbGenerationPromises.length > 0) {+ genPromices = true;dispatch(actions.setGeneratingThumbnails(true));// dispatch(actions.showNotification('Checking thumbnails', 'info', false));Promise.all(tmbGenerationPromises)@@ -1232,11 +1234,18 @@ function prepareDirectoryContent(}if (tmbGenerationList.length > 0) {- dispatch(actions.setGeneratingThumbnails(true));+ if (!genPromices) {+ dispatch(actions.setGeneratingThumbnails(true));+ }// dispatch(actions.showNotification('Loading or generating thumbnails...', 'info', false));PlatformIO.createThumbnailsInWorker(tmbGenerationList).then(handleTmbGenerationResults).catch(handleTmbGenerationFailed);+ } else if (!genPromices) { // no dirEntries+ console.log('Dir ' + directoryPath + ' contains ' + directoryContent.length);+ dispatch(actions.setGeneratingThumbnails(false));+ dispatch(actions.loadDirectorySuccess(directoryPath, directoryContent));+ return;}// directoryContent.sort((a, b) => (a.name < b.name ? -1 : 1));diff --git a/app/services/cordova-io.js b/app/services/cordova-io.jsindex 490f5144f..41526f3b7 100644--- a/app/services/cordova-io.js+++ b/app/services/cordova-io.js@@ -21,7 +21,7 @@import AppConfig from '../config';import { b64toBlob } from '../utils/misc';-import { extractParentDirectoryPath } from '../utils/paths';+import { extractParentDirectoryPath, cleanTrailingDirSeparator } from '../utils/paths';const appSettingFile = 'settings.json';const appSettingTagsFile = 'settingsTags.json';@@ -44,7 +44,7 @@ export default class CordovaIO {loadedSettingsTags: any;onDeviceReady = () => {- console.log('Device Ready: ' + window['device'].platform + ' - ' + window['device'].version);+ console.log('Device Ready: ' + window.device.platform + ' - ' + window.device.version);// attachFastClick(document.body);this.getFileSystem();@@ -313,9 +313,7 @@ export default class CordovaIO {this.saveSettingsFile(appSettingFile, settings);};- loadSettings = () => {- return this.loadedSettings;- };+ loadSettings = () => this.loadedSettings;saveSettingsTags = (tagGroups: Object) => {// TODO use js objects@@ -334,9 +332,7 @@ export default class CordovaIO {this.saveSettingsFile(appSettingTagsFile, jsonFormat);};- loadSettingsTags = () => {- return this.loadedSettingsTags;- };+ loadSettingsTags = () => this.loadedSettingsTags;sendFile = (filePath: string) => {console.log('Sending file: ' + filePath);@@ -361,9 +357,7 @@ export default class CordovaIO {return paths;};- getUserHomePath = (): string => {- return '/';- };+ getUserHomePath = (): string => '/';getAppDataPath = () => {// const appDataPath = ipcRenderer.sendSync('app-data-path-request', 'notNeededArgument');@@ -385,112 +379,218 @@ export default class CordovaIO {console.warn('Creating directory tree is not supported in Cordova yet.');};+ listMetaDirectoryPromise = async (path: string): Promise<Array<Object>> => {+ const promise = new Promise((resolve) => {+ const entries = [];+ const metaDirPath = cleanTrailingDirSeparator(path) + AppConfig.dirSeparator + AppConfig.metaFolder + AppConfig.dirSeparator;++ this.getFileSystemPromise(metaDirPath).then(+ fileSystem => {+ const reader = fileSystem.createReader();+ reader.readEntries(+ entr => {+ entr.forEach(entry => {+ const entryPath = entry.fullPath;+ if (entryPath.toLowerCase() === metaDirPath.toLowerCase()) {+ console.log('Skipping current folder');+ } else {+ const ee = {};+ ee.name = entry.name;+ ee.path = decodeURI(entryPath);+ ee.isFile = true;+ entries.push(ee);+ }+ });+ resolve(entries);+ });+ return true;+ })+ .catch((err) => {+ console.error('Error getting listMetaDirectoryPromise:', err);+ resolve([]); // returning results even if any promise fails+ });+ });+ const result = await promise; // this.listDirectoryPromise(normalizePath(path) + AppConfig.dirSeparator + AppConfig.metaFolder + AppConfig.dirSeparator, true);+ return result;+ };+/*** Creates a list with containing the files and the sub directories of a given directory*/- listDirectoryPromise = (path: string, lite: boolean): Promise<*> => {+ listDirectoryPromise = (path: string, lite: boolean): Promise<*> => new Promise(async (resolve, reject) => {console.time('listDirectoryPromise');- return new Promise((resolve, reject) => {- const anotatedDirList = [];- const fileWorkers = [];- this.getFileSystemPromise(path).then(- fileSystem => {- const reader = fileSystem.createReader();- reader.readEntries(- entries => {- entries.forEach(entry => {- if (entry.isDirectory) {+ const metaContent = !lite ? await this.listMetaDirectoryPromise(path) : [];++ const enhancedEntries = [];+ const metaPromises = [];+ this.getFileSystemPromise(path).then(+ fileSystem => {+ const reader = fileSystem.createReader();+ reader.readEntries(+ entries => {+ entries.forEach(entry => {+ const eentry = {};+ eentry.name = entry.name;+ eentry.path = entry.fullPath;+ eentry.tags = [];+ eentry.thumbPath = '';+ // eentry.meta = {};+ eentry.isFile = entry.isFile;+ if (entry.isFile) {+ entry.file(+ fileEntry => {+ eentry.size = fileEntry.size;+ eentry.lmdt = fileEntry.lastModifiedDate;+ });+ }++ if (!lite) {+ if (entry.isDirectory) { // Read tsm.json from subfolders+ const metaDirAvailable = metaContent.find(obj => obj.name === AppConfig.metaFolder);+ if (metaDirAvailable) {+ metaPromises.push(this.getEntryMeta(eentry, metaDirAvailable.path));+ }+ } else {+ const metaFileAvailable = metaContent.find(obj => obj.name === entry.name + AppConfig.metaFileExt);+ if (metaFileAvailable) {+ metaPromises.push(this.getEntryMeta(eentry, metaFileAvailable.path));+ }++ // Finding if thumbnail available+ const metaThumbAvailable = metaContent.find(obj => obj.name === entry.name + AppConfig.thumbFileExt);+ if (metaThumbAvailable) {+ eentry.thumbPath = metaThumbAvailable.path;+ }+ }+ }++ enhancedEntries.push(eentry);++ /* if (entry.isDirectory) {+ anotatedDirList.push({+ name: entry.name,+ path: entry.fullPath,+ isFile: false,+ size: '',+ lmdt: ''+ });+ } else if (entry.isFile) {+ if (lite) {anotatedDirList.push({name: entry.name,path: entry.fullPath,- isFile: false,+ isFile: true,size: '',lmdt: ''});- } else if (entry.isFile) {- if (lite) {- anotatedDirList.push({- name: entry.name,- path: entry.fullPath,- isFile: true,- size: '',- lmdt: ''- });- } else {- const filePromise = Promise.resolve({- then: (onFulfill, onReject) => {- entry.file(- fileEntry => {- if (!fileEntry.fullPath) {- fileEntry.fullPath = this.resolveFullPath(- fileEntry.localURL- );- }- anotatedDirList.push();- onFulfill({- name: fileEntry.name,- isFile: true,- size: fileEntry.size,- lmdt: fileEntry.lastModifiedDate,- path: fileEntry.fullPath- });- },- err => {- onReject('Error reading entry ' + path);+ } else {+ const filePromise = Promise.resolve({+ then: (onFulfill, onReject) => {+ entry.file(+ fileEntry => {+ if (!fileEntry.fullPath) {+ fileEntry.fullPath = this.resolveFullPath(+ fileEntry.localURL+ );}- );- }- }); // jshint ignore:line- fileWorkers.push(filePromise);- }+ anotatedDirList.push();+ onFulfill({+ name: fileEntry.name,+ isFile: true,+ size: fileEntry.size,+ lmdt: fileEntry.lastModifiedDate,+ path: fileEntry.fullPath+ });+ },+ err => {+ onReject('Error reading entry ' + path);+ }+ );+ }+ }); // jshint ignore:line+ fileWorkers.push(filePromise);}- });-- Promise.all(fileWorkers).then(- entries => {- entries.forEach(entry => {- anotatedDirList.push(entry);- });- console.timeEnd('listDirectoryPromise');- resolve(anotatedDirList);- },- err => {- console.warn(- 'At least one file worker failed for ' ++ } */+ });++ Promise.all(metaPromises).then(() => {+ resolve(enhancedEntries);+ return true;+ }).catch(() => {+ resolve(enhancedEntries);+ });+ /* Promise.all(fileWorkers).then(+ entries => {+ entries.forEach(entry => {+ anotatedDirList.push(entry);+ });+ console.timeEnd('listDirectoryPromise');+ resolve(anotatedDirList);+ },+ err => {+ console.warn(+ 'At least one file worker failed for ' +path +'err ' +JSON.stringify(err)- );- console.timeEnd('listDirectoryPromise');- resolve(anotatedDirList); // returning results even if any promise fails- }- );- },- err => {- console.warn(- 'Error reading entries promise from ' ++ );+ console.timeEnd('listDirectoryPromise');+ resolve(anotatedDirList); // returning results even if any promise fails+ }+ ); */+ },+ err => {+ console.warn(+ 'Error reading entries promise from ' +path +'err ' +JSON.stringify(err)- );- resolve(anotatedDirList); // returning results even if any promise fails- }- );- },- () => {- console.warn('Error getting file system promise');- resolve(anotatedDirList); // returning results even if any promise fails- }- );+ );+ resolve(enhancedEntries); // returning results even if any promise fails+ }+ );+ return true;+ },+ () => {+ console.warn('Error getting file system promise');+ resolve(enhancedEntries); // returning results even if any promise fails+ }+ )+ .catch((err) => {+ console.error('Error getting listDirectoryPromise:', err);+ resolve(enhancedEntries); // returning results even if any promise fails+ });+ });++ getEntryMeta = (eentry: Object, metaPath: string): Promise<Object> => {+ if (eentry.isFile) {+ // const metaFilePath = getMetaFileLocationForFile(eentry.path);+ return this.loadTextFilePromise(metaPath).then(result => {+ // eslint-disable-next-line no-param-reassign+ eentry.meta = JSON.parse(result.trim());+ return eentry;+ });+ }+ // const folderMetaPath = normalizePath(eentry.path) + AppConfig.dirSeparator + AppConfig.metaFolderFile; // getMetaFileLocationForDir(eentry.path);+ if (!eentry.path.endsWith(AppConfig.metaFolder + '/')) { // Skip the /.ts folder+ return this.loadTextFilePromise(metaPath).then(result => {+ // eslint-disable-next-line no-param-reassign+ eentry.meta = JSON.parse(result.trim());+ return eentry;+ });+ }++ return new Promise((resolve) => {+ resolve(eentry);});};/*** Finds out the properties of a file or directory such last modification date or file size*/- getPropertiesPromise = (path: string): Promise<*> => {- return new Promise((resolve, reject) => {- let entryPath = this.normalizePath(path);+ getPropertiesPromise = (path: string): Promise<*> =>+ new Promise((resolve, reject) => {+ const entryPath = this.normalizePath(path);// getFileSystemPromise(dir).then(function(fileSystem) {const fileProperties = {};this.fsRoot.getFile(@@ -507,6 +607,8 @@ export default class CordovaIO {fileProperties.size = file.size;fileProperties.lmdt = file.lastModifiedDate;fileProperties.mimetype = file.type;+ fileProperties.isFile = entry.isFile;+ fileProperties.name = file.name;resolve(fileProperties);},() => {@@ -526,21 +628,19 @@ export default class CordovaIO {resolve(false);}},- () => {- console.log('getPropertiesPromise: Error getting file ' + entryPath);+ (err) => {+ console.log('getPropertiesPromise: Error getting file ' + entryPath, err);resolve(false);});- });+ })// });- };+ ;/*** Load the content of a text file*/- loadTextFilePromise = (filePath: string): Promise<*> => {- return this.getFileContentPromise(filePath, 'text');- };+ loadTextFilePromise = (filePath: string): Promise<*> => this.getFileContentPromise(filePath, 'text');/*** Gets the content of file, useful for binary files@@ -590,10 +690,10 @@ export default class CordovaIO {return new Promise((resolve, reject) => {getFilePromise(filePath, resolvePath).then(file => {const reader = new FileReader();- reader.onerror = function() {+ reader.onerror = function () {reject(reader.error);};- reader.onload = function() {+ reader.onload = function () {resolve(reader.result);};if (type === 'text') {@@ -642,7 +742,7 @@ export default class CordovaIO {entry => {entry.createWriter(writer => {- writer.onwriteend = function(evt) {+ writer.onwriteend = function (evt) {// resolve(this.fsRoot.fullPath + "/" + filePath);resolve(isFileNew);};@@ -868,98 +968,94 @@ export default class CordovaIO {renameDirectoryPromise = (dirPath: string,newDirName: string- ): Promise<*> => {- return new Promise((resolve, reject) => {- let newDirPath =+ ): Promise<*> => new Promise((resolve, reject) => {+ let newDirPath =extractParentDirectoryPath(dirPath) +AppConfig.dirSeparator +newDirName;- dirPath = this.normalizePath(dirPath);- const newDirParentPath = this.normalizePath(- newDirPath.substring(0, newDirPath.lastIndexOf('/'))- );- newDirPath = this.normalizePath(newDirPath);- console.log('renameDirectoryPromise: ' + dirPath + ' to: ' + newDirPath);- // TODO check if the newFilePath exist or cause issues by renaming- this.fsRoot.getDirectory(- newDirParentPath,- {- create: false,- exclusive: false- },- parentDirEntry => {- this.fsRoot.getDirectory(- dirPath,- {- create: false,- exclusive: false- },- entry => {- entry.moveTo(- parentDirEntry,- newDirName,- () => {- console.log(- 'Directory renamed to: ' ++ dirPath = this.normalizePath(dirPath);+ const newDirParentPath = this.normalizePath(+ newDirPath.substring(0, newDirPath.lastIndexOf('/'))+ );+ newDirPath = this.normalizePath(newDirPath);+ console.log('renameDirectoryPromise: ' + dirPath + ' to: ' + newDirPath);+ // TODO check if the newFilePath exist or cause issues by renaming+ this.fsRoot.getDirectory(+ newDirParentPath,+ {+ create: false,+ exclusive: false+ },+ parentDirEntry => {+ this.fsRoot.getDirectory(+ dirPath,+ {+ create: false,+ exclusive: false+ },+ entry => {+ entry.moveTo(+ parentDirEntry,+ newDirName,+ () => {+ console.log(+ 'Directory renamed to: ' +newDirPath +' from: ' +entry.fullPath- );- resolve('/' + newDirPath);- },- err => {- reject('error renaming directory: ' + dirPath + ' ' + err);- }- );- },- error => {- reject('Error getting directory: ' + dirPath + ' ' + error);- }- );- },- error => {- console.error(- 'Getting dir: ' ++ );+ resolve('/' + newDirPath);+ },+ err => {+ reject('error renaming directory: ' + dirPath + ' ' + err);+ }+ );+ },+ error => {+ reject('Error getting directory: ' + dirPath + ' ' + error);+ }+ );+ },+ error => {+ console.error(+ 'Getting dir: ' +newDirParentPath +' failed with error code: ' +error.code- );- reject(error);- }- );- });- };+ );+ reject(error);+ }+ );+ });/*** Delete a specified file*/- deleteFilePromise = (filePath: string): Promise<*> => {- return new Promise((resolve, reject) => {- const path = this.normalizePath(filePath);- this.fsRoot.getFile(- path,- {- create: false,- exclusive: false- },- entry => {- entry.remove(- () => {- console.log('file deleted: ' + path);- resolve(filePath);- },- err => {- reject('error deleting: ' + filePath + ' ' + err);- }- );- },- error => {- reject('error getting file' + path + ' ' + error);- }- );- });- };+ deleteFilePromise = (filePath: string): Promise<*> => new Promise((resolve, reject) => {+ const path = this.normalizePath(filePath);+ this.fsRoot.getFile(+ path,+ {+ create: false,+ exclusive: false+ },+ entry => {+ entry.remove(+ () => {+ console.log('file deleted: ' + path);+ resolve(filePath);+ },+ err => {+ reject('error deleting: ' + filePath + ' ' + err);+ }+ );+ },+ error => {+ reject('error getting file' + path + ' ' + error);+ }+ );+ });/*** Delete a specified directory, the directory should be empty, if the trash can functionality is not enableddiff --git a/package.json b/package.jsonindex bca4769f9..80abfe583 100644--- a/package.json+++ b/package.json@@ -11,6 +11,7 @@"build": "yarn version-meta && concurrently \"yarn build-main\" \"yarn build-renderer\" \"yarn build-worker\"","build-dll": "cross-env NODE_ENV=development node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.dev.dll.js --progress --profile --colors","build-cordova": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.cordova.js --progress --profile --colors",+ "build-cordova-dev": "cross-env NODE_ENV=development node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.cordova.js --progress --profile --colors","build-web": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.web.js --progress --profile --colors","build-main": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --progress --profile --colors","build-renderer": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --progress --profile --colors",@@ -51,6 +52,7 @@"cordova-android": "cd cordova && cordova platform add android && cd ..","cordova-create": "cordova create ./cordova org.tagspaces.mobile TagSpaces","start-android": "yarn build-cordova && yarn run-android",+ "start-android-dev": "yarn build-cordova-dev && yarn run-android","update-changelog": "git log v3.0.0-rc.6..HEAD --no-merges --format=%B > CHANGELOG.TXT","clean": "rimraf app/dist && rimraf node_modules && rimraf app/node_modules"},