aboutsummaryrefslogtreecommitdiff
path: root/src/background/presenters
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/presenters')
-rw-r--r--src/background/presenters/IndicatorPresenter.ts4
-rw-r--r--src/background/presenters/NotifyPresenter.ts8
-rw-r--r--src/background/presenters/TabPresenter.ts44
-rw-r--r--src/background/presenters/WindowPresenter.ts2
4 files changed, 34 insertions, 24 deletions
diff --git a/src/background/presenters/IndicatorPresenter.ts b/src/background/presenters/IndicatorPresenter.ts
index 5737519..d9a615a 100644
--- a/src/background/presenters/IndicatorPresenter.ts
+++ b/src/background/presenters/IndicatorPresenter.ts
@@ -1,12 +1,12 @@
export default class IndicatorPresenter {
- indicate(enabled) {
+ indicate(enabled: boolean): Promise<void> {
let path = enabled
? 'resources/enabled_32x32.png'
: 'resources/disabled_32x32.png';
return browser.browserAction.setIcon({ path });
}
- onClick(listener) {
+ onClick(listener: (arg: browser.tabs.Tab) => void): void {
browser.browserAction.onClicked.addListener(listener);
}
}
diff --git a/src/background/presenters/NotifyPresenter.ts b/src/background/presenters/NotifyPresenter.ts
index a81f227..c83c205 100644
--- a/src/background/presenters/NotifyPresenter.ts
+++ b/src/background/presenters/NotifyPresenter.ts
@@ -1,8 +1,12 @@
const NOTIFICATION_ID = 'vimvixen-update';
export default class NotifyPresenter {
- notify(title, message, onclick) {
- const listener = (id) => {
+ notify(
+ title: string,
+ message: string,
+ onclick: () => void,
+ ): Promise<string> {
+ const listener = (id: string) => {
if (id !== NOTIFICATION_ID) {
return;
}
diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts
index 744be39..33c6513 100644
--- a/src/background/presenters/TabPresenter.ts
+++ b/src/background/presenters/TabPresenter.ts
@@ -3,27 +3,29 @@ import MemoryStorage from '../infrastructures/MemoryStorage';
const CURRENT_SELECTED_KEY = 'tabs.current.selected';
const LAST_SELECTED_KEY = 'tabs.last.selected';
+type Tab = browser.tabs.Tab;
+
export default class TabPresenter {
- open(url, tabId) {
+ open(url: string, tabId?: number): Promise<Tab> {
return browser.tabs.update(tabId, { url });
}
- create(url, opts) {
+ create(url: string, opts?: object): Promise<Tab> {
return browser.tabs.create({ url, ...opts });
}
- async getCurrent() {
+ async getCurrent(): Promise<Tab> {
let tabs = await browser.tabs.query({
active: true, currentWindow: true
});
return tabs[0];
}
- getAll() {
+ getAll(): Promise<Tab[]> {
return browser.tabs.query({ currentWindow: true });
}
- async getLastSelectedId() {
+ async getLastSelectedId(): Promise<number | undefined> {
let cache = new MemoryStorage();
let tabId = await cache.get(LAST_SELECTED_KEY);
if (tabId === null || typeof tabId === 'undefined') {
@@ -32,25 +34,25 @@ export default class TabPresenter {
return tabId;
}
- async getByKeyword(keyword, excludePinned = false) {
+ async getByKeyword(keyword: string, excludePinned = false): Promise<Tab[]> {
let tabs = await browser.tabs.query({ currentWindow: true });
return tabs.filter((t) => {
- return t.url.toLowerCase().includes(keyword.toLowerCase()) ||
+ return t.url && t.url.toLowerCase().includes(keyword.toLowerCase()) ||
t.title && t.title.toLowerCase().includes(keyword.toLowerCase());
}).filter((t) => {
return !(excludePinned && t.pinned);
});
}
- select(tabId) {
+ select(tabId: number): Promise<Tab> {
return browser.tabs.update(tabId, { active: true });
}
- remove(ids) {
+ remove(ids: number[]): Promise<void> {
return browser.tabs.remove(ids);
}
- async reopen() {
+ async reopen(): Promise<any> {
let window = await browser.windows.getCurrent();
let sessions = await browser.sessions.getRecentlyClosed();
let session = sessions.find((s) => {
@@ -59,39 +61,43 @@ export default class TabPresenter {
if (!session) {
return;
}
- if (session.tab) {
+ if (session.tab && session.tab.sessionId) {
return browser.sessions.restore(session.tab.sessionId);
}
- return browser.sessions.restore(session.window.sessionId);
+ if (session.window && session.window.sessionId) {
+ return browser.sessions.restore(session.window.sessionId);
+ }
}
- reload(tabId, cache) {
+ reload(tabId: number, cache: boolean): Promise<void> {
return browser.tabs.reload(tabId, { bypassCache: cache });
}
- setPinned(tabId, pinned) {
+ setPinned(tabId: number, pinned: boolean): Promise<Tab> {
return browser.tabs.update(tabId, { pinned });
}
- duplicate(id) {
+ duplicate(id: number): Promise<Tab> {
return browser.tabs.duplicate(id);
}
- getZoom(tabId) {
+ getZoom(tabId: number): Promise<number> {
return browser.tabs.getZoom(tabId);
}
- setZoom(tabId, factor) {
+ setZoom(tabId: number, factor: number): Promise<void> {
return browser.tabs.setZoom(tabId, factor);
}
- onSelected(listener) {
+ onSelected(
+ listener: (arg: { tabId: number, windowId: number}) => void,
+ ): void {
browser.tabs.onActivated.addListener(listener);
}
}
let tabPresenter = new TabPresenter();
-tabPresenter.onSelected((tab) => {
+tabPresenter.onSelected((tab: any) => {
let cache = new MemoryStorage();
let lastId = cache.get(CURRENT_SELECTED_KEY);
diff --git a/src/background/presenters/WindowPresenter.ts b/src/background/presenters/WindowPresenter.ts
index a82c4a2..e04f258 100644
--- a/src/background/presenters/WindowPresenter.ts
+++ b/src/background/presenters/WindowPresenter.ts
@@ -1,5 +1,5 @@
export default class WindowPresenter {
- create(url) {
+ create(url: string): Promise<browser.windows.Window> {
return browser.windows.create({ url });
}
}