diff options
Diffstat (limited to 'src/background/presenters')
-rw-r--r-- | src/background/presenters/Notifier.ts | 4 | ||||
-rw-r--r-- | src/background/presenters/WindowPresenter.ts | 11 | ||||
-rw-r--r-- | src/background/presenters/ZoomPresenter.ts | 60 |
3 files changed, 68 insertions, 7 deletions
diff --git a/src/background/presenters/Notifier.ts b/src/background/presenters/Notifier.ts index 2cd3225..957572d 100644 --- a/src/background/presenters/Notifier.ts +++ b/src/background/presenters/Notifier.ts @@ -30,10 +30,10 @@ export class NotifierImpl implements NotifierImpl { } async notifyInvalidSettings(onclick: () => void): Promise<void> { - const title = `Loaded settings is invalid`; + const title = `Loading settings failed`; // eslint-disable-next-line max-len const message = - "The default settings is used due to the last saved settings is invalid. Check your current settings from the add-on preference"; + "The default settings are used due to the last saved settings is invalid. Check your current settings from the add-on preference"; const listener = (id: string) => { if (id !== NOTIFICATION_ID_INVALID_SETTINGS) { diff --git a/src/background/presenters/WindowPresenter.ts b/src/background/presenters/WindowPresenter.ts index 4f37f5d..5eb0f22 100644 --- a/src/background/presenters/WindowPresenter.ts +++ b/src/background/presenters/WindowPresenter.ts @@ -1,8 +1,9 @@ -import { injectable } from "tsyringe"; +export default interface WindowPresenter { + create(url: string): Promise<void>; +} -@injectable() -export default class WindowPresenter { - create(url: string): Promise<browser.windows.Window> { - return browser.windows.create({ url }); +export class WindowPresenterImpl implements WindowPresenter { + async create(url: string): Promise<void> { + await browser.windows.create({ url }); } } diff --git a/src/background/presenters/ZoomPresenter.ts b/src/background/presenters/ZoomPresenter.ts new file mode 100644 index 0000000..5a3c64d --- /dev/null +++ b/src/background/presenters/ZoomPresenter.ts @@ -0,0 +1,60 @@ +const ZOOM_SETTINGS = [ + 0.33, + 0.5, + 0.66, + 0.75, + 0.8, + 0.9, + 1.0, + 1.1, + 1.25, + 1.5, + 1.75, + 2.0, + 2.5, + 3.0, +] as const; + +export default interface ZoomPresenter { + zoomIn(): Promise<void>; + zoomOut(): Promise<void>; + resetZoom(): Promise<void>; +} + +export class ZoomPresenterImpl implements ZoomPresenter { + async zoomIn(): Promise<void> { + const tab = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + const tabId = tab[0].id as number; + const current = await browser.tabs.getZoom(tabId); + const factor = ZOOM_SETTINGS.find((f) => f > current); + if (factor) { + return browser.tabs.setZoom(tabId, factor); + } + } + + async zoomOut(): Promise<void> { + const tab = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + const tabId = tab[0].id as number; + const current = await browser.tabs.getZoom(tabId); + const factor = ZOOM_SETTINGS.slice(0) + .reverse() + .find((f) => f < current); + if (factor) { + return browser.tabs.setZoom(tabId, factor); + } + } + + async resetZoom(): Promise<void> { + const tab = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + return browser.tabs.setZoom(tab[0].id, 1); + } +} |