зеркало из
1
0
Форкнуть 0

Merge pull request #169 from bakulf/hideTabs

Fixing the hiding of tabs #167
Restoring hidden tabs #156
This commit is contained in:
Andrea Marchesini 2017-02-11 17:26:03 +01:00 коммит произвёл GitHub
Родитель f8fd316e56 f77a5d4e3a
Коммит a086e3c003
1 изменённых файлов: 35 добавлений и 10 удалений

Просмотреть файл

@ -31,6 +31,7 @@ const { getFavicon } = require("sdk/places/favicon");
const { modelFor } = require("sdk/model/core");
const prefService = require("sdk/preferences/service");
const self = require("sdk/self");
const ss = require("sdk/simple-storage");
const { Style } = require("sdk/stylesheet/style");
const tabs = require("sdk/tabs");
const tabsUtils = require("sdk/tabs/utils");
@ -85,6 +86,18 @@ const ContainerService = {
this._remapTabsIfMissing(identity.userContextId);
});
// Let's restore the hidden tabs from the previous session.
if (prefService.get('browser.startup.page') == 3 &&
"identitiesData" in ss.storage) {
ContextualIdentityService.getIdentities().forEach(identity => {
if (identity.userContextId in ss.storage.identitiesData &&
"hiddenTabs" in ss.storage.identitiesData[identity.userContextId]) {
this._identitiesState[identity.userContextId].hiddenTabs =
ss.storage.identitiesData[identity.userContextId].hiddenTabs;
}
});
}
tabs.on("open", tab => {
const userContextId = this._getUserContextIdFromTab(tab);
if (userContextId) {
@ -141,7 +154,7 @@ const ContainerService = {
image: this._fromIconToName(identity.icon),
color: this._fromColorToName(identity.color),
userContextId: identity.userContextId,
hasHiddenTabs: !!this._identitiesState[identity.userContextId].hiddenTabUrls.length,
hasHiddenTabs: !!this._identitiesState[identity.userContextId].hiddenTabs.length,
hasOpenTabs: !!this._identitiesState[identity.userContextId].openTabs
};
},
@ -208,7 +221,7 @@ const ContainerService = {
_createIdentityState() {
return {
hiddenTabUrls: [],
hiddenTabs: [],
openTabs: 0
};
},
@ -232,11 +245,14 @@ const ContainerService = {
_closeTabs(tabsToClose) {
// We create a new tab only if the current operation closes all the
// existing ones.
let promise;
if (tabs.length !== tabsToClose.length) {
return Promise.resolve(null);
promise = Promise.resolve(null);
} else {
promise = this.openTab({});
}
return this.openTab({}).then(() => {
return promise.then(() => {
for (let tab of tabsToClose) { // eslint-disable-line prefer-const
tab.close();
}
@ -254,6 +270,11 @@ const ContainerService = {
return Promise.resolve(browserWin);
},
_syncTabs() {
// Let's store all what we have.
ss.storage.identitiesData = this._identitiesState;
},
// Tabs management
hideTabs(args) {
@ -281,11 +302,13 @@ const ContainerService = {
object.favicon = "";
});
this._identitiesState[args.userContextId].hiddenTabUrls.push(object);
this._identitiesState[args.userContextId].hiddenTabs.push(object);
tabsToClose.push(tab);
});
return this._closeTabs(tabsToClose);
return this._closeTabs(tabsToClose).then(() => {
return this._syncTabs();
});
},
showTabs(args) {
@ -300,13 +323,15 @@ const ContainerService = {
const promises = [];
for (let object of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const
for (let object of this._identitiesState[args.userContextId].hiddenTabs) { // eslint-disable-line prefer-const
promises.push(this.openTab({ userContextId: args.userContextId, url: object.url }));
}
this._identitiesState[args.userContextId].hiddenTabUrls = [];
this._identitiesState[args.userContextId].hiddenTabs = [];
return Promise.all(promises);
return Promise.all(promises).then(() => {
return this._syncTabs();
});
},
sortTabs() {
@ -386,7 +411,7 @@ const ContainerService = {
}
Promise.all(promises).then(() => {
resolve(list.concat(this._identitiesState[args.userContextId].hiddenTabUrls));
resolve(list.concat(this._identitiesState[args.userContextId].hiddenTabs));
}).catch((e) => {
reject(e);
});