Added new page for multiple tabs

This commit is contained in:
Igor Zhukov 2015-10-21 15:59:34 +02:00
parent 287a35eea6
commit 9dde343d98
6 changed files with 118 additions and 31 deletions

BIN
app/img/Manytabs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -698,13 +698,13 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
}; };
}) })
.service('MtpSingleInstanceService', function (_, $rootScope, $interval, Storage, AppRuntimeManager, IdleManager, ErrorService, MtpNetworkerFactory) { .service('MtpSingleInstanceService', function (_, $rootScope, $compile, $timeout, $interval, $modalStack, Storage, AppRuntimeManager, IdleManager, ErrorService, MtpNetworkerFactory) {
var instanceID = nextRandomInt(0xFFFFFFFF); var instanceID = nextRandomInt(0xFFFFFFFF);
var started = false; var started = false;
var masterInstance = false; var masterInstance = false;
var startTime = tsNow(); var deactivatePromise = false;
var errorShowTime = 0; var deactivated = false;
function start() { function start() {
if (!started && !Config.Navigator.mobile && !Config.Modes.packed) { if (!started && !Config.Navigator.mobile && !Config.Modes.packed) {
@ -712,7 +712,6 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
IdleManager.start(); IdleManager.start();
startTime = tsNow();
$rootScope.$watch('idle.isIDLE', checkInstance); $rootScope.$watch('idle.isIDLE', checkInstance);
$interval(checkInstance, 5000); $interval(checkInstance, 5000);
checkInstance(); checkInstance();
@ -727,7 +726,38 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
Storage.remove(masterInstance ? 'xt_instance' : 'xt_idle_instance'); Storage.remove(masterInstance ? 'xt_instance' : 'xt_idle_instance');
} }
function deactivateInstance () {
if (masterInstance || deactivated) {
return false;
}
console.log(dT(), 'deactivate');
deactivatePromise = false;
deactivated = true;
clearInstance();
$modalStack.dismissAll();
document.title = _('inactive_tab_title_raw');
var inactivePageCompiled = $compile('<ng-include src="\'partials/desktop/inactive.html\'"></ng-include>');
var scope = $rootScope.$new(true);
scope.close = function () {
AppRuntimeManager.close();
};
scope.reload = function () {
AppRuntimeManager.reload();
};
inactivePageCompiled(scope, function (clonedElement) {
$('.page_wrap').hide();
$(clonedElement).appendTo($('body'));
});
$rootScope.idle.deactivated = true;
}
function checkInstance() { function checkInstance() {
if (deactivated) {
return false;
}
var time = tsNow(); var time = tsNow();
var idle = $rootScope.idle && $rootScope.idle.isIDLE; var idle = $rootScope.idle && $rootScope.idle.isIDLE;
var newInstance = {id: instanceID, idle: idle, time: time}; var newInstance = {id: instanceID, idle: idle, time: time};
@ -736,38 +766,36 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
var curInstance = result[0], var curInstance = result[0],
idleInstance = result[1]; idleInstance = result[1];
if (!curInstance || // console.log(dT(), 'check instance', newInstance, curInstance, idleInstance);
curInstance.time < time - 60000 || if (!idle ||
!curInstance ||
curInstance.id == instanceID || curInstance.id == instanceID ||
curInstance.idle || curInstance.time < time - 60000) {
!idle) {
if (idleInstance) { if (idleInstance &&
if (idleInstance.id == instanceID) { idleInstance.id == instanceID) {
Storage.remove('xt_idle_instance'); Storage.remove('xt_idle_instance');
}
else if (idleInstance.time > time - 10000 &&
time > errorShowTime) {
ErrorService.alert(
_('error_modal_warning_title_raw'),
_('error_modal_multiple_open_tabs_raw')
);
errorShowTime += tsNow() + 60000;
}
} }
Storage.set({xt_instance: newInstance}); Storage.set({xt_instance: newInstance});
if (!masterInstance) { if (!masterInstance) {
MtpNetworkerFactory.startAll(); MtpNetworkerFactory.startAll();
console.warn(dT(), 'now master instance', newInstance);
} }
masterInstance = true; masterInstance = true;
if (deactivatePromise) {
$timeout.cancel(deactivatePromise);
deactivatePromise = false;
}
} else { } else {
Storage.set({xt_idle_instance: newInstance}); Storage.set({xt_idle_instance: newInstance});
if (masterInstance) { if (masterInstance) {
MtpNetworkerFactory.stopAll(); MtpNetworkerFactory.stopAll();
console.warn(dT(), 'now idle instance', newInstance);
if (!deactivatePromise) {
deactivatePromise = $timeout(deactivateInstance, 30000);
}
} }
masterInstance = false; masterInstance = false;
} }
}); });
} }

View File

@ -360,7 +360,6 @@
"error_modal_flood_description": "You are performing too many actions. Please try again later.", "error_modal_flood_description": "You are performing too many actions. Please try again later.",
"error_modal_internal_description": "Internal server error occured. Please try again later.", "error_modal_internal_description": "Internal server error occured. Please try again later.",
"error_modal_tech_details": "Technical details here", "error_modal_tech_details": "Technical details here",
"error_modal_multiple_open_tabs": "Please close other Telegram app tabs.",
"error_modal_recovery_na_description": "Since you haven't provided a recovery e-mail when setting up your password, your remaining options are either to remember your password or to reset your account.", "error_modal_recovery_na_description": "Since you haven't provided a recovery e-mail when setting up your password, your remaining options are either to remember your password or to reset your account.",
"error_modal_password_success_descripion": "Your password for Two-Step Verification is now active.", "error_modal_password_success_descripion": "Your password for Two-Step Verification is now active.",
"error_modal_password_disabled_descripion": "You have disabled Two-Step Verification.", "error_modal_password_disabled_descripion": "You have disabled Two-Step Verification.",
@ -531,6 +530,12 @@
"phonebook_modal_submit_active": "Importing", "phonebook_modal_submit_active": "Importing",
"phonebook_modal_submit": "Import contacts", "phonebook_modal_submit": "Import contacts",
"inactive_tab_title": "Telegram: Zzz...",
"inactive_title": "Such error, many tabs",
"inactive_description_md": "Telegram supports only one active tab with the app.\nPlease reload this page to continue using this tab or close it",
"inactive_reload_btn": "Reload App",
"country_select_modal_country_ab": "Abkhazia", "country_select_modal_country_ab": "Abkhazia",
"country_select_modal_country_af": "Afghanistan", "country_select_modal_country_af": "Afghanistan",
"country_select_modal_country_ax": "Åland Islands", "country_select_modal_country_ax": "Åland Islands",

View File

@ -2908,13 +2908,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var titleBackup = document.title, var titleBackup = document.title,
titleChanged = false, titleChanged = false,
titleCnt = 0,
titlePromise; titlePromise;
var prevFavicon; var prevFavicon;
var stopped = false;
var settings = {}; var settings = {};
$rootScope.$watch('idle.deactivated', function (newVal) {
if (newVal) {
stop();
}
});
$rootScope.$watch('idle.isIDLE', function (newVal) { $rootScope.$watch('idle.isIDLE', function (newVal) {
if (stopped) {
return;
}
if (!newVal) { if (!newVal) {
notificationsClear(); notificationsClear();
} }
@ -2928,12 +2937,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
titleBackup = document.title; titleBackup = document.title;
titlePromise = $interval(function () { titlePromise = $interval(function () {
if (!notificationsCount || ((titleCnt++) % 2)) { if (titleChanged || !notificationsCount) {
if (titleChanged) { titleChanged = false;
titleChanged = false; document.title = titleBackup;
document.title = titleBackup; setFavicon();
setFavicon();
}
} else { } else {
titleChanged = true; titleChanged = true;
document.title = langNotificationsPluralize(notificationsCount); document.title = langNotificationsPluralize(notificationsCount);
@ -3028,7 +3035,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
faviconEl.parentNode.replaceChild(link, faviconEl); faviconEl.parentNode.replaceChild(link, faviconEl);
faviconEl = link; faviconEl = link;
prevFavicon = href prevFavicon = href;
} }
function savePeerSettings (peerID, settings) { function savePeerSettings (peerID, settings) {
@ -3080,12 +3087,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} catch (e) {} } catch (e) {}
} }
function stop () {
notificationsClear();
$interval.cancel(titlePromise);
setFavicon();
stopped = true;
}
function requestPermission() { function requestPermission() {
Notification.requestPermission(); Notification.requestPermission();
$($window).off('click', requestPermission); $($window).off('click', requestPermission);
} }
function notify (data) { function notify (data) {
if (stopped) {
return;
}
// console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport); // console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport);
// FFOS Notification blob src bug workaround // FFOS Notification blob src bug workaround

View File

@ -4118,6 +4118,30 @@ a.countries_modal_search_clear {
} }
} }
.inactive_page_content {
max-width: 400px;
margin: 0 auto;
text-align: center;
}
.inactive_image {
display: block;
background: url(../img/Manytabs.png) no-repeat 0 0;
width: 341px;
height: 262px;
margin: 0 auto;
}
.inactive_title {
font-size: 18px;
color: #444444;
}
.inactive_description {
color: #666666;
font-size: 15px;
line-height: 150%;
}
.inactive_actions {
margin-top: 15px;
}
@media print { @media print {

View File

@ -0,0 +1,13 @@
<div class="inactive_page_wrap">
<div class="tg_head_split inactive_head"></div>
<div class="im_page_wrap">
<div class="inactive_page_content" my-vertical-position="0.35">
<a class="inactive_image" ng-click="reload()"></a>
<h3 class="inactive_title" my-i18n="inactive_title"></h3>
<div class="inactive_description" my-i18n="inactive_description_md"></div>
<div class="inactive_actions">
<button class="btn btn-lg btn-md btn-md-primary" ng-click="reload()" my-i18n="inactive_reload_btn" my-focused></button>
</div>
</div>
</div>
</div>