Improved loading of sessions.

This commit is contained in:
Maxim Stewart 2019-01-19 01:05:01 -06:00
parent 03ae173a9f
commit 96809cabec
3 changed files with 44 additions and 29 deletions

View File

@ -4,8 +4,8 @@ Easy Session Manager allows you to manage your Firefox session by backing up or
# Download
https://addons.mozilla.org/en-US/firefox/addon/easy-session-manager/
# Version: 0.0.5
Added proper alert messages and improved security of import file.
# Version: 0.0.6
Improved loading of sessions.
# Images
![1 Default interface with no sessions. ](images/pic1.png)

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": " Easy Session Manager",
"version": "0.0.5",
"version": "0.0.6",
"description": " Easy Session Manager allows you to manage your Firefox session by backing up or loading your saved sessions.",
"applications": {

View File

@ -2,7 +2,6 @@ const regexp = /^[a-zA-Z0-9-_]+$/; // Alphanumeric, dash, underscore
const storage = browser.storage.local;
const windowSys = browser.windows;
const alertMessage = (type, message) => {
let msgTag = document.getElementById("allertMessage");
let text = document.createTextNode(message);
@ -131,36 +130,52 @@ const editSession = () => {
const loadSession = (id = null) => {
console.log("Loading session...");
try {
storage.get(id).then((storageResults) => {
storage.get(id).then(storageResults => {
let json = JSON.parse(storageResults[id]);
let keys = Object.keys(json);
let keysLength = Object.keys(json).length;
browser.windows.getAll().then((windows) => {
windowSys.getCurrent({populate: true}).then((currentWindow) => {
// Clear out windows
for (var i = 0; i < windows.length; i++) {
browser.windows.getAll().then(windows => {
windowSys.getCurrent({populate: true}).then(currentWindow => {
let wasCurrentTabId = null;
// Clear all non-current windows and then current window's tabs
for (let i = 0; i < windows.length; i++) {
if (currentWindow.id != windows[i].id) {
windowSys.remove(windows[i].id);
} else {
let ids = [];
currentWindow.tabs.forEach(tab => {
if (!tab.active) {
ids.push(tab.id);
} else {
wasCurrentTabId = tab.id;
}
});
browser.tabs.remove(ids);
}
}
}, windows);
// First load tabs to current window.
let store = json[keys[0]];
store.forEach(tab => {
browser.tabs.create({ url: tab.link });
});
// Open windows and populate with proper tabs
keys.forEach((key) => {
let store = json[key];
// If more than one window, load tabs to new windows.
browser.tabs.remove(wasCurrentTabId);
if (keysLength > 1) {
for (let i = 1; i < keysLength; i++) {
let store = json[keys[i]];
let urls = [];
for (var i = 0; i < store.length; i++) {
urls.push(store[i].link);
for (let j = 0; j < store.length; j++) {
urls.push(store[j].link);
}
windowSys.create({ url: urls });
}
}
});
// Finalize clear out windows
windowSys.getCurrent({populate: true}).then((currentWindow) => {
windowSys.remove(currentWindow.id);
});
});
} catch (e) { console.log(e); }