Skip to content

Commit

Permalink
added option to enable troubleshooting (fix for incorrect saved session)
Browse files Browse the repository at this point in the history
improved auto-saved history storage upgrading and updating
  • Loading branch information
ReDEnergy committed Jul 12, 2019
1 parent 32a87cf commit ed88497
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 41 deletions.
8 changes: 8 additions & 0 deletions data/scripts/components/config-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ define(function(require, exports) {
}
},
});

options.parent.addItem(toggleBtn.DOMRoot);
AppConfig.onChange(options.key, function(value) {
if (isSwitch)
Expand Down Expand Up @@ -213,6 +214,13 @@ define(function(require, exports) {
type: 'switch',
});

ToggleOptionConfig({
parent: section,
name: 'Troubleshooting',
key: 'troubleshooting',
type: 'switch',
});

})();

// ------------------------
Expand Down
46 changes: 36 additions & 10 deletions data/scripts/components/session-header-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -307,6 +327,12 @@ define(function(require, exports) {
closeMenu();
});

AppConfig.onChange('troubleshooting', function(value) {
if (value == true) {
Troubleshooting.init();
}
});

// ------------------------------------------------------------------------
// Public

Expand Down
34 changes: 22 additions & 12 deletions data/scripts/components/session-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions data/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
52 changes: 34 additions & 18 deletions scripts/session-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -116,7 +123,7 @@ var SessionAutoSave = (function SessionAutoSave()
enabled: true,
interval: 15,
saveBuffer: 3,
savingSlots: 10,
savingSlots: 20,
expireTimeHours: 48, // hours
};

Expand Down Expand Up @@ -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) {

Expand All @@ -196,23 +205,28 @@ 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);
});
};

// ------------------------------------------------------------------------
// Events

browser.runtime.onMessage.addListener(function (message) {
if (message.event == 'history.deleteActive') {
activeSession.clear();
}
});

var onConfigChanged = function onConfigChanged(object)
{
if (object[config.key]) {
Expand All @@ -221,6 +235,8 @@ var SessionAutoSave = (function SessionAutoSave()
}
};

browser.storage.onChanged.addListener(onConfigChanged);

// ------------------------------------------------------------------------
// Public API

Expand Down

0 comments on commit ed88497

Please sign in to comment.