Browse Source

Fixed app reload for packaged app

master
Igor Zhukov 10 years ago
parent
commit
f141abe049
  1. 8
      app/js/controllers.js
  2. 28
      app/js/lib/ng_utils.js
  3. 14
      app/js/services.js

8
app/js/controllers.js

@ -305,7 +305,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
ChangelogNotifyService.checkUpdate(); ChangelogNotifyService.checkUpdate();
}) })
.controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, ContactsSelectService, ChangelogNotifyService, ErrorService) { .controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager) {
$scope.$on('$routeUpdate', updateCurDialog); $scope.$on('$routeUpdate', updateCurDialog);
@ -382,7 +382,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
ErrorService.confirm({type: 'LOGOUT'}).then(function () { ErrorService.confirm({type: 'LOGOUT'}).then(function () {
MtpApiManager.logOut().then(function () { MtpApiManager.logOut().then(function () {
location.hash = '/login'; location.hash = '/login';
location.reload(); AppRuntimeManager.reload();
}); });
}) })
}; };
@ -1455,7 +1455,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
}) })
.controller('AppLangFooterController', function ($scope, _, Storage, ErrorService) { .controller('AppLangFooterController', function ($scope, _, Storage, ErrorService, AppRuntimeManager) {
$scope.supportedLocales = Config.I18n.supported; $scope.supportedLocales = Config.I18n.supported;
$scope.langNames = Config.I18n.languages; $scope.langNames = Config.I18n.languages;
$scope.curLocale = Config.I18n.locale; $scope.curLocale = Config.I18n.locale;
@ -1464,7 +1464,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
Storage.set({i18n_locale: newLocale}); Storage.set({i18n_locale: newLocale});
if ($scope.curLocale !== newLocale) { if ($scope.curLocale !== newLocale) {
ErrorService.confirm({type: 'APPLY_LANG_WITH_RELOAD'}).then(function () { ErrorService.confirm({type: 'APPLY_LANG_WITH_RELOAD'}).then(function () {
location.reload(); AppRuntimeManager.reload();
}); });
} }
}; };

28
app/js/lib/ng_utils.js

@ -569,6 +569,34 @@ angular.module('izhukov.utils', [])
}; };
}) })
.service('AppRuntimeManager', function ($window) {
return {
reload: function () {
try {
location.reload();
} catch (e) {};
if ($window.chrome && chrome.runtime && chrome.runtime.reload) {
chrome.runtime.reload();
};
},
focus: function () {
if (window.navigator.mozApps && document.hidden) {
// Get app instance and launch it to bring app to foreground
window.navigator.mozApps.getSelf().onsuccess = function() {
this.result.launch();
};
} else {
if (window.chrome && chrome.app && chrome.app.window) {
chrome.app.window.current().focus();
}
window.focus();
}
}
}
})

14
app/js/services.js

@ -3448,7 +3448,7 @@ angular.module('myApp.services', ['myApp.i18n'])
}) })
.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, MtpApiManager, AppPeersManager, IdleManager, Storage) { .service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, MtpApiManager, AppPeersManager, IdleManager, Storage, AppRuntimeManager) {
navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate; navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate;
@ -3647,17 +3647,7 @@ angular.module('myApp.services', ['myApp.i18n'])
notification.onclick = function () { notification.onclick = function () {
notification.close(); notification.close();
if (window.navigator.mozApps && document.hidden) { AppRuntimeManager.focus();
// Get app instance and launch it to bring app to foreground
window.navigator.mozApps.getSelf().onsuccess = function() {
this.result.launch();
};
} else {
if (window.chrome && chrome.app && chrome.app.window) {
chrome.app.window.current().focus();
}
window.focus();
}
notificationsClear(); notificationsClear();
if (data.onclick) { if (data.onclick) {
data.onclick(); data.onclick();

Loading…
Cancel
Save