-
-// Set default values if needed
-if (!localStorage.prefsMaxBackupItems) {
- localStorage.prefsMaxBackupItems = "10";
+// Migrate old localStorage to chrome.storage.local.
+if (localStorage.prefsMaxBackupItems !== undefined) {
+ chrome.storage.local.set({
+ prefs_max_backup_items: parseInt(localStorage.prefsMaxBackupItems),
+ });
+ localStorage.removeItem("prefsMaxBackupItems");
}
-
-if (!localStorage.prefsBackupTimer) {
- localStorage.prefsBackupTimer = "30";
+if (localStorage.prefsBackupTimer !== undefined) {
+ chrome.storage.local.set({
+ prefs_backup_timer: parseInt(localStorage.prefsBackupTimer),
+ });
+ localStorage.removeItem("prefsBackupTimer");
+}
+if (localStorage.prefsTheme !== undefined) {
+ chrome.storage.local.set({
+ prefs_theme: localStorage.prefsTheme,
+ });
+ localStorage.removeItem("prefsTheme");
}
+localStorage.removeItem("lastBackupTime");
-// Create a backup on first install (or if storage is wiped for some reason).
-chrome.storage.local.get("backups_list", function(items) {
+// Create a backup on first install (or if storage is wiped for some reason.
+chrome.storage.local.get(function(items) {
+ // Setup defaults.
+ if (items.prefs_max_backup_items === undefined) {
+ chrome.storage.local.set({prefs_max_backup_items: 10});
+ }
+ if (items.prefs_backup_timer === undefined) {
+ chrome.storage.local.set({prefs_backup_timer: 30});
+ }
+
+ // If a backup exists already, nothing to do.
if (items.backups_list) {
return;
}
// Clear any previous alarm
chrome.alarms.clearAll();
- var timerMinutes = parseInt(localStorage.prefsBackupTimer);
- chrome.alarms.create(BACKUP_ALARM_NAME, {periodInMinutes: timerMinutes});
+ chrome.storage.local.get(function(items) {
+ const timerMinutes = items.prefs_backup_timer;
+ chrome.alarms.create(BACKUP_ALARM_NAME, {periodInMinutes: timerMinutes});
+ });
}
initAlarm();
}
function deleteOldestBackup () {
- chrome.storage.local.get("backups_list", function(items) {
+ chrome.storage.local.get(function(items) {
if(!items.backups_list) {
return;
}
var backupsList = items.backups_list;
- var numItemsToDelete = backupsList.length - parseInt(localStorage.prefsMaxBackupItems);
+ var numItemsToDelete = backupsList.length - items.prefs_max_backup_items;
if (numItemsToDelete > 0) {
var i = 0;
var loopFunc = function () {
console.log("backup saved");
//alert("Backup saved successfully!");
- chrome.storage.local.get("backups_list", function(items) {
+ chrome.storage.local.get(function(items) {
var backupsList = [];
if(items.backups_list) {
backupsList = items.backups_list;
updateBrowserActionIcon (0);
callbackDone(true, backupName, fullBackup);
- if (backupsList.length > parseInt(localStorage.prefsMaxBackupItems)) {
+ if (backupsList.length > items.prefs_max_backup_items) {
deleteOldestBackup();
}
}
}
function saveOptions () {
- var backupPeriodMinutes = getSelectValue("prefsSelectBackupPeriod");
- localStorage.prefsBackupTimer = backupPeriodMinutes;
-
- var backupMaxItems = getSelectValue("prefsSelectMaxBackups");
- localStorage.prefsMaxBackupItems = backupMaxItems;
-
- var theme = document.getElementById('prefsTheme').value;
- localStorage.prefsTheme = theme;
+ chrome.storage.local.set({
+ prefs_backup_timer: getSelectValue("prefsSelectBackupPeriod"),
+ prefs_max_backup_items: getSelectValue("prefsSelectMaxBackups"),
+ prefs_theme: document.getElementById('prefsTheme').value,
+ });
// Re-initialize the backup alarm
chrome.runtime.getBackgroundPage((bg) => bg.initAlarm());
}
function restoreOptions() {
- var backupPeriodMinutes = localStorage.prefsBackupTimer;
- var backupMaxItems = localStorage.prefsMaxBackupItems;
- var theme = localStorage.prefsTheme;
-
- setSelectValue ("prefsSelectBackupPeriod", backupPeriodMinutes);
- setSelectValue ("prefsSelectMaxBackups", backupMaxItems);
- setThemeValue(theme);
+ chrome.storage.local.get(function(items) {
+ setSelectValue("prefsSelectBackupPeriod", items.prefs_backup_timer);
+ setSelectValue("prefsSelectMaxBackups", items.prefs_max_backup_items);
+ setThemeValue(items.prefs_theme);
+ });
}