diff --git a/data/scripts/components/config-panel.js b/data/scripts/components/config-panel.js index ea7529f..422feac 100644 --- a/data/scripts/components/config-panel.js +++ b/data/scripts/components/config-panel.js @@ -79,6 +79,7 @@ define(function(require, exports) { } }, }); + options.parent.addItem(toggleBtn.DOMRoot); AppConfig.onChange(options.key, function(value) { if (isSwitch) @@ -213,6 +214,13 @@ define(function(require, exports) { type: 'switch', }); + ToggleOptionConfig({ + parent: section, + name: 'Troubleshooting', + key: 'troubleshooting', + type: 'switch', + }); + })(); // ------------------------ diff --git a/data/scripts/components/session-header-bar.js b/data/scripts/components/session-header-bar.js index 2afe822..89ddf3e 100644 --- a/data/scripts/components/session-header-bar.js +++ b/data/scripts/components/session-header-bar.js @@ -251,6 +251,21 @@ define(function(require, exports) { } }); + devRow1.appendChild(activeTabInfo); + devRow1.appendChild(localStorage); + devRow1.appendChild(clearFaviconCache); + menuArea.appendChild(devRow1); + } + + if (AppConfig.devMode()) + { + initDevMode(); + } + + var Troubleshooting = (function Troubleshooting() + { + var isInit = false; + var fixLazySession = MenuButton({ title: 'Fix session', icon: 'icons/tools.png', @@ -259,19 +274,24 @@ define(function(require, exports) { } }); - devRow1.appendChild(activeTabInfo); - devRow1.appendChild(localStorage); - devRow1.appendChild(clearFaviconCache); - menuArea.appendChild(devRow1); + function init() + { + if (isInit == true) + { + return; + } + isInit = true; + var devRow = DomElem('div', {class: 'menu-row'}); + devRow.appendChild(fixLazySession); + menuArea.appendChild(devRow); + } - var devRow2 = DomElem('div', {class: 'menu-row'}); - devRow2.appendChild(fixLazySession); - menuArea.appendChild(devRow2); - } + return { + init: init + }; - if (AppConfig.devMode()) - initDevMode(); + })(); // ------------------------------------------------------------------------ // Events @@ -307,6 +327,12 @@ define(function(require, exports) { closeMenu(); }); + AppConfig.onChange('troubleshooting', function(value) { + if (value == true) { + Troubleshooting.init(); + } + }); + // ------------------------------------------------------------------------ // Public diff --git a/data/scripts/components/session-history.js b/data/scripts/components/session-history.js index cabcdb0..faa592c 100644 --- a/data/scripts/components/session-history.js +++ b/data/scripts/components/session-history.js @@ -67,27 +67,37 @@ define(function(require, exports) { }); }; + var onStorageChanged = function onStorageChanged(object) + { + if (object[storageKey.list]) { + init(); + } + }; + GlobalEvents.on('HistorySessionDelete', function(index) { - getFullHistory(function (sessions) { - if (index >= 0 && index < sessions.length) { - if (index == sessions.length - 1) - { - sessions[index] = undefined; - } - else - { + if (index == -1) + { + browser.runtime.sendMessage({event: 'history.deleteActive'}); + } + else + { + getFullHistory(function (sessions) { + if (index >= 0 && index < sessions.length) { sessions.splice(index, 1); + updateSessions(sessions); } - updateSessions(sessions); - } - }); + }); + } }); GlobalEvents.on('HistorySessionDeleteAll', function() { - updateSessions([]); + sessions = []; + updateSessions(sessions); }); + browser.storage.onChanged.addListener(onStorageChanged); + // ------------------------------------------------------------------------ // Public API diff --git a/data/scripts/config.js b/data/scripts/config.js index 23e6d29..2bf5552 100644 --- a/data/scripts/config.js +++ b/data/scripts/config.js @@ -91,6 +91,8 @@ define(function(require, exports) { getConfigValue('trashcan.hide', true); getConfigValue('trashcan.hide-count', 0); getConfigValue('undo.events', []); + + getConfigValue('troubleshooting', false); }; var set = function set(key, value, onSuccess) diff --git a/manifest.json b/manifest.json index 89deba1..1c36fbe 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Session Sync", - "version": "3.1.10", + "version": "3.1.12", "author": "Gabriel Ivanica", "description": "Save sessions as bookmarks and sync them through Firefox Sync (or any other sync engine).\nPowerful session management - organize, edit, change, save, restore, etc\n", "homepage_url": "https://github.com/ReDEnergy/SessionSync", diff --git a/scripts/session-history.js b/scripts/session-history.js index b6d415c..b23abc4 100644 --- a/scripts/session-history.js +++ b/scripts/session-history.js @@ -68,6 +68,13 @@ BrowserSession.prototype.update = function update() }.bind(this)); }; +BrowserSession.prototype.clear = function clear() +{ + // Save new session + this.windows = {}; + browser.storage.local.set({ 'history.active' : this}); +}; + BrowserSession.prototype.start = function start(updateInterval) { if (this.timer == undefined) { @@ -116,7 +123,7 @@ var SessionAutoSave = (function SessionAutoSave() enabled: true, interval: 15, saveBuffer: 3, - savingSlots: 10, + savingSlots: 20, expireTimeHours: 48, // hours }; @@ -158,36 +165,38 @@ var SessionAutoSave = (function SessionAutoSave() var updateStorage = function updateStorage() { - var removeCount = sessions.length - config.savingSlots; - if (removeCount <= 0) - return; + upgradeStorage(); + var removeCount = Math.max(sessions.length - config.savingSlots, 0); var expireTime = new Date(new Date() - config.expireTimeHours * 3600 * 1000); var list = []; + // console.log('To remove', removeCount); // compact free space and delete expired sessions sessions.forEach(function (session) { - if (removeCount > 0) { - removeCount--; - if (session.lastSave < expireTime) { - return; - } + if (session != undefined && (removeCount <= 0 || session.lastSave > expireTime)) + { list.push(session); } - else { - list.push(session); + else + { + if (removeCount > 0) + removeCount--; } }); - // get session list + if (removeCount > 0) + { + list = list.slice(removeCount); + } + + // update session list sessions = list; }; var init = function init() { - browser.storage.onChanged.addListener(onConfigChanged); - browser.storage.local.get([activeSessionKey, sessionsKey]) .then(function(obj) { @@ -196,16 +205,15 @@ var SessionAutoSave = (function SessionAutoSave() updateStorage(); } + // console.log(sessions); + if (obj[activeSessionKey]) { obj[activeSessionKey].windows = Object.values(obj[activeSessionKey].windows); delete obj[activeSessionKey].active; sessions.push(obj[activeSessionKey]); } - upgradeStorage(); - - browser.storage.local.set({ [sessionsKey] : sessions}); - + browser.storage.local.set({ [sessionsKey] : sessions }); activeSession.setConfig(config); }); }; @@ -213,6 +221,12 @@ var SessionAutoSave = (function SessionAutoSave() // ------------------------------------------------------------------------ // Events + browser.runtime.onMessage.addListener(function (message) { + if (message.event == 'history.deleteActive') { + activeSession.clear(); + } + }); + var onConfigChanged = function onConfigChanged(object) { if (object[config.key]) { @@ -221,6 +235,8 @@ var SessionAutoSave = (function SessionAutoSave() } }; + browser.storage.onChanged.addListener(onConfigChanged); + // ------------------------------------------------------------------------ // Public API