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

manifest-v3 #1359

Closed
Closed
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
12 changes: 6 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ module.exports = function(grunt) {
grunt.registerTask('default', [
'copy',
'string-replace:debugoff',
'crx:public',
'crx:private',
'clean',
// 'crx:public',
// 'crx:private',
// 'clean',
]);
grunt.registerTask('tgut', [
'copy',
'string-replace:debugon',
'string-replace:localesTgut',
'crx:public',
'crx:private',
'clean',
// 'crx:public',
// 'crx:private',
// 'clean',
]);
};
2 changes: 1 addition & 1 deletion src/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ext_extension_name": { "message": "The Great Suspender" },
"ext_extension_name": { "message": "The Great SAFE Suspender" },
"ext_extension_description": { "message": "Make your computer run smoothly by suspending the tabs you aren't using" },
"ext_default_title": { "message": "The Great Suspender" },
"ext_cmd_toggle_tab_suspension_description": { "message": "Suspend/Unsuspend active tab" },
Expand Down
4 changes: 1 addition & 3 deletions src/js/about.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global chrome, XMLHttpRequest, gsStorage, gsAnalytics, gsUtils */
/* global chrome, gsStorage, gsUtils */
(function(global) {
'use strict';

Expand All @@ -23,6 +23,4 @@
);
}
});

gsAnalytics.reportPageView('about.html');
})(this);
109 changes: 2 additions & 107 deletions src/js/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global gsStorage, gsChrome, gsIndexedDb, gsUtils, gsFavicon, gsSession, gsMessages, gsTabSuspendManager, gsTabDiscardManager, gsAnalytics, gsTabCheckManager, gsSuspendedTab, chrome, XMLHttpRequest */
/* global gsStorage, gsChrome, gsIndexedDb, gsUtils, gsFavicon, gsSession, gsMessages, gsTabSuspendManager, gsTabDiscardManager, gsTabCheckManager, gsSuspendedTab, chrome */
/*
* The Great Suspender
* Copyright (C) 2017 Dean Oemcke
Expand Down Expand Up @@ -33,9 +33,7 @@ var tgs = (function() {
const STATE_SCROLL_POS = 'scrollPos';

const focusDelay = 500;
const noticeCheckInterval = 1000 * 60 * 60 * 12; // every 12 hours
const sessionMetricsCheckInterval = 1000 * 60 * 15; // every 15 minutes
const analyticsCheckInterval = 1000 * 60 * 60 * 23.5; // every 23.5 hours

const _tabStateByTabId = {};
const _currentFocusedTabIdByWindowId = {};
Expand All @@ -46,7 +44,6 @@ var tgs = (function() {
let _sessionSaveTimer;
let _newTabFocusTimer;
let _newWindowFocusTimer;
let _noticeToDisplay;
let _isCharging = false;
let _triggerHotkeyUpdate = false;
let _suspensionToggleHotkey;
Expand All @@ -56,7 +53,6 @@ var tgs = (function() {
tgs,
gsUtils,
gsChrome,
gsAnalytics,
gsStorage,
gsIndexedDb,
gsMessages,
Expand Down Expand Up @@ -142,9 +138,7 @@ var tgs = (function() {
}

function startTimers() {
startNoticeCheckerJob();
startSessionMetricsJob();
startAnalyticsUpdateJob();
}

function getInternalViewByTabId(tabId) {
Expand Down Expand Up @@ -1183,77 +1177,6 @@ var tgs = (function() {
});
}

function checkForNotices() {
gsUtils.log('background', 'Checking for notices..');
var xhr = new XMLHttpRequest();
var lastShownNoticeVersion = gsStorage.fetchNoticeVersion();

xhr.open('GET', 'https://greatsuspender.github.io/notice.json', true);
xhr.timeout = 4000;
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.responseText) {
var resp;
try {
resp = JSON.parse(xhr.responseText);
} catch (e) {
gsUtils.error(
'background',
'Failed to parse notice response',
xhr.responseText
);
return;
}

if (!resp || !resp.active || !resp.text) {
gsUtils.log('background', 'No new notice found');
return;
}

//only show notice if it is intended for this extension version
var noticeTargetExtensionVersion = String(resp.target);
if (
noticeTargetExtensionVersion !== chrome.runtime.getManifest().version
) {
gsUtils.log(
'background',
`Notice target extension version: ${noticeTargetExtensionVersion}
does not match actual extension version: ${
chrome.runtime.getManifest().version
}`
);
return;
}

//only show notice if it has not already been shown
var noticeVersion = String(resp.version);
if (noticeVersion <= lastShownNoticeVersion) {
gsUtils.log(
'background',
`Notice version: ${noticeVersion} is not greater than last shown notice version: ${lastShownNoticeVersion}`
);
return;
}

//show notice - set global notice field (so that it can be trigger to show later)
_noticeToDisplay = resp;
gsAnalytics.reportEvent(
'Notice',
'Prep',
resp.target + ':' + resp.version
);
}
};
xhr.send();
}

function requestNotice() {
return _noticeToDisplay;
}
function clearNotice() {
_noticeToDisplay = undefined;
}

function isCharging() {
return _isCharging;
}
Expand Down Expand Up @@ -1445,7 +1368,7 @@ var tgs = (function() {
var icon = ![gsUtils.STATUS_NORMAL, gsUtils.STATUS_ACTIVE].includes(status)
? ICON_SUSPENSION_PAUSED
: ICON_SUSPENSION_ACTIVE;
chrome.browserAction.setIcon({ path: icon, tabId: tabId }, function() {
chrome.action.setIcon({ path: icon, tabId: tabId }, function() {
if (chrome.runtime.lastError) {
gsUtils.warning(
tabId,
Expand Down Expand Up @@ -1757,16 +1680,6 @@ var tgs = (function() {
chrome.windows.onCreated.addListener(function(window) {
gsUtils.log(window.id, 'window created.');
queueSessionTimer();

var noticeToDisplay = requestNotice();
if (noticeToDisplay) {
chrome.tabs.create({ url: chrome.extension.getURL('notice.html') });
gsAnalytics.reportEvent(
'Notice',
'Display',
noticeToDisplay.target + ':' + noticeToDisplay.version
);
}
});
chrome.windows.onRemoved.addListener(function(windowId) {
gsUtils.log(windowId, 'window removed.');
Expand Down Expand Up @@ -1812,11 +1725,6 @@ var tgs = (function() {
});
}

function startNoticeCheckerJob() {
checkForNotices();
window.setInterval(checkForNotices, noticeCheckInterval);
}

function startSessionMetricsJob() {
gsSession.updateSessionMetrics(true);
window.setInterval(
Expand All @@ -1825,14 +1733,6 @@ var tgs = (function() {
);
}

function startAnalyticsUpdateJob() {
window.setInterval(() => {
gsAnalytics.performPingReport();
const reset = true;
gsSession.updateSessionMetrics(reset);
}, analyticsCheckInterval);
}

return {
STATE_TIMER_DETAILS,
STATE_UNLOADED_URL,
Expand All @@ -1853,8 +1753,6 @@ var tgs = (function() {
getInternalViewByTabId,
getInternalViewsByViewName,
startTimers,
requestNotice,
clearNotice,
buildContextMenu,
getActiveTabStatus,
getDebugInfo,
Expand Down Expand Up @@ -1890,7 +1788,6 @@ Promise.resolve()
.then(() => {
// initialise other gsLibs
return Promise.all([
gsAnalytics.initAsPromised(),
gsFavicon.initAsPromised(),
gsTabSuspendManager.initAsPromised(),
gsTabCheckManager.initAsPromised(),
Expand All @@ -1911,7 +1808,5 @@ Promise.resolve()
gsUtils.error('background init error: ', error);
})
.finally(() => {
gsAnalytics.performStartupReport();
gsAnalytics.performVersionReport();
tgs.startTimers();
});
3 changes: 1 addition & 2 deletions src/js/broken.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global chrome, gsAnalytics */
/*global chrome */
(function(global) {
'use strict';

Expand All @@ -20,7 +20,6 @@
.addEventListener('click', function() {
chrome.tabs.create({ url: chrome.extension.getURL('history.html') });
});
gsAnalytics.reportPageView('broken.html');
}
if (document.readyState !== 'loading') {
init();
Expand Down
15 changes: 1 addition & 14 deletions src/js/debug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global chrome, tgs, gsAnalytics, gsUtils, gsFavicon, gsStorage, gsChrome */
/*global chrome, tgs, gsUtils, gsFavicon, gsStorage, gsChrome */
(function(global) {
'use strict';

Expand Down Expand Up @@ -131,18 +131,5 @@
document.getElementById('backgroundPage').onclick = function() {
chrome.tabs.create({ url: extensionsUrl });
};

/*
chrome.processes.onUpdatedWithMemory.addListener(function (processes) {
chrome.tabs.query({}, function (tabs) {
var html = '';
html += generateMemStats(processes);
html += '<br />';
html += generateTabStats(tabs);
document.getElementById('gsProfiler').innerHTML = html;
});
});
*/
});
gsAnalytics.reportPageView('debug.html');
})(this);
Loading