Commit ae122e44 authored by laurent l's avatar laurent l

use plugin nativescript-background-fetch

parent a88a4ae0
......@@ -32,11 +32,14 @@ global.__onLiveSyncCore = myReloadPage;
Database.open('prod');
new BackgroundJobs().setupScheduleJob(Database.current())
new BackgroundJobs().setupScheduleJob(app)
let manager = new Manager(config.MANAGER_URL, new NSHTTPClient())
app.start({
moduleName: 'views/accounts/list-page',
bindingContext: new AccountsController(manager)
})
import { UpdateAccountsJob } from './models/background-jobs/update-accounts-job'
new UpdateAccountsJob().setup()
declare var fr: any;
import { Database, Portal, Account } from '../models/'
import * as utils from 'utils/utils'
import * as ApplicationSettings from "tns-core-modules/application-settings"
android.app.job.JobService.extend("fr.afi_sa.MyBibApp.RefreshAccountsService", {
onStartJob: function(params:android.app.job.JobParameters):boolean {
if (!ApplicationSettings.getBoolean('background_refresh_on', false)) {
android.util.Log.d('MyBibApp', 'background refresh disabled')
this.jobFinished(params, true)
return true
}
let portal = new Portal()
let accounts = Database.current().findAll(Account)
accounts.reduce(
(promise: Promise<any>, account: Account) => {
return promise.then( ()=> {
android.util.Log.d('MyBibApp', 'refresh account: ' + account.label)
return portal.refresh(account).catch( (error) => {
android.util.Log.e('MyBibApp', error.message)
})
})
},
Promise.resolve())
.then( () => {
android.util.Log.d('MyBibApp', 'refresh accounts finished')
this.jobFinished(params, true);
})
return true
},
onStopJob: function(params:android.app.job.JobParameters):boolean {
this.jobFinished(params, false)
return true;
}
})
export class BackgroundJobs {
public setupScheduleJob(database: Database) {
let context = utils.ad.getApplicationContext()
let component = new android.content.ComponentName(context, fr.afi_sa.MyBibApp.RefreshAccountsService.class)
const builder = new (<any>android.app).job.JobInfo.Builder(1, component)
builder.setPeriodic(20 * 60 * 1000)
builder.setPersisted(true)
const jobScheduler = context.getSystemService((<any>android.content.Context).JOB_SCHEDULER_SERVICE)
console.log("Job Scheduled: " + jobScheduler.schedule(builder.build()))
return this
}
}
import { Database } from '../models/'
export declare class BackgroundJobs {
public setupScheduleJob(database: Database): this
}
import { Database } from '../models/'
export class BackgroundJobs {
public setupScheduleJob(database: Database) {
}
}
    
export {Persistable, Serializable, DataSource} from './persistable';
export {Database} from './database';
export {Account} from './account';
export {ItemOperation} from './item-operation';
export {Loan} from './loan';
export {Hold} from './hold';
export {Portal} from './portal';
export {HTTPClient} from './http/http-client';
export {NSHTTPClient} from './http/ns-http-client';
export {NullHTTPClient} from './http/null-http-client';
export {PortalAdapter} from './portal/adapter';
export {OAuthTokenNotSet} from './portal/oauth-token-not-set';
export {WrongLoginPassword} from './portal/wrong-login-password';
export {PortalDetectionFail} from './portal/portal-detection-fail';
export {Cookies} from './cookies/cookies';
export {Manager, MBPortal} from './manager';
export {Record} from './record';
export {Item} from './item';
export {Novelties} from './novelties';
export {Card} from './card';
export {Iso8601Date} from './iso8601_date';
export {BackgroundJobs} from './background-jobs';
export {Form} from './form';
export { Persistable, Serializable, DataSource } from './persistable';
export { Database } from './database';
export { Account } from './account';
export { ItemOperation } from './item-operation';
export { Loan } from './loan';
export { Hold } from './hold';
export { Portal } from './portal';
export { HTTPClient } from './http/http-client';
export { NSHTTPClient } from './http/ns-http-client';
export { NullHTTPClient } from './http/null-http-client';
export { PortalAdapter } from './portal/adapter';
export { OAuthTokenNotSet } from './portal/oauth-token-not-set';
export { WrongLoginPassword } from './portal/wrong-login-password';
export { PortalDetectionFail } from './portal/portal-detection-fail';
export { Cookies } from './cookies/cookies';
export { Manager, MBPortal } from './manager';
export { Record } from './record';
export { Item } from './item';
export { Novelties } from './novelties';
export { Card } from './card';
export { Iso8601Date } from './iso8601_date';
export { BackgroundJobs } from './background-jobs/background-jobs';
export { Form } from './form';
......@@ -21,6 +21,7 @@
"jstoxml": "^1.4.3",
"nativescript-android-utils": "^1.0.2",
"nativescript-appversion": "^1.4.1",
"nativescript-background-fetch": "^1.2.1",
"nativescript-barcodescanner": "^2.7.7",
"nativescript-couchbase": "git+https://github.com/Afibre/nativescript-couchbase.git",
"nativescript-i18n": "^0.2.4",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment