Skip to content

Instantly share code, notes, and snippets.

@meeximum
Created October 3, 2016 19:33
Show Gist options
  • Save meeximum/363bd38948cd95c58ec67c9066ec1a96 to your computer and use it in GitHub Desktop.
Save meeximum/363bd38948cd95c58ec67c9066ec1a96 to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { Platform, ionicBootstrap, AlertController } from 'ionic-angular';
import { StatusBar, AppVersion, Splashscreen } from 'ionic-native';
import { FlipsPage } from './pages/flips';
import {Deploy} from '@ionic/cloud-angular';
import {provideCloud, CloudSettings, DeployDownloadOptions} from '@ionic/cloud-angular';
const cloudSettings: CloudSettings = {
'core': {
'app_id': '26acc044'
}
};
@Component({
template: '<ion-nav [root]="rootPage"></ion-nav>'
})
export class MyApp {
public rootPage: any;
constructor(private platform: Platform, public deploy: Deploy, public alertCtrl: AlertController) {
this.rootPage = FlipsPage;
platform.ready().then(() => {
this.hideSplashScreen();
AppVersion.getVersionNumber().then((version) => {
console.log('Version: ' + version);
});
this.deploy.info().then((info) => {
var actualUuid = info.deploy_uuid;
console.log('Info: ' + JSON.stringify(info));
this.deploy.getSnapshots().then((snapshots) => {
console.log('Snapshots: ' + JSON.stringify(snapshots));
var arrayLength = snapshots.length;
for (var i = 0; i < arrayLength; i++) {
if (snapshots[i] !== actualUuid) {
var snapshot = snapshots[i];
this.deploy.deleteSnapshot(snapshot).then(() => {
console.log('Snapshoot deleted: ' + snapshot);
});
}
}
});
});
// update app if new version is available
this.deploy.check().then((snapshotAvailable: boolean) => {
if (snapshotAvailable) {
let confirm = this.alertCtrl.create({
title: 'Update',
message: 'Es ist eine neue Version vorhanden, soll diese installiert werden?',
buttons: [
{
text: 'Ok',
handler: () => {
this.deploy.download(class extends DeployDownloadOptions {
onProgress(p: number) {
console.log("Progress: " + p);
}
}).then(() => {
console.log('Downloading ...');
this.deploy.extract().then(() => {
console.log('Extracting ...');
this.deploy.load();
}, (extractError) => {
console.log('Error extracting update: ' + extractError);
});
}, (downloadError) => {
console.log('Error downloading update: ' + downloadError);
});
}
},
{
text: 'Später',
handler: () => {
console.log('Install later');
}
}
]
});
confirm.present();
}
});
StatusBar.styleDefault();
});
}
hideSplashScreen() {
if (Splashscreen) {
setTimeout(() => {
Splashscreen.hide();
}, 100);
}
}
}
ionicBootstrap(MyApp, [provideCloud(cloudSettings)]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment