From: Mike Frysinger Date: Mon, 3 Jun 2019 15:03:24 +0000 (-0400) Subject: my customizations X-Git-Tag: v0.3~17 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=e0b6a877d70e8127142781e883b8287c97cf32d6;p=chrome-ext%2Ftabs-backup.git my customizations --- diff --git a/advanced.html b/advanced.html index 57bf236..ecdb129 100644 --- a/advanced.html +++ b/advanced.html @@ -379,11 +379,11 @@ Restore selected
- + Restore to a single window
- + Restore to multiple windows
diff --git a/advanced.js b/advanced.js index 9d48a66..588e056 100644 --- a/advanced.js +++ b/advanced.js @@ -672,7 +672,7 @@ function menu_backupNow() { 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*/); @@ -682,12 +682,12 @@ function menu_backupNow() { } 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 () { diff --git a/background.js b/background.js index a1debe5..6b6f89d 100644 --- a/background.js +++ b/background.js @@ -1,19 +1,11 @@ // 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) { @@ -26,99 +18,18 @@ 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(); @@ -127,12 +38,10 @@ function onAlarm (alarm) { 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"}); @@ -148,9 +57,6 @@ function onAlarm (alarm) { } } }); - - localStorage.lastBackupTime = localStorage.lastTabsEdit; - } } chrome.alarms.onAlarm.addListener(onAlarm); @@ -282,6 +188,9 @@ function backupNow(isAutomatic, backupName, callbackDone) { fullBackup.windows.push(bkpWindow); } + if (totNumTabs == 0) + return; + fullBackup.totNumTabs = totNumTabs; var storageSetValues = {}; @@ -464,4 +373,4 @@ function restoreNow(backupName) { } }); -} \ No newline at end of file +} diff --git a/manifest.json b/manifest.json index cd65f1d..06162e6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,12 +1,13 @@ { - "name": "Tabs Backup & Restore", - "version": "0.2.1", + "name": "vapier tabs backup", + "version": "0.2.1.1", "manifest_version": 2, "description": "With 'Tabs Backup & Restore' you will never lose your work again! Backup an entire Chrome session (windows and tabs).", "icons": { "16": "icon_16.png", "48": "icon_48.png", "128": "icon_128.png" }, "background": { + "persistent": false, "scripts": ["background.js"] }, "options_page": "options.html", diff --git a/options.js b/options.js index e443a8f..26d6d1c 100644 --- a/options.js +++ b/options.js @@ -33,7 +33,7 @@ function saveOptions () { localStorage.prefsMaxBackupItems = backupMaxItems; // Re-initialize the backup alarm - chrome.extension.getBackgroundPage().initAlarm(); + chrome.runtime.getBackgroundPage((bg) => bg.initAlarm()); // Update status to let user know options were saved. var status = document.getElementById("statusDiv"); diff --git a/popup.js b/popup.js index a8f1a04..7c5f2f5 100644 --- a/popup.js +++ b/popup.js @@ -140,7 +140,7 @@ function insertBackupItem (backupName, backupObj, insertAtBeginning, doAnimation 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)); } }); @@ -157,8 +157,8 @@ function insertBackupItem (backupName, backupObj, insertAtBeginning, doAnimation 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) { @@ -321,7 +321,7 @@ function menu_backupNow() { 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*/); @@ -331,12 +331,12 @@ function menu_backupNow() { } 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 () {