diff --git a/Gruntfile.js b/Gruntfile.js
index 0bc34bf..2ef099c 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -89,13 +89,25 @@ module.exports = function (grunt) {
root: "./"
},
src: [
- 'app/*.js',
- 'lib/*.js',
'css/*.css',
+ 'lib/*.js',
+ 'app/*.js',
'templates/*.html'
],
dest: ['manifest.json']
}
+ },
+ processhtml: {
+ options: {
+ data: {
+ message: 'Deleting includes for hot push code.'
+ }
+ },
+ hotpush: {
+ files: {
+ '../www/index.html': ['../www/index.html']
+ }
+ }
}
});
@@ -109,7 +121,8 @@ module.exports = function (grunt) {
'filerev',
'usemin',
'jsonmanifest',
- 'copy:manifest'
+ 'copy:manifest',
+ 'processhtml:hotpush'
]);
grunt.loadNpmTasks('grunt-usemin');
@@ -119,6 +132,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-filerev');
grunt.loadNpmTasks('grunt-ng-annotate');
+ grunt.loadNpmTasks('grunt-processhtml');
grunt.file.setBase('app');
diff --git a/README.md b/README.md
index 4a5bcb7..b45808f 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,9 @@
+* cordova platform add ios/android
+* cordova plugin add org.apache.cordova.file
+* cordova plugin add org.apache.cordova.file-transfer
* npm install
* bower install
* grunt build
+* ionic run ios/android
* node_modules/http-server/bin/http-server www --cors -c-1
+
diff --git a/app/index.html b/app/index.html
index 407241c..86a3680 100644
--- a/app/index.html
+++ b/app/index.html
@@ -5,27 +5,32 @@
-
+
+
-
+
+
+
+
+
diff --git a/app/js/app.js b/app/js/app.js
index 198e0cc..531301e 100644
--- a/app/js/app.js
+++ b/app/js/app.js
@@ -4,7 +4,7 @@
// 'starter' is the name of this angular module example (also set in a attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
-angular.module('starter', ['ionic', 'starter.controllers'])
+angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(['$ionicPlatform', function ($ionicPlatform) {
@@ -23,7 +23,7 @@ angular.module('starter', ['ionic', 'starter.controllers'])
});
}])
- .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
+ .config(['$stateProvider', '$urlRouterProvider', '$httpProvider', function ($stateProvider, $urlRouterProvider, $httpProvider) {
$stateProvider
.state('app', {
@@ -71,4 +71,20 @@ angular.module('starter', ['ionic', 'starter.controllers'])
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/playlists');
+ // config hot push code http interceptor
+ $httpProvider.interceptors.push(['UpdateService', function (UpdateService) {
+ return {
+ 'request': function (config) {
+ if (UpdateService.isFileCached(config.url)) {
+
+ var url = UpdateService.getCachedUrl(config.url);
+ config.url = url;
+ }
+ return config;
+ },
+ 'response': function (response) {
+ return response;
+ }
+ };
+ }]);
}]);
diff --git a/app/js/controllers.js b/app/js/controllers.js
index 2f5223f..a33eba9 100644
--- a/app/js/controllers.js
+++ b/app/js/controllers.js
@@ -1,6 +1,6 @@
angular.module('starter.controllers', [])
- .controller('AppCtrl', ['$scope', '$ionicModal', '$timeout', '$q', function ($scope, $ionicModal, $timeout, $q) {
+ .controller('AppCtrl', ['$scope', '$ionicModal', '$timeout', '$q', 'UpdateService', function ($scope, $ionicModal, $timeout, $q, UpdateService) {
// Form data for the login modal
$scope.loginData = {};
// Create the login modal that we will use later
@@ -27,35 +27,31 @@ angular.module('starter.controllers', [])
}, 1000);
};
$scope.checkUpdate = function () {
- var fs = new CordovaPromiseFS({
- Promise: $q
- });
- // Initialize a CordovaAppLoader
- var loader = new CordovaAppLoader({
- fs: fs,
- serverRoot: 'http://192.168.188.46:8080/',
- localRoot: 'app',
- cacheBuster: true, // make sure we're not downloading cached files.
- checkTimeout: 10000 // timeout for the "check" function - when you loose internet connection
- });
- loader.check().then(function (updateAvailable) {
- console.log(updateAvailable);
- if (updateAvailable)
- {
- loader.download(onprogress)
- .then(
- function (manifest)
- {
- console.log(manifest);
- loader.update();
- },
- function (failedDownloadUrlArray)
- {
- console.log(failedDownloadUrlArray);
- }
- )
- }
- });
+ var check = UpdateService.check();
+ check.
+ then(function(result) {
+ if(result === true) {
+ console.log('update available');
+ var download = UpdateService.download();
+ download.then(
+ function(manifest) {
+ console.log('manifest.....:');
+ console.log(JSON.stringify(manifest));
+ UpdateService.update();
+ },
+ function(error) {
+ console.log('error....: ');
+ console.log(JSON.stringify(error));
+ }
+ );
+ } else {
+ console.log('not update available');
+ }
+ },
+ function(error){
+ console.log('no update available');
+ console.log(JSON.stringify(error));
+ });
}
}
])
@@ -64,10 +60,14 @@ angular.module('starter.controllers', [])
$scope.playlists = [
{title: 'Reggae2', id: 1},
{title: 'Chill3', id: 2},
- {title: 'Dubstepfdsfd', id: 3},
+ {title: 'Dubstep', id: 3},
{title: 'Indie', id: 4},
{title: 'Rap', id: 5},
- {title: 'Cowbell', id: 6}
+ {title: 'Cowbell', id: 6},
+ {title: 'Techno', id: 7},
+ {title: 'Swing', id: 8},
+ {title: 'Jazz', id: 9},
+ {title: 'Hip Hop', id: 10}
];
}])
diff --git a/app/js/services.js b/app/js/services.js
new file mode 100644
index 0000000..26794e6
--- /dev/null
+++ b/app/js/services.js
@@ -0,0 +1,86 @@
+angular.module('starter.services', [])
+
+ .factory('UpdateService', ['$log', 'ConfigService', '$q', function ($log, ConfigService, $q) {
+ var fs = new CordovaPromiseFS({
+ Promise: Promise
+ });
+
+ var loader = new CordovaAppLoader({
+ fs: fs,
+ serverRoot: 'http://'+ConfigService.getHost()+':'+ConfigService.getPort(),
+ localRoot: 'app',
+ cacheBuster: true, // make sure we're not downloading cached files.
+ checkTimeout: 10000, // timeout for the "check" function - when you loose internet connection
+ mode: 'mirror',
+ manifest: 'manifest.json' + "?" + Date.now()
+ });
+ var service = {
+ // Check for new updates on js and css files
+ check: function () {
+
+ var defer = $q.defer();
+ loader.check().then(function (updateAvailable) {
+ console.log("Update available:");
+ if (updateAvailable) {
+ defer.resolve(updateAvailable);
+ }
+ else {
+ defer.reject(updateAvailable);
+ }
+ });
+
+ return defer.promise;
+ },
+ // Download new js/css files
+ download: function (onprogress) {
+ var defer = $q.defer();
+
+ loader.download(onprogress).then(function (manifest) {
+ console.log("Download active!");
+ defer.resolve(manifest);
+ }, function (error) {
+ console.log("Download Error:");
+ defer.reject(error);
+ });
+ return defer.promise;
+ },
+ // Update the local files with a new version just downloaded
+ update: function (reload) {
+ console.log("update files--------------");
+ return loader.update(reload);
+ },
+ // Check wether the HTML file is cached
+ isFileCached: function (file) {
+ if (angular.isDefined(loader.cache)) {
+ return loader.cache.isCached(file);
+ }
+ return false;
+ },
+ // returns the cached HTML file as a url for HTTP interceptor
+ getCachedUrl : function (url) {
+ if(angular.isDefined(loader.cache)) {
+ return loader.cache.get(url);
+ }
+ return url;
+ }
+ };
+
+ return service;
+ }])
+
+ .factory('ConfigService', [function() {
+ var hostURL = "192.168.3.163";
+ var hostPort = 8080;
+
+ var service = {
+ getHost : function () {
+ return hostURL;
+ },
+
+ getPort : function () {
+ return hostPort;
+ }
+ }
+ return service;
+ }]);
+
\ No newline at end of file
diff --git a/app/lib/cordova-app-loader/dist/bootstrap.js b/app/lib/cordova-app-loader/dist/bootstrap.js
index f2d08d2..006d701 100644
--- a/app/lib/cordova-app-loader/dist/bootstrap.js
+++ b/app/lib/cordova-app-loader/dist/bootstrap.js
@@ -68,7 +68,7 @@ function loadManifest(manifest,fromLocalStorage,timeout){
el.src= src + '?' + now;
el.async = false;
// Load CSS
- } else {
+ } else if(src.substr(-4) === ".css"){
el= document.createElement('link');
el.rel = "stylesheet";
el.href = src + '?' + now;
diff --git a/bower.json b/bower.json
index cf2080b..3c764b0 100644
--- a/bower.json
+++ b/bower.json
@@ -2,8 +2,8 @@
"name": "loaderApp",
"private": "true",
"devDependencies": {
- "ionic": "driftyco/ionic-bower#1.0.0-beta.14",
- "cordova-app-loader": "~0.14.0",
- "cordova-promise-fs": "~0.10.0"
+ "ionic": "driftyco/ionic-bower#1.0.0-rc.2",
+ "cordova-app-loader": "~0.17.0",
+ "cordova-promise-fs": "~0.12.0"
}
}
diff --git a/package.json b/package.json
index c38810a..0a8cf3a 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"grunt-contrib-uglify": "^0.8.0",
"grunt-filerev": "^2.1.2",
"grunt-ng-annotate": "^0.10.0",
+ "grunt-processhtml": "^0.3.7",
"grunt-usemin": "^3.0.0",
"gulp-util": "^2.2.14",
"http-server": "^0.7.4",
@@ -25,6 +26,12 @@
},
"cordovaPlugins": [
"org.apache.cordova.file",
- "org.apache.cordova.file-transfer"
+ "org.apache.cordova.file-transfer",
+ "com.ionic.keyboard",
+ "org.apache.cordova.console",
+ "org.apache.cordova.device"
+ ],
+ "cordovaPlatforms": [
+ "android"
]
-}
\ No newline at end of file
+}