Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call ForceSync on app resume #797

Open
wants to merge 1 commit into
base: single_tenant_app_snapshot_unmaintained
Choose a base branch
from
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
18 changes: 17 additions & 1 deletion www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ angular.module('emission', ['ionic',
'emission.controllers','emission.services', 'emission.plugin.logger',
'emission.splash.customURLScheme', 'emission.splash.referral',
'emission.splash.updatecheck', 'emission.services.email',
'emission.main.control.sync',
'emission.intro', 'emission.main',
'pascalprecht.translate'])

.run(function($ionicPlatform, $rootScope, $http, Logger,
CustomURLScheme, ReferralHandler, UpdateCheck) {
CustomURLScheme, ReferralHandler, UpdateCheck, ControlSyncHelper) {
console.log("Starting run");
// alert("Starting run");
// BEGIN: Global listeners, no need to wait for the platform
Expand All @@ -34,6 +35,15 @@ angular.module('emission', ['ionic',
}
});
// END: Global listeners
let autoForceSync = function() {
if ($ionicPlatform.is("android")) {
console.log("app has started/resumed, forcing sync on android");
ControlSyncHelper.forceSync().then(function() {
ClientStats.addEvent(ClientStats.getStatKeys().RESUME_FORCE_SYNC);
});
}
};

$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
Expand Down Expand Up @@ -68,7 +78,13 @@ angular.module('emission', ['ionic',
});
});
cordova.plugin.http.setDataSerializer('json');
autoForceSync();
});

$ionicPlatform.on("resume", function() {
autoForceSync();
});

console.log("Ending run");
})

Expand Down
3 changes: 2 additions & 1 deletion www/js/stats/clientstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ angular.module('emission.stats.clientstats', [])
INF_SCROLL_TIME: "inf_scroll_time",
VERIFY_TRIP: "verify_trip",
LABEL_TAB_SWITCH: "label_tab_switch",
SELECT_LABEL: "select_label"
SELECT_LABEL: "select_label",
RESUME_FORCE_SYNC: "resume_force_sync"
};
}

Expand Down