aboutsummaryrefslogtreecommitdiff
path: root/src/background/presenters
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-29 11:17:01 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-07-29 11:17:01 +0900
commit0ca138cba46408388ee46eab16f46cec25cac41a (patch)
treeff3e1593e78e5f33a4b12cf96c84bc1fe01a1a4e /src/background/presenters
parent09c5247dbadb468a764eef308634503484d398c5 (diff)
Select last tab on presenter
Diffstat (limited to 'src/background/presenters')
-rw-r--r--src/background/presenters/tab.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/background/presenters/tab.js b/src/background/presenters/tab.js
index 2a06a5a..6ad9736 100644
--- a/src/background/presenters/tab.js
+++ b/src/background/presenters/tab.js
@@ -1,3 +1,8 @@
+import MemoryStorage from '../infrastructures/memory-storage';
+
+const CURRENT_SELECTED_KEY = 'tabs.current.selected';
+const LAST_SELECTED_KEY = 'tabs.last.selected';
+
export default class TabPresenter {
open(url, tabId) {
return browser.tabs.update(tabId, { url });
@@ -18,6 +23,15 @@ export default class TabPresenter {
return browser.tabs.query({ currentWindow: true });
}
+ async getLastSelectedId() {
+ let cache = new MemoryStorage();
+ let tabId = await cache.get(LAST_SELECTED_KEY);
+ if (tabId === null || typeof tabId === 'undefined') {
+ return;
+ }
+ return tabId;
+ }
+
async getByKeyword(keyword, excludePinned = false) {
let tabs = await browser.tabs.query({ currentWindow: true });
return tabs.filter((t) => {
@@ -99,3 +113,14 @@ export default class TabPresenter {
browser.tabs.onActivated.addListener(listener);
}
}
+
+let tabPresenter = new TabPresenter();
+tabPresenter.onSelected((tab) => {
+ let cache = new MemoryStorage();
+
+ let lastId = cache.get(CURRENT_SELECTED_KEY);
+ if (lastId) {
+ cache.set(LAST_SELECTED_KEY, lastId);
+ }
+ cache.set(CURRENT_SELECTED_KEY, tab.tabId);
+});