// Set default values if needed
if (!localStorage.prefsMaxBackupItems) {
- localStorage.prefsMaxBackupItems = "30";
+ localStorage.prefsMaxBackupItems = "10";
}
if (!localStorage.prefsBackupTimer) {
- localStorage.prefsBackupTimer = "5";
-}
-
-if (!localStorage.lastTimerIntervalId) {
- localStorage.lastTimerIntervalId = 0;
-}
-
-if (!localStorage.lastTabsEdit) {
- localStorage.lastTabsEdit = 0;
+ localStorage.prefsBackupTimer = "30";
}
if (!localStorage.lastBackupTime) {
backupNow(true, formattedDate, function(success, backupName, backupObj) {
// backup completed
});
-
- localStorage.lastBackupTime = localStorage.lastTabsEdit;
-}
-
-
-
-// Works only for Event Pages
-/*
-chrome.runtime.onInstalled.addListener(function() {
- console.log("Extension installed/updates");
-
- if (localStorage.lastBackupTime != localStorage.lastTabsEdit) {
- // Create a backup now
- var d = new Date();
- var formattedDate = date_format (d);
-
- backupNow(true, formattedDate, function(success, backupName, backupObj) {
- // backup completed
- });
-
- localStorage.lastBackupTime = localStorage.lastTabsEdit;
- }
-});*/
-
-chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {
- //console.log('tabs.onRemoved');
-
- tabsEdited(true);
-});
-
-chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
- //console.log('tabs.onUpdated');
-
- tabsEdited(true);
-});
-
-chrome.tabs.onAttached.addListener(function(tabId, attachInfo) {
- //console.log('tabs.onAttached');
-
- tabsEdited(false);
-});
-
-chrome.tabs.onMoved.addListener(function(tabId, moveInfo) {
- //console.log('tabs.onMoved');
-
- tabsEdited(false);
-});
-
-chrome.tabs.onDetached.addListener(function(tabId, detachInfo) {
- //console.log('tabs.onDetached');
-
- tabsEdited(false);
-});
-
-chrome.tabs.onCreated.addListener(function(tab) {
- //console.log('tabs.onCreated');
-
- tabsEdited(true);
-});
-
-function tabsEdited (isImportant) {
- var d = new Date();
- var millis = d.getTime();
-
- console.log('tabsEdited - lastTabsEdit: ' + localStorage.lastTabsEdit);
- console.log('tabsEdited - new lastTabsEdit: ' + millis);
-
- localStorage.lastTabsEdit = millis;
-
-
}
function initAlarm () {
- console.log("initAlarm");
+ //console.log("initAlarm");
var BACKUP_ALARM_NAME = "backup_alarm";
// Clear any previous alarm
chrome.alarms.clearAll();
- clearInterval(parseInt(localStorage.lastTimerIntervalId));
var timerMinutes = parseInt(localStorage.prefsBackupTimer);
-
- // Apparantely once the app is on the Chrome Store it's not possible
- // to create alarms that have period less than 5 minutes..
- if (timerMinutes < 5) {
- var timerMillis = timerMinutes * 60 * 1000;
- localStorage.lastTimerIntervalId = setInterval (onAlarm, timerMillis);
- console.log("Created interval alarm - id: " + localStorage.lastTimerIntervalId + " time: " + timerMinutes + " minutes");
- } else {
- console.log("Creating chrome.alarm 'backup_alarm' - time: " + timerMinutes + " minutes");
- chrome.alarms.create(BACKUP_ALARM_NAME, {periodInMinutes: timerMinutes});
- }
+ chrome.alarms.create(BACKUP_ALARM_NAME, {periodInMinutes: timerMinutes});
}
initAlarm();
var d = new Date();
var formattedDate = date_format (d);
- console.log("Alarm {" + alarm + "} fired up: " + formattedDate + " last tabs edit: " + localStorage.lastTabsEdit + " last backup time: " + localStorage.lastBackupTime);
+ console.log("Alarm {" + alarm + "} fired up: " + formattedDate);
- // localStorage.lastBackupTime
// if last backup time != lastTabsEdit
// perform automatic backup
- if (localStorage.lastBackupTime != localStorage.lastTabsEdit) {
backupNow(true, formattedDate, function(success, backupName, backupObj) {
// automatic backup completed
var popupViews = chrome.extension.getViews({type: "popup"});
}
}
});
-
- localStorage.lastBackupTime = localStorage.lastTabsEdit;
- }
}
chrome.alarms.onAlarm.addListener(onAlarm);
fullBackup.windows.push(bkpWindow);
}
+ if (totNumTabs == 0)
+ return;
+
fullBackup.totNumTabs = totNumTabs;
var storageSetValues = {};
}
});
-}
\ No newline at end of file
+}
return function(event) {
bootbox.confirm("Open Windows & Tabs of backup '" + backupName + "'?", function(confirmed) {
if (confirmed) {
- chrome.extension.getBackgroundPage().restoreNow(backupName);
+ chrome.runtime.getBackgroundPage((bg) => bg.restoreNow(backupName));
}
});
bootbox.confirm("Delete backup '" + backupName + "'?", function(confirmed) {
if (confirmed) {
- chrome.extension.getBackgroundPage().deleteBackup(backupName, function() {
- updateStorageInfo();
+ chrome.runtime.getBackgroundPage((bg) => {
+ bg.deleteBackup(backupName, () => updateStorageInfo());
});
//if (elem.parentNode) {
lastTimeBackupNowClicked = new Date().getTime();
- chrome.extension.getBackgroundPage().backupNowManual(function(success, backupName, backupObj) {
+ chrome.runtime.getBackgroundPage((bg) => bg.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.extension.getBackgroundPage().restoreNow('full_backup');
+ chrome.runtime.getBackgroundPage((bg) => bg.restoreNow('full_backup'));
}
//document.onload(function () {