From c60d0e7392fc708e961614d6b756a045de74f458 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 14:00:07 +0900 Subject: Rename .js/.jsx to .ts/.tsx --- src/background/presenters/IndicatorPresenter.js | 12 --- src/background/presenters/IndicatorPresenter.ts | 12 +++ src/background/presenters/NotifyPresenter.js | 23 ------ src/background/presenters/NotifyPresenter.ts | 23 ++++++ src/background/presenters/TabPresenter.js | 102 ------------------------ src/background/presenters/TabPresenter.ts | 102 ++++++++++++++++++++++++ src/background/presenters/WindowPresenter.js | 5 -- src/background/presenters/WindowPresenter.ts | 5 ++ 8 files changed, 142 insertions(+), 142 deletions(-) delete mode 100644 src/background/presenters/IndicatorPresenter.js create mode 100644 src/background/presenters/IndicatorPresenter.ts delete mode 100644 src/background/presenters/NotifyPresenter.js create mode 100644 src/background/presenters/NotifyPresenter.ts delete mode 100644 src/background/presenters/TabPresenter.js create mode 100644 src/background/presenters/TabPresenter.ts delete mode 100644 src/background/presenters/WindowPresenter.js create mode 100644 src/background/presenters/WindowPresenter.ts (limited to 'src/background/presenters') diff --git a/src/background/presenters/IndicatorPresenter.js b/src/background/presenters/IndicatorPresenter.js deleted file mode 100644 index 5737519..0000000 --- a/src/background/presenters/IndicatorPresenter.js +++ /dev/null @@ -1,12 +0,0 @@ -export default class IndicatorPresenter { - indicate(enabled) { - let path = enabled - ? 'resources/enabled_32x32.png' - : 'resources/disabled_32x32.png'; - return browser.browserAction.setIcon({ path }); - } - - onClick(listener) { - browser.browserAction.onClicked.addListener(listener); - } -} diff --git a/src/background/presenters/IndicatorPresenter.ts b/src/background/presenters/IndicatorPresenter.ts new file mode 100644 index 0000000..5737519 --- /dev/null +++ b/src/background/presenters/IndicatorPresenter.ts @@ -0,0 +1,12 @@ +export default class IndicatorPresenter { + indicate(enabled) { + let path = enabled + ? 'resources/enabled_32x32.png' + : 'resources/disabled_32x32.png'; + return browser.browserAction.setIcon({ path }); + } + + onClick(listener) { + browser.browserAction.onClicked.addListener(listener); + } +} diff --git a/src/background/presenters/NotifyPresenter.js b/src/background/presenters/NotifyPresenter.js deleted file mode 100644 index a81f227..0000000 --- a/src/background/presenters/NotifyPresenter.js +++ /dev/null @@ -1,23 +0,0 @@ -const NOTIFICATION_ID = 'vimvixen-update'; - -export default class NotifyPresenter { - notify(title, message, onclick) { - const listener = (id) => { - if (id !== NOTIFICATION_ID) { - return; - } - - onclick(); - - browser.notifications.onClicked.removeListener(listener); - }; - browser.notifications.onClicked.addListener(listener); - - return browser.notifications.create(NOTIFICATION_ID, { - 'type': 'basic', - 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'), - title, - message, - }); - } -} diff --git a/src/background/presenters/NotifyPresenter.ts b/src/background/presenters/NotifyPresenter.ts new file mode 100644 index 0000000..a81f227 --- /dev/null +++ b/src/background/presenters/NotifyPresenter.ts @@ -0,0 +1,23 @@ +const NOTIFICATION_ID = 'vimvixen-update'; + +export default class NotifyPresenter { + notify(title, message, onclick) { + const listener = (id) => { + if (id !== NOTIFICATION_ID) { + return; + } + + onclick(); + + browser.notifications.onClicked.removeListener(listener); + }; + browser.notifications.onClicked.addListener(listener); + + return browser.notifications.create(NOTIFICATION_ID, { + 'type': 'basic', + 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'), + title, + message, + }); + } +} diff --git a/src/background/presenters/TabPresenter.js b/src/background/presenters/TabPresenter.js deleted file mode 100644 index 744be39..0000000 --- a/src/background/presenters/TabPresenter.js +++ /dev/null @@ -1,102 +0,0 @@ -import MemoryStorage from '../infrastructures/MemoryStorage'; - -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 }); - } - - create(url, opts) { - return browser.tabs.create({ url, ...opts }); - } - - async getCurrent() { - let tabs = await browser.tabs.query({ - active: true, currentWindow: true - }); - return tabs[0]; - } - - getAll() { - 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) => { - return t.url.toLowerCase().includes(keyword.toLowerCase()) || - t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); - }).filter((t) => { - return !(excludePinned && t.pinned); - }); - } - - select(tabId) { - return browser.tabs.update(tabId, { active: true }); - } - - remove(ids) { - return browser.tabs.remove(ids); - } - - async reopen() { - let window = await browser.windows.getCurrent(); - let sessions = await browser.sessions.getRecentlyClosed(); - let session = sessions.find((s) => { - return s.tab && s.tab.windowId === window.id; - }); - if (!session) { - return; - } - if (session.tab) { - return browser.sessions.restore(session.tab.sessionId); - } - return browser.sessions.restore(session.window.sessionId); - } - - reload(tabId, cache) { - return browser.tabs.reload(tabId, { bypassCache: cache }); - } - - setPinned(tabId, pinned) { - return browser.tabs.update(tabId, { pinned }); - } - - duplicate(id) { - return browser.tabs.duplicate(id); - } - - getZoom(tabId) { - return browser.tabs.getZoom(tabId); - } - - setZoom(tabId, factor) { - return browser.tabs.setZoom(tabId, factor); - } - - onSelected(listener) { - 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); -}); diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts new file mode 100644 index 0000000..744be39 --- /dev/null +++ b/src/background/presenters/TabPresenter.ts @@ -0,0 +1,102 @@ +import MemoryStorage from '../infrastructures/MemoryStorage'; + +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 }); + } + + create(url, opts) { + return browser.tabs.create({ url, ...opts }); + } + + async getCurrent() { + let tabs = await browser.tabs.query({ + active: true, currentWindow: true + }); + return tabs[0]; + } + + getAll() { + 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) => { + return t.url.toLowerCase().includes(keyword.toLowerCase()) || + t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); + }).filter((t) => { + return !(excludePinned && t.pinned); + }); + } + + select(tabId) { + return browser.tabs.update(tabId, { active: true }); + } + + remove(ids) { + return browser.tabs.remove(ids); + } + + async reopen() { + let window = await browser.windows.getCurrent(); + let sessions = await browser.sessions.getRecentlyClosed(); + let session = sessions.find((s) => { + return s.tab && s.tab.windowId === window.id; + }); + if (!session) { + return; + } + if (session.tab) { + return browser.sessions.restore(session.tab.sessionId); + } + return browser.sessions.restore(session.window.sessionId); + } + + reload(tabId, cache) { + return browser.tabs.reload(tabId, { bypassCache: cache }); + } + + setPinned(tabId, pinned) { + return browser.tabs.update(tabId, { pinned }); + } + + duplicate(id) { + return browser.tabs.duplicate(id); + } + + getZoom(tabId) { + return browser.tabs.getZoom(tabId); + } + + setZoom(tabId, factor) { + return browser.tabs.setZoom(tabId, factor); + } + + onSelected(listener) { + 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); +}); diff --git a/src/background/presenters/WindowPresenter.js b/src/background/presenters/WindowPresenter.js deleted file mode 100644 index a82c4a2..0000000 --- a/src/background/presenters/WindowPresenter.js +++ /dev/null @@ -1,5 +0,0 @@ -export default class WindowPresenter { - create(url) { - return browser.windows.create({ url }); - } -} diff --git a/src/background/presenters/WindowPresenter.ts b/src/background/presenters/WindowPresenter.ts new file mode 100644 index 0000000..a82c4a2 --- /dev/null +++ b/src/background/presenters/WindowPresenter.ts @@ -0,0 +1,5 @@ +export default class WindowPresenter { + create(url) { + return browser.windows.create({ url }); + } +} -- cgit v1.2.3