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 # Download
https://addons.mozilla.org/en-US/firefox/addon/easy-session-manager/ https://addons.mozilla.org/en-US/firefox/addon/easy-session-manager/
# Version: 0.0.5 # Version: 0.0.6
Added proper alert messages and improved security of import file. Improved loading of sessions.
# Images # Images
![1 Default interface with no sessions. ](images/pic1.png) ![1 Default interface with no sessions. ](images/pic1.png)

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": " Easy Session Manager", "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.", "description": " Easy Session Manager allows you to manage your Firefox session by backing up or loading your saved sessions.",
"applications": { "applications": {

View File

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