Skip to content

Commit

Permalink
Add cordova.file.dataDirectory check
Browse files Browse the repository at this point in the history
  • Loading branch information
pbakondy committed Apr 5, 2016
1 parent 9a2d0f3 commit 420508b
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 14 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Ionic File Logger

[![Bower](http://img.shields.io/badge/bower-filelogger-FFCC2F.svg?style=flat)](http://bower.io/search/?q=filelogger)

Logger module for Cordova/Ionic projects.
Logger module for Ionic projects.

When you run your application in device the Logger writes in the local filesystem (with cordova-plugin-file) and the system logs (with console.log).

When you run your application in browser with „ionic serve” the Logger uses browsers localStorage and the browser console (with console.log).

## Dependencies

- [ngCordova](http://ngcordova.com/) ( required version v0.1.14-alpha )
- [ngCordova](http://ngcordova.com/) ( required version v0.1.24-alpha )
- [cordova-plugin-file](https://github.com/apache/cordova-plugin-file)

## Installation
Expand All @@ -28,6 +28,12 @@ Install manually, or from bower:
$ bower install filelogger
```

Install with npm:

```bash
$ npm install ionic-filelogger
```

Include *filelogger.min.js* and ng-cordova.js or *ng-cordova.min.js* in your index.html file before cordova.js and after your AngularJS / Ionic file (since ngCordova depends on AngularJS).

```html
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filelogger",
"version": "1.3.0",
"version": "1.3.1",
"homepage": "https://github.com/pbakondy/filelogger",
"authors": [
"Peter Bakondy <[email protected]>"
Expand All @@ -14,7 +14,7 @@
"config"
],
"dependencies": {
"ngCordova": ">= 0.1.14-alpha"
"ngCordova": ">= 0.1.24-alpha"
},
"keywords": [
"cordova",
Expand Down
2 changes: 1 addition & 1 deletion config/build.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
banner: '/*!\n' +
' * fileLogger\n' +
' * Copyright 2015 Peter Bakondy https://github.com/pbakondy\n' +
' * Copyright 2016 Peter Bakondy https://github.com/pbakondy\n' +
' * See LICENSE in this repository for license information\n' +
' */\n',

Expand Down
24 changes: 23 additions & 1 deletion dist/filelogger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* fileLogger
* Copyright 2015 Peter Bakondy https://github.com/pbakondy
* Copyright 2016 Peter Bakondy https://github.com/pbakondy
* See LICENSE in this repository for license information
*/
(function(){
Expand Down Expand Up @@ -172,6 +172,11 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])

} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.checkFile(cordova.file.dataDirectory, storageFilename).then(
function() {
// writeExistingFile(path, fileName, text)
Expand Down Expand Up @@ -209,6 +214,12 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])
if (isBrowser()) {
q.resolve($window.localStorage[storageFilename]);
} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.readAsText(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
Expand All @@ -230,6 +241,12 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])
$window.localStorage.removeItem(storageFilename);
q.resolve();
} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.removeFile(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
Expand Down Expand Up @@ -281,6 +298,11 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])

} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.checkFile(cordova.file.dataDirectory, storageFilename).then(function(fileEntry) {
fileEntry.file(q.resolve, q.reject);
}, q.reject);
Expand Down
4 changes: 2 additions & 2 deletions dist/filelogger.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
{
"name": "filelogger",
"name": "ionic-filelogger",
"private": false,
"main": "dist/filelogger",
"version": "1.3.0",
"version": "1.3.1",
"repository": {
"url": "git://github.com/pbakondy/filelogger.git"
"type": "git",
"url": "https://github.com/pbakondy/filelogger.git"
},
"devDependencies": {
"gulp": "^3.7.0",
"gulp": "^3.9.1",
"gulp-footer": "^1.0.4",
"gulp-header": "^1.0.2",
"gulp-jshint": "^2.0.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.5.1",
"gulp-uglify": "^1.5.3",
"jshint": "^2.8.0",
"jshint-stylish": "^2.1.0",
"minimist": "^1.2.0"
},
"license": "MIT",
"dependencies": {}
"dependencies": {
"ng-cordova": "^0.1.24-alpha"
},
"bugs": {
"url": "https://github.com/pbakondy/filelogger/issues"
},
"homepage": "https://github.com/pbakondy/filelogger#readme"
}
22 changes: 22 additions & 0 deletions src/filelogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])

} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.checkFile(cordova.file.dataDirectory, storageFilename).then(
function() {
// writeExistingFile(path, fileName, text)
Expand Down Expand Up @@ -203,6 +208,12 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])
if (isBrowser()) {
q.resolve($window.localStorage[storageFilename]);
} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.readAsText(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
Expand All @@ -224,6 +235,12 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])
$window.localStorage.removeItem(storageFilename);
q.resolve();
} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.removeFile(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
Expand Down Expand Up @@ -275,6 +292,11 @@ angular.module('fileLogger', ['ngCordova.plugins.file'])

} else {

if (!$window.cordova || !$window.cordova.file || !$window.cordova.file.dataDirectory) {
q.reject('cordova.file.dataDirectory is not available');
return q.promise;
}

$cordovaFile.checkFile(cordova.file.dataDirectory, storageFilename).then(function(fileEntry) {
fileEntry.file(q.resolve, q.reject);
}, q.reject);
Expand Down

0 comments on commit 420508b

Please sign in to comment.