Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
}
}
});

Expand All @@ -109,7 +121,8 @@ module.exports = function (grunt) {
'filerev',
'usemin',
'jsonmanifest',
'copy:manifest'
'copy:manifest',
'processhtml:hotpush'
]);

grunt.loadNpmTasks('grunt-usemin');
Expand All @@ -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');


Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

9 changes: 7 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>


<!-- build:remove -->
<!-- build:css css/app-css.css -->
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- endbuild -->
<!-- /build -->




<!-- build:remove -->
<!-- build:js lib/vendor-lib.js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- endbuild -->
<!-- /build -->

<script src="cordova.js"></script>
<script src="lib/cordova-app-loader/dist/cordova-app-loader-complete.js"></script>
<script type="text/javascript" timeout="5000" manifest="manifest.json" src="lib/cordova-app-loader/dist/bootstrap.js"></script>

<!-- build:remove -->
<!-- build:js app/my-app.js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<!-- endbuild -->
<!-- /build -->
</head>

<body ng-app="starter">
Expand Down
20 changes: 18 additions & 2 deletions app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 'starter' is the name of this angular module example (also set in a <body> 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) {

Expand All @@ -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', {
Expand Down Expand Up @@ -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;
}
};
}]);
}]);
64 changes: 32 additions & 32 deletions app/js/controllers.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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));
});
}
}
])
Expand All @@ -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}
];
}])

Expand Down
86 changes: 86 additions & 0 deletions app/js/services.js
Original file line number Diff line number Diff line change
@@ -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;
}]);

2 changes: 1 addition & 1 deletion app/lib/cordova-app-loader/dist/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
"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",
"shelljs": "^0.3.0"
},
"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"
]
}
}