Skip to content

Commit d0533b2

Browse files
committed
feat: add a context menu item (and a shortcut key) to open options page
#30
1 parent 2a7df24 commit d0533b2

7 files changed

Lines changed: 69 additions & 6 deletions

File tree

‎locales.toml‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ zh = "连接到文本编辑器"
9898
zh-tw = "連接到文本編輯器"
9999

100100
[manifest_commands_stop_ghostbird_description]
101-
# Description of the shortcut key to stop Ghostbird.
101+
# Description of the shortcut key to stop Ghostbird. Also used as a context menu item.
102102
ar = "قطع الاتصال بمحرر النصوص"
103103
be = "Адключыцца ад тэкставага рэдактара"
104104
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"
159159
zh = "切换与文本编辑器的连接"
160160
zh-tw = "切換與文本編輯器的連接"
161161

162+
[manifest_commands_open_options_description]
163+
# Description of the shortcut key to open the options. Also used as a context menu item.
164+
ar = "خيارات"
165+
be = "Параметры"
166+
ca = "Opcions"
167+
cs = "Možnosti"
168+
de = "Optionen"
169+
el = "Επιλογές"
170+
en = "Options"
171+
es = "Opciones"
172+
fi = "Asetukset"
173+
fr = "Options"
174+
hu = "Beállítások"
175+
id = "Opsi"
176+
it = "Opzioni"
177+
ja = "オプション"
178+
ko = "옵션"
179+
nl = "Opties"
180+
pl = "Opcje"
181+
pt = "Opções"
182+
pt-br = "Opções"
183+
ro = "Opțiuni"
184+
ru = "Настройки"
185+
sk = "Možnosti"
186+
th = "ตัวเลือก"
187+
tr = "Seçenekler"
188+
uk = "Параметри"
189+
vi = "Tùy chọn"
190+
zh = "选项"
191+
zh-tw = "選項"
192+
162193
[options_server_port]
163194
# Description of the option item for the server port.
164195
ar = "منفذ وجهة GhostText"

‎manifest_template.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
},
5050
"toggle_ghostbird": {
5151
"description": "__MSG_manifest_commands_toggle_ghostbird_description__"
52+
},
53+
"open_options": {
54+
"description": "__MSG_manifest_commands_open_options_description__"
5255
}
5356
},
5457
"background": {

‎src/app-background/api.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { MessageId } from "src/util"
44
export type { IGhostServerPort } from "src/ghosttext-adaptor/api"
55

66
/** IDs of shortcut keys. Must be in sync with ones in manifest.json */
7-
export type CommandId = "start_ghostbird" | "stop_ghostbird" | "toggle_ghostbird"
7+
export type CommandId = "start_ghostbird" | "stop_ghostbird" | "toggle_ghostbird" | "open_options"
88

99
/** Queries current shortcut key config */
1010
export interface ICommandConfig {
@@ -14,6 +14,12 @@ export interface ICommandConfig {
1414
getAll(): PromiseLike<Readonly<CommandInfo>[]>
1515
}
1616

17+
/** Miscellaneous UI utilities */
18+
export interface IUiUtil {
19+
/** Opens the options page for the extension */
20+
openOptionsPage(): Promise<void>
21+
}
22+
1723
/**
1824
* A single shortcut key command.
1925
*/

‎src/app-background/command_handler.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import type { IComposeWindow } from "src/ghosttext-adaptor"
2-
import type { CommandId } from "./api"
2+
import type { CommandId, IUiUtil } from "./api"
33
import type { ComposeActionNotifier } from "./compose_action_notifier"
44

55
/** Handles execution of commands in the context a compose tab */
66

77
export class CommandHandler {
88
static isSingleton = true
9-
constructor(private readonly composeActionNotifier: ComposeActionNotifier) {}
9+
constructor(
10+
private readonly composeActionNotifier: ComposeActionNotifier,
11+
private readonly uiUtil: IUiUtil,
12+
) {}
1013

1114
/** Executes a command in the context of a compose tab */
1215
runCommand(command: CommandId, composeTab: IComposeWindow): Promise<void> {
@@ -17,6 +20,8 @@ export class CommandHandler {
1720
return this.composeActionNotifier.stop(composeTab)
1821
case "toggle_ghostbird":
1922
return this.composeActionNotifier.toggle(composeTab)
23+
case "open_options":
24+
return this.uiUtil.openOptionsPage()
2025
}
2126
// We don't handle default here so that tsc checks for exhaustiveness
2227
}

‎src/ghosttext-adaptor/api.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ export interface IManifestInfo {
7979

8080
/** Options stored in local storage */
8181
export type StoredOptions = {
82+
/** The port of the GhostText server to connect to */
8283
serverPort: number
84+
/** Shows notifications when connecting or disconnecting from GhostText if true */
8385
enableNotifications: boolean
8486
}
8587

86-
/** * Loads options from storage */
88+
/** Manages access to options */
8789
export interface IStoredOptionsLoader {
88-
/** * Loads options from storage */
90+
/** Loads options from storage */
8991
load(): Promise<StoredOptions>
9092
}
9193

‎src/root/background.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const prepareThen: LazyThen<BackgroundEventRouter> = makeLazyThen(async () => {
2020
id: "stop_ghostbird",
2121
icon: "gray.svg",
2222
},
23+
{
24+
label: "manifest_commands_open_options_description",
25+
id: "open_options",
26+
icon: "gray.svg",
27+
},
2328
]
2429
let heart = new AlarmHeart(messenger)
2530

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { IUiUtil } from "src/app-background"
2+
3+
export class UiUtil implements IUiUtil {
4+
static isSingleton = true
5+
6+
constructor(private readonly messenger: typeof globalThis.messenger) {}
7+
8+
openOptionsPage(): Promise<void> {
9+
return this.messenger.runtime.openOptionsPage()
10+
}
11+
}

0 commit comments

Comments
 (0)