import Controller from '@ember/controller'; import { getOwner } from '@ember/application'; import { inject as service } from '@ember/service'; import { computed } from '@ember/object'; export default Controller.extend({ session: service(), offline: service(), router: service(), fcm: service(), homeNotification: service(), sessionAccount: service(), appVersionCodeData: service(), isShowAppUpdate:false, cordovaEvents: service('ember-cordova/events'), currentRouteName : computed('router.currentRouteName', { get() { let currentRoute = this.get('router').get('currentRouteName'); let currentRouteArr = currentRoute.split("."); currentRoute = currentRouteArr[0]; return currentRoute; } }), isShowAppBar: computed('currentRouteName', { get() { let currentRoute = this.get("currentRouteName"); let routeConfig = _appBarData[currentRoute.split("-").join("")]; let isShowAppBar = false; if (routeConfig != null) { isShowAppBar = routeConfig.showAppBar; } return isShowAppBar; } }), isShowMenu: computed('currentRouteName', { get() { let currentRoute = this.get("currentRouteName"); if (currentRoute == "choose-dealer") { return false; } return true; } }), hasNotification: computed('homeNotification.model', { get() { let result = this.get('homeNotification').get('model').get('hasNotification'); return result; } }), rootClassName: computed('currentRouteName', { get() { } }), init() { this._super(...arguments); this.initFcm(); this.initBackButton(); //this.checkAppVersionNumber(); //this.set('currentPrivilegeInfo', this.sessionAccount.currentPrivilegeUser); }, initBackButton: function() { this.get('cordovaEvents').on('backbutton', this, '_onBackKeyDown'); }, _onBackKeyDown: function(event) { if (window.cordova) { window.history.back(); return; } else { console.log("window"); } }, initFcm: function() { this.get('cordovaEvents').on('deviceready', this, '_initFcm'); }, _initFcm: function() { console.log("fcm _init"); this.fcm.initFcmDaemon(); }, checkAppVersionNumber: function() { this.get('cordovaEvents').on('deviceready', this, '_checkAppVersionNumber'); }, _checkAppVersionNumber: function() { if (window.cordova) { let _this = this; window.cordova.getAppVersion.getVersionNumber(function (version) { _this.appVersionCodeData.getData(1, { adapterOptions: { query : { versionCode : version, platform : window.cordova.platformId } } }).then(result => { if (result.isNeedUpdate) { _this.set("isShowAppUpdate", true); } }); }); } }, actions: { transitionToLoginRoute() { this.transitionToRoute('login'); }, refreshRoute() { let route = getOwner(this).lookup('route:' + this.get('router').get('currentRouteName')); route.controller.set("model", null); route.refresh(); }, logout() { this.get('session').invalidate(); }, closePopup() { this.set("isShowAppUpdate", false); }, goToStore() { this.set("isShowAppUpdate", false); if (window.cordova) { let appId = "com.hino.newhearts"; if (window.cordova.platformId == "ios") { appId = "id1527053331"; } window.cordova.plugins.market.open(appId); } } } });