diff --git a/README.md b/README.md index 1c7351d..1c35c28 100644 --- a/README.md +++ b/README.md @@ -259,10 +259,8 @@ If you've looked at the options above and still want to motivate the maintainer ### Services [![Github Actions Status](https://github.com/exteditor/ghostbird/actions/workflows/build.yml/badge.svg)](https://github.com/exteditor/ghostbird/actions/workflows/build.yml) -[![Reviewed by CodeRabbit](https://img.shields.io/badge/reviewed_by-CodeRabbit-ff570a?logo=coderabbit)](https://github.com/search?q=repo%3Aexteditor%2Fghostbird&type=pullrequests&s=created&o=desc) -[![Test coverage tracked with Codecov](https://codecov.io/github/exteditor/ghostbird/graph/badge.svg?token=NDWAK8NEC6)](https://codecov.io/github/exteditor/ghostbird) -[![Bundle size tracked with Codecov (esm)](https://codecov.io/github/exteditor/ghostbird/graph/bundle/esm/badge.svg?token=NDWAK8NEC6)](https://codecov.io/github/exteditor/ghostbird/bundles/background) -[![Bundle size tracked with Codecov (iife)](https://codecov.io/github/exteditor/ghostbird/graph/bundle/iife/badge.svg?token=NDWAK8NEC6)](https://codecov.io/github/exteditor/ghostbird/bundles/compose) +[![Reviewed by CodeRabbit](https://img.shields.io/coderabbit/prs/github/exteditor/ghostbird?utm_source=oss&utm_medium=github&utm_campaign=exteditor%2Fghostbird&color=FF570A&link=https%3A%2F%2Fcoderabbit.ai&label=CodeRabbit+Reviews&logo=coderabbit&logoSize=auto)](https://github.com/search?q=repo%3Aexteditor%2Fghostbird&type=pullrequests&s=created&o=desc) +[![Covered by Codecov](https://codecov.io/github/exteditor/ghostbird/graph/badge.svg?token=NDWAK8NEC6)](https://app.codecov.io/github/exteditor/ghostbird/commits) ## License diff --git a/locales.toml b/locales.toml index 162e98e..8bf9f5a 100644 --- a/locales.toml +++ b/locales.toml @@ -98,7 +98,7 @@ zh = "连接到文本编辑器" zh-tw = "連接到文本編輯器" [manifest_commands_stop_ghostbird_description] -# Description of the shortcut key to stop Ghostbird. +# Description of the shortcut key to stop Ghostbird. Also used as a context menu item. ar = "قطع الاتصال بمحرر النصوص" be = "Адключыцца ад тэкставага рэдактара" ca = "Desconnecta de l'editor de text" @@ -159,6 +159,37 @@ vi = "Chuyển đổi kết nối với trình soạn thảo văn bản" zh = "切换与文本编辑器的连接" zh-tw = "切換與文本編輯器的連接" +[manifest_commands_open_options_description] +# Description of the shortcut key to open the options. Also used as a context menu item. +ar = "خيارات" +be = "Параметры" +ca = "Opcions" +cs = "Možnosti" +de = "Optionen" +el = "Επιλογές" +en = "Options" +es = "Opciones" +fi = "Asetukset" +fr = "Options" +hu = "Beállítások" +id = "Opsi" +it = "Opzioni" +ja = "オプション" +ko = "옵션" +nl = "Opties" +pl = "Opcje" +pt = "Opções" +pt-br = "Opções" +ro = "Opțiuni" +ru = "Настройки" +sk = "Možnosti" +th = "ตัวเลือก" +tr = "Seçenekler" +uk = "Параметри" +vi = "Tùy chọn" +zh = "选项" +zh-tw = "選項" + [options_server_port] # Description of the option item for the server port. ar = "منفذ وجهة GhostText" diff --git a/manifest_template.json b/manifest_template.json index b91d473..2e72ca2 100644 --- a/manifest_template.json +++ b/manifest_template.json @@ -49,6 +49,9 @@ }, "toggle_ghostbird": { "description": "__MSG_manifest_commands_toggle_ghostbird_description__" + }, + "open_options": { + "description": "__MSG_manifest_commands_open_options_description__" } }, "background": { diff --git a/src/app-background/api.ts b/src/app-background/api.ts index 357c9b6..4684b6c 100644 --- a/src/app-background/api.ts +++ b/src/app-background/api.ts @@ -4,7 +4,7 @@ import type { MessageId } from "src/util" export type { IGhostServerPort } from "src/ghosttext-adaptor/api" /** IDs of shortcut keys. Must be in sync with ones in manifest.json */ -export type CommandId = "start_ghostbird" | "stop_ghostbird" | "toggle_ghostbird" +export type CommandId = "start_ghostbird" | "stop_ghostbird" | "toggle_ghostbird" | "open_options" /** Queries current shortcut key config */ export interface ICommandConfig { @@ -14,6 +14,12 @@ export interface ICommandConfig { getAll(): PromiseLike[]> } +/** Miscellaneous UI utilities */ +export interface IUiUtil { + /** Opens the options page for the extension */ + openOptionsPage(): Promise +} + /** * A single shortcut key command. */ diff --git a/src/app-background/command_handler.ts b/src/app-background/command_handler.ts index 8404a05..91b51a0 100644 --- a/src/app-background/command_handler.ts +++ b/src/app-background/command_handler.ts @@ -1,12 +1,15 @@ import type { IComposeWindow } from "src/ghosttext-adaptor" -import type { CommandId } from "./api" +import type { CommandId, IUiUtil } from "./api" import type { ComposeActionNotifier } from "./compose_action_notifier" /** Handles execution of commands in the context a compose tab */ export class CommandHandler { static isSingleton = true - constructor(private readonly composeActionNotifier: ComposeActionNotifier) {} + constructor( + private readonly composeActionNotifier: ComposeActionNotifier, + private readonly uiUtil: IUiUtil, + ) {} /** Executes a command in the context of a compose tab */ runCommand(command: CommandId, composeTab: IComposeWindow): Promise { @@ -17,6 +20,8 @@ export class CommandHandler { return this.composeActionNotifier.stop(composeTab) case "toggle_ghostbird": return this.composeActionNotifier.toggle(composeTab) + case "open_options": + return this.uiUtil.openOptionsPage() } // We don't handle default here so that tsc checks for exhaustiveness } diff --git a/src/ghosttext-adaptor/api.ts b/src/ghosttext-adaptor/api.ts index 5f161f9..bf7ca61 100644 --- a/src/ghosttext-adaptor/api.ts +++ b/src/ghosttext-adaptor/api.ts @@ -79,13 +79,15 @@ export interface IManifestInfo { /** Options stored in local storage */ export type StoredOptions = { + /** The port of the GhostText server to connect to */ serverPort: number + /** Shows notifications when connecting or disconnecting from GhostText if true */ enableNotifications: boolean } -/** * Loads options from storage */ +/** Manages access to options */ export interface IStoredOptionsLoader { - /** * Loads options from storage */ + /** Loads options from storage */ load(): Promise } diff --git a/src/root/background.ts b/src/root/background.ts index 6765606..81083e4 100644 --- a/src/root/background.ts +++ b/src/root/background.ts @@ -20,6 +20,11 @@ const prepareThen: LazyThen = makeLazyThen(async () => { id: "stop_ghostbird", icon: "gray.svg", }, + { + label: "manifest_commands_open_options_description", + id: "open_options", + icon: "gray.svg", + }, ] let heart = new AlarmHeart(messenger) diff --git a/src/thunderbird/background_util/ui_util.ts b/src/thunderbird/background_util/ui_util.ts new file mode 100644 index 0000000..a4ae5b1 --- /dev/null +++ b/src/thunderbird/background_util/ui_util.ts @@ -0,0 +1,11 @@ +import type { IUiUtil } from "src/app-background" + +export class UiUtil implements IUiUtil { + static isSingleton = true + + constructor(private readonly messenger: typeof globalThis.messenger) {} + + openOptionsPage(): Promise { + return this.messenger.runtime.openOptionsPage() + } +} diff --git a/src/thunderbird/messenger/alarms.ts b/src/thunderbird/messenger/alarms.ts index e4c6a1d..de3c0e0 100644 --- a/src/thunderbird/messenger/alarms.ts +++ b/src/thunderbird/messenger/alarms.ts @@ -1,6 +1,6 @@ /** * @file `messenger.alarms` API somehow missing in the type lib - * @see https://webextension-api.thunderbird.net/en/128-esr-mv3/alarms.html + * @see https://webextension-api.thunderbird.net/en/esr-mv3/alarms.html */ /** Use the scripting API to execute script in different contexts. */ diff --git a/src/thunderbird/messenger/global.ts b/src/thunderbird/messenger/global.ts index b7da850..b69a676 100644 --- a/src/thunderbird/messenger/global.ts +++ b/src/thunderbird/messenger/global.ts @@ -1,6 +1,6 @@ /** * @file Functions added in Thunderbird 128 ESR - * @see https://webextension-api.thunderbird.net/en/128-esr-mv3/ + * @see https://webextension-api.thunderbird.net/en/esr-mv3/ */ import type { IAlarmsAPI } from "./alarms" diff --git a/src/thunderbird/messenger/scripting.ts b/src/thunderbird/messenger/scripting.ts index a177aee..fd084f5 100644 --- a/src/thunderbird/messenger/scripting.ts +++ b/src/thunderbird/messenger/scripting.ts @@ -1,6 +1,6 @@ /** * @file `messenger.scripting` API added at Thunderbird 128 ESR - * @see https://webextension-api.thunderbird.net/en/128-esr-mv3/scripting.html + * @see https://webextension-api.thunderbird.net/en/esr-mv3/scripting.html */ import type { PlainJSONValue } from "./"