lastTimeBackupNowClicked = new Date().getTime();
- chrome.runtime.getBackgroundPage((bg) => bg.backupNowManual(function(success, backupName, backupObj) {
+ chrome.runtime.sendMessage({
+ action: 'backupNowManual',
+ }, function({success, backupName, backupObj}) {
if (success) {
//updateBackupsList();
insertBackupItem (backupName, backupObj, true /*insertAtBeginning*/, true /*doAnimation*/);
} else {
alert('An error occured while creating the backup..');
}
- }));
+ });
}
function menu_restoreNow() {
- chrome.runtime.getBackgroundPage((bg) => bg.restoreNow('full_backup'));
+ chrome.runtime.sendMessage({
+ action: 'restoreNow',
+ args: ['full_backup'],
+ });
}
//document.onload(function () {
var d = new Date();
var formattedDate = date_format (d);
- backupNow(true, formattedDate, function(success, backupName, backupObj) {
+ backupNow(true, formattedDate, function({success, backupName, backupObj}) {
// backup completed
});
});
// if last backup time != lastTabsEdit
// perform automatic backup
- backupNow(true, formattedDate, function(success, backupName, backupObj) {
+ backupNow(true, formattedDate, function({success, backupName, backupObj}) {
// automatic backup completed
var popupViews = chrome.extension.getViews({type: "popup"});
if (popupViews.length > 0) {
//alert ("Error: " + chrome.runtime.lastError.message);
updateBrowserActionIcon (1);
- callbackDone(false);
+ callbackDone({success: false});
} else {
console.log("backup saved");
//alert("Backup saved successfully!");
if (chrome.runtime.lastError) {
console.log ("Error saving backups_list: " + chrome.runtime.lastError.message);
updateBrowserActionIcon (1);
- callbackDone(false);
+ callbackDone({success: false});
} else {
console.log("Backups list saved successfully");
updateBrowserActionIcon (0);
- callbackDone(true, backupName, fullBackup);
+ callbackDone({
+ success: true,
+ backupName,
+ backupObj: fullBackup,
+ });
if (backupsList.length > items.prefs_max_backup_items) {
deleteOldestBackup();
}
});
}
+
+/**
+ * Callback from other pages (like the popup).
+ */
+chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
+ console.log(`Got message from ${sender.id}: action=${request.action}`, request);
+
+ let asyncResponse = false;
+ switch (request?.action) {
+ case 'initAlarm':
+ initAlarm();
+ break;
+
+ case 'restoreNow':
+ restoreNow(...request.args);
+ break;
+
+ case 'deleteBackup':
+ deleteBackup(...request.args, sendResponse);
+ asyncResponse = true;
+ break;
+
+ case 'backupNowManual':
+ backupNowManual(sendResponse);
+ asyncResponse = true;
+ break;
+ }
+ return asyncResponse;
+});
});
// Re-initialize the backup alarm
- chrome.runtime.getBackgroundPage((bg) => bg.initAlarm());
+ chrome.runtime.sendMessage({action: 'initAlarm'});
// Update status to let user know options were saved.
var status = document.getElementById("statusDiv");
return function(event) {
bootbox.confirm("Open Windows & Tabs of backup '" + backupName + "'?", function(confirmed) {
if (confirmed) {
- chrome.runtime.getBackgroundPage((bg) => bg.restoreNow(backupName));
+ chrome.runtime.sendMessage({
+ action: 'restoreNow',
+ args: [backupName],
+ });
}
});
bootbox.confirm("Delete backup '" + backupName + "'?", function(confirmed) {
if (confirmed) {
- chrome.runtime.getBackgroundPage((bg) => {
- bg.deleteBackup(backupName, () => updateStorageInfo());
- });
+ chrome.runtime.sendMessage({
+ action: 'deleteBackup',
+ args: [backupName],
+ }, () => updateStorageInfo());
//if (elem.parentNode) {
// elem.parentNode.removeChild(elem);
lastTimeBackupNowClicked = new Date().getTime();
- chrome.runtime.getBackgroundPage((bg) => bg.backupNowManual(function(success, backupName, backupObj) {
+ chrome.runtime.sendMessage({
+ action: 'backupNowManual',
+ }, function({success, backupName, backupObj}) {
if (success) {
//updateBackupsList();
insertBackupItem (backupName, backupObj, true /*insertAtBeginning*/, true /*doAnimation*/);
} else {
alert('An error occured while creating the backup..');
}
- }));
+ });
}
function menu_restoreNow() {
- chrome.runtime.getBackgroundPage((bg) => bg.restoreNow('full_backup'));
+ chrome.runtime.sendMessage({
+ action: 'restoreNow',
+ args: ['full_backup'],
+ });
}