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

Adding pause and unpause feature to Tgs #1213

Open
wants to merge 1 commit into
base: master
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
2 changes: 2 additions & 0 deletions src/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"html_options_suspend_on_low_memory_tooltip_line5": { "message": "in den Einstellung für automatisches Tab aussetzen." },
"html_options_suspend_on_low_memory_tooltip_line6": { "message": "Mehr Informationen zu Chromes Verwerfen Funktionalität findest du unter:" },
"html_options_suspend_on_low_memory_tooltip_discarding_link": { "message": "https://developers.google.com/web/updates/2015/09/tab-discarding" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_popup_unsuspend_tab": { "message": "Diesen Tab aufwachen" },
"html_popup_suspend_tab": { "message": "Diesen Tab jetzt aussetzen" },
"html_popup_dont_suspend_now": { "message": "Jetzt nicht aussetzen" },
Expand Down
2 changes: 2 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"html_options_suspend_on_low_memory_tooltip_line5": { "message": "specified in the Automatic tab suspension options." },
"html_options_suspend_on_low_memory_tooltip_line6": { "message": "For more information on Chrome discarding refer to:" },
"html_options_suspend_on_low_memory_tooltip_discarding_link": { "message": "https://developers.google.com/web/updates/2015/09/tab-discarding" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_popup_unsuspend_tab": { "message": "Unsuspend this tab" },
"html_popup_suspend_tab": { "message": "Suspend this tab now" },
"html_popup_dont_suspend_now": { "message": "Don't suspend for now" },
Expand Down
2 changes: 2 additions & 0 deletions src/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"html_options_suspend_on_low_memory_tooltip_line5": { "message": "especificada nas opções de suspensão de guia Automática." },
"html_options_suspend_on_low_memory_tooltip_line6": { "message": "Para mais informações sobre o descarte do Chrome, consulte:" },
"html_options_suspend_on_low_memory_tooltip_discarding_link": { "message": "https://developers.google.com/web/updates/2015/09/tab-discarding" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_popup_unsuspend_tab": { "message": "Recarregar esta guia" },
"html_popup_suspend_tab": { "message": "Suspender esta guia agora" },
"html_popup_dont_suspend_now": { "message": "Não suspender agora" },
Expand Down
2 changes: 2 additions & 0 deletions src/_locales/pt_PT/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"html_options_suspend_on_low_memory_tooltip_line5": { "message": "especificada nas opções de suspensão de guia Automática." },
"html_options_suspend_on_low_memory_tooltip_line6": { "message": "Para mais informações sobre o descarte do Chrome, consulte:" },
"html_options_suspend_on_low_memory_tooltip_discarding_link": { "message": "https://developers.google.com/web/updates/2015/09/tab-discarding" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_popup_unsuspend_tab": { "message": "Recarregar esta guia" },
"html_popup_suspend_tab": { "message": "Suspender esta guia agora" },
"html_popup_dont_suspend_now": { "message": "Não suspender agora" },
Expand Down
2 changes: 2 additions & 0 deletions src/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"html_options_suspend_on_low_memory_tooltip_line5": {"message": "в настройке \"Автоматически приостанавливать вкладки после\"." },
"html_options_suspend_on_low_memory_tooltip_line6": {"message": "Для получения дополнительной информации о механизме выгрузки вкладок Chrome см.:"},
"html_options_suspend_on_low_memory_tooltip_discarding_link": { "message": "https://developers.google.com/web/updates/2015/09/tab-discarding" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_popup_unsuspend_tab": { "message": "Возобновить эту вкладку" },
"html_popup_suspend_tab": { "message": "Приостановить эту вкладку" },
"html_popup_dont_suspend_now": { "message": "Не приостанавливать" },
Expand Down
2 changes: 2 additions & 0 deletions src/_locales/tr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"html_popup_unsuspend_all_tabs": { "message": "Tüm sekmelerin askısını kaldır" },
"html_popup_unsuspend_selected_tabs": { "message": "Seçilen sekmenin askısını kaldır" },
"html_popup_unsuspend_tab": { "message": "Bu sekmenin askısını kaldır" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_recovery_description_line1": { "message": "Uzantının çökmesinden kurtuldunuz gibi görünüyor." },
"html_recovery_description_line2": { "message": "Askıya alınan sekmeleriniz çökmüş veya kaybolmuş olabilir." },
"html_recovery_disable_screen_capturing": { "message": "Ekran görüntüsü yakalama devre dışı" },
Expand Down
2 changes: 2 additions & 0 deletions src/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"html_options_suspend_on_low_memory_tooltip_line5": { "message": "" },
"html_options_suspend_on_low_memory_tooltip_line6": { "message": "有关 automatic tab discarding 的更多信息,请参阅:" },
"html_options_suspend_on_low_memory_tooltip_discarding_link": { "message": "https://developers.google.com/web/updates/2015/09/tab-discarding" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_popup_unsuspend_tab": { "message": "恢复当前标签页" },
"html_popup_suspend_tab": { "message": "冻结此标签页" },
"html_popup_dont_suspend_now": { "message": "现在还不要冻结" },
Expand Down
2 changes: 2 additions & 0 deletions src/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
"html_options_suspend_on_low_memory_tooltip_line5": { "message": "" },
"html_options_suspend_on_low_memory_tooltip_line6": { "message": "有關 Chrome discarding 的更多資訊,請參閱:" },
"html_options_suspend_on_low_memory_tooltip_discarding_link": { "message": "https://developers.google.com/web/updates/2015/09/tab-discarding" },
"html_popup_pause_suspend": { "message": "Pause suspend" },
"html_popup_unpause_suspend": { "message": "Unpause suspend" },
"html_popup_unsuspend_tab": { "message": "回復目前分頁" },
"html_popup_suspend_tab": { "message": "凍結此分頁" },
"html_popup_dont_suspend_now": { "message": "現在還不要凍結" },
Expand Down
20 changes: 20 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var tgs = (function() {
let _isCharging = false;
let _triggerHotkeyUpdate = false;
let _suspensionToggleHotkey;
let _pauseValue = 0;

function getExtensionGlobals() {
const globals = {
Expand Down Expand Up @@ -609,6 +610,23 @@ var tgs = (function() {
delete _tabStateByTabId[tabId];
}

function pauseTgs() {
_pauseValue = gsStorage.getOption(gsStorage.SUSPEND_TIME);
if (_pauseValue === 0) return;

// store current timeout in _pauseValue, and set global timeout to never
gsStorage.setOption(gsStorage.SUSPEND_TIME, 0);
resetAutoSuspendTimerForAllTabs();
}

function unpauseTgs() {
if (_pauseValue === 0) return;

// restore global timeout from value in _pauseValue
gsStorage.setOption(gsStorage.SUSPEND_TIME, _pauseValue);
resetAutoSuspendTimerForAllTabs();
}

function unsuspendTab(tab) {
if (!gsUtils.isSuspendedTab(tab)) return;

Expand Down Expand Up @@ -1868,6 +1886,8 @@ var tgs = (function() {
resetAutoSuspendTimerForAllTabs,
getSuspensionToggleHotkey,

pauseTgs,
unpauseTgs,
unsuspendTab,
unsuspendHighlightedTab,
unwhitelistHighlightedTab,
Expand Down
20 changes: 20 additions & 0 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
});

function setSuspendCurrentVisibility(tabStatus) {
if (gsStorage.getOption(gsStorage.SUSPEND_TIME) > 0) {
document.getElementById('pauseSuspend').style.display = 'block';
document.getElementById('unpauseSuspend').style.display = 'none';
} else {
document.getElementById('pauseSuspend').style.display = 'none';
document.getElementById('unpauseSuspend').style.display = 'block';
}

var suspendOneVisible = ![
gsUtils.STATUS_SUSPENDED,
gsUtils.STATUS_SPECIAL,
Expand Down Expand Up @@ -267,6 +275,18 @@
}

function addClickHandlers() {
document
.getElementById('pauseSuspend')
.addEventListener('click', function() {
tgs.pauseTgs();
window.close();
});
document
.getElementById('unpauseSuspend')
.addEventListener('click', function() {
tgs.unpauseTgs();
window.close();
});
document
.getElementById('unsuspendOne')
.addEventListener('click', function(e) {
Expand Down
8 changes: 8 additions & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
<span id="statusDetail"></span>
</div>
<div id="popupContent">
<div class="group" id="optsEnableDisable">
<div class="menuOption" id="pauseSuspend">
<span class="optionText" data-i18n="__MSG_html_popup_pause_suspend__"></span>
</div>
<div class="menuOption" id="unpauseSuspend">
<span class="optionText" data-i18n="__MSG_html_popup_unpause_suspend__"></span>
</div>
</div>
<div class="group" id="optsCurrent">
<div class="menuOption" id="unsuspendOne">
<span class="optionText" data-i18n="__MSG_html_popup_unsuspend_tab__"></span>
Expand Down