Skip to content

Commit 47d7e7d

Browse files
committed
feat: implement a simple option page #3
Squashed commit of the following: commit 4846648 Author: snipsnipsnip <[email protected]> Date: Tue Sep 23 15:59:30 2025 +0900 fix: address warnings from the AMO add-on validator * In the compose script, the HTML body should be parsed and appended rather than setting `innerHTML` directly. * Add a `data_collection_permissions` key that will be used to notify users about the personal data the add‑on collects; in our case it's `none`. https://blog.mozilla.org/addons/2025/05/09/new-extension-data-consent-experience-now-available-in-firefox-nightly/ commit 08da813 Author: snipsnipsnip <[email protected]> Date: Sun Sep 21 22:24:33 2025 +0900 feat: send a readable hostname to the GhostText server Ghostbird used to send a random UUID generated by Thunderbird as the `url` field in the GhostText handshake. Send a more permanent value (the add-on ID defined in the `manifest.json`) instead of UUIDs. While we're at it, modify the add-on ID to include `addons.thunderbird` to make it clearer that this is a Thunderbird add-on. The change is needed because moving the `description` to `messages.json` made it less obvious. commit 9dd96f0 Author: snipsnipsnip <[email protected]> Date: Sun Sep 21 21:52:12 2025 +0900 feat: implement a simple option page #3
1 parent 79f73cb commit 47d7e7d

29 files changed

Lines changed: 460 additions & 139 deletions

‎ext/options.css‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
@import "chrome://global/skin/in-content/common.css";
2+
@import "options.nolint.css";
3+
:root {
4+
background: var(--background-color-box);
5+
direction: var(--direction);
6+
}
7+
ghostbird-options {
8+
margin: 1rem;
9+
display: flex;
10+
flex-direction: column;
11+
align-items: center;
12+
align-content: center;
13+
justify-content: center;
14+
}
15+
form {
16+
display: grid;
17+
grid-template: auto / 1fr auto;
18+
border-radius: var(--border-radius-medium);
19+
border: 1px solid var(--border-color);
20+
box-shadow: var(--box-shadow-level-2);
21+
}
22+
form > * {
23+
align-items: center;
24+
align-content: center;
25+
background: var(--layout-background-2);
26+
padding: 0.5rem 1rem;
27+
}
28+
form > *:first-child {
29+
border-start-start-radius: var(--border-radius-medium);
30+
}
31+
form > *:nth-child(2) {
32+
border-start-end-radius: var(--border-radius-medium);
33+
}
34+
form > *:nth-last-child(2) {
35+
border-end-start-radius: var(--border-radius-medium);
36+
}
37+
form > *:last-child {
38+
border-end-end-radius: var(--border-radius-medium);
39+
}
40+
input {
41+
width: 100%;
42+
height: 100%;
43+
}
44+
input[type="number"] {
45+
text-align: var(--align-end);
46+
}
47+
input[type="reset"] {
48+
height: var(--in-content-button-height);
49+
}
50+
label[for="serverPort"]::before {
51+
content: "__MSG_options_server_port__";
52+
}
53+
label[for="enableNotifications"]::before {
54+
content: "__MSG_options_enable_notifications__";
55+
}
56+
.progress.saved::before {
57+
content: "__MSG_options_saved__";
58+
color: var(--color-success-default);
59+
animation: fadeOut 1s forwards;
60+
}
61+
.progress.error::before {
62+
content: "__MSG_options_error__";
63+
color: var(--color-danger-default);
64+
animation: fadeOut 1s forwards;
65+
}
66+
67+
@keyframes fadeOut {
68+
0% {
69+
opacity: 1;
70+
}
71+
90% {
72+
opacity: 1;
73+
}
74+
100% {
75+
opacity: 0;
76+
}
77+
}

‎ext/options.html‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5+
<title>Ghostbird Options</title>
56
<script type="module" src="js/options.js"></script>
7+
<link rel="stylesheet" href="options.css">
68
</head>
79
<body>
8-
<h1>Ghostbird: GhostText for Thunderbird</h1>
9-
<p>
10-
Options are still in development. See
11-
<a href="https://github.com/exteditor/ghostbird/">GitHub page</a>for the
12-
roadmap.
13-
</pp>
14-
<ghostbird-options></ghostbird-options>
10+
<ghostbird-options>
11+
<form>
12+
<label for="serverPort"></label>
13+
<label>
14+
<input
15+
id="serverPort"
16+
name="serverPort"
17+
type="number"
18+
min="1"
19+
max="65535"
20+
size="4"
21+
>
22+
</label>
23+
<span></span>
24+
<span
25+
><input type="reset"></span
26+
>
27+
</form>
28+
<div class="progress"></div>
29+
</ghostbird-options>
1530
</body>
1631
</html>

‎ext/options.nolint.css‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* biome-ignore-all parse: These rules are preprocessed at runtime by Thunderbird, producing valid css */
2+
/* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Internationalization#predefined_messages */
3+
:root {
4+
--direction: __MSG_@@bidi_dir__;
5+
--align-end: __MSG_@@bidi_end_edge__;
6+
}

‎locales.toml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ ja = "テキストエディタから切断"
3030
# Description of the shortcut key to toggle Ghostbird.
3131
en = "Toggle connection with the text editor"
3232
ja = "テキストエディタとの接続を切り替え"
33+
34+
[options_server_port]
35+
en = "GhostText destination port"
36+
ja = "GhostText接続先ポート"
37+
38+
[options_enable_notifications]
39+
en = "Show notifications"
40+
ja = "通知を表示する"
41+
42+
[options_saved]
43+
en = "Options saved"
44+
ja = "保存しました"
45+
46+
[options_error]
47+
en = "Error saving options"
48+
ja = "保存に失敗しました"

‎manifest_template.json‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
"author": "snipsnipsnip",
1111
"browser_specific_settings": {
1212
"gecko": {
13-
"id": "@ghostbird.exteditor.github.io",
14-
"strict_min_version": "128.0"
13+
"id": "@ghostbird.exteditor.addons.thunderbird.net",
14+
"strict_min_version": "128.0",
15+
"data_collection_permissions": {
16+
"required": [
17+
"none"
18+
]
19+
}
1520
}
1621
},
1722
"permissions": [

‎src/app-background/background_event_router.ts‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
import type { IComposeWindow } from "src/ghosttext-adaptor/api"
2-
import type { CommandId, ICommandConfig, IComposeWindowDetector, ITab } from "./api"
2+
import type { CommandId, IComposeWindowDetector, ITab } from "./api"
33
import type { ComposeActionNotifier } from "./compose_action_notifier"
44

55
export class BackgroundEventRouter {
66
static isSingleton = true
77

88
constructor(
9-
readonly composeActionNotifier: ComposeActionNotifier,
10-
readonly composeTabDetector: IComposeWindowDetector,
11-
readonly commandConfig: ICommandConfig,
9+
private readonly composeActionNotifier: ComposeActionNotifier,
10+
private readonly composeTabDetector: IComposeWindowDetector,
1211
) {}
1312

1413
/** Handles shortcut key presses defined in the manifest.json */
15-
async handleCommand(command: string, tab: ITab): Promise<void> {
16-
console.log("handleCommand")
17-
18-
let isToggleMode = this.isToggleMode()
14+
handleCommand(command: string, tab: ITab): Promise<void> {
1915
let composeTab = this.composeTabDetector.tryWrap(tab)
2016
if (!composeTab) {
21-
throw Error("Event dropped")
22-
}
23-
24-
if (await isToggleMode) {
25-
return this.composeActionNotifier.toggle(composeTab)
17+
return Promise.reject(Error("Event dropped"))
2618
}
2719

2820
return this.runCommand(command, composeTab)
@@ -40,12 +32,6 @@ export class BackgroundEventRouter {
4032
// We don't handle default here so that tsc checks for exhaustiveness
4133
}
4234

43-
private async isToggleMode(): Promise<boolean> {
44-
let config = await this.commandConfig.getAll()
45-
46-
return new Set(config.map((x) => x.shortcut)).size === 1
47-
}
48-
4935
/** Handles the toolbar button press */
5036
handleComposeAction(tab: ITab): Promise<void> {
5137
console.log("handleComposeAction")

‎src/app-background/client_options.ts‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎src/app-background/compose_action_notifier.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import type { IComposeWindow, IGhostServerPort } from "src/ghosttext-adaptor/api"
22
import { EmailEditor } from "src/ghosttext-adaptor/email_editor"
3-
import type { GhostTextRunner } from "src/ghosttext-runner"
3+
import type { GhostTextRunner, IClientOptionsLoader } from "src/ghosttext-runner"
44

55
export class ComposeActionNotifier {
66
static isSingleton = true
7-
readonly runners = new Map<number, IGhostServerPort>()
7+
private readonly runners = new Map<number, IGhostServerPort>()
88

9-
constructor(readonly ghostTextRunner: GhostTextRunner) {}
9+
constructor(
10+
private readonly ghostTextRunner: GhostTextRunner,
11+
private readonly clientOptionsLoader: IClientOptionsLoader,
12+
) {}
1013

1114
async start(tab: IComposeWindow): Promise<void> {
1215
if (this.findOpenPort(tab)) {
@@ -20,8 +23,9 @@ export class ComposeActionNotifier {
2023

2124
try {
2225
console.info("starting session")
23-
let editor = new EmailEditor(tab, port)
24-
await this.ghostTextRunner.run(editor, editor)
26+
const options = await this.clientOptionsLoader.load()
27+
const editor = new EmailEditor(tab, port, options)
28+
await this.ghostTextRunner.run(editor, editor, options)
2529
} finally {
2630
console.info("session closed")
2731
this.close(tab, port)

‎src/app-compose/body_editor.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export class BodyEditor {
2+
static isSingleton = true
3+
4+
constructor(
5+
private readonly body: HTMLBodyElement,
6+
private readonly domParser: DOMParser,
7+
) {}
8+
9+
getBody(isPlainText: boolean): string {
10+
return (isPlainText ? this.body.textContent : this.body.innerHTML) ?? ""
11+
}
12+
13+
applyEdit(body: string, isPlainText: boolean): void {
14+
if (isPlainText) {
15+
this.body.textContent = body
16+
} else {
17+
const doc = this.domParser.parseFromString(body, "text/html")
18+
this.body.innerHTML = ""
19+
this.body.append(...doc.body.childNodes)
20+
}
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export class ComposeEditListener {
2+
static isSingleton = true
3+
4+
constructor(
5+
private readonly body: HTMLBodyElement,
6+
private readonly selection: Selection,
7+
) {}
8+
9+
listen(): () => void {
10+
const body = this.body
11+
const selection = this.selection
12+
const disable = (e: Event): void => {
13+
e.preventDefault()
14+
selection.removeAllRanges()
15+
}
16+
const controller = new AbortController()
17+
const option = { signal: controller.signal }
18+
19+
body.addEventListener("beforeinput", disable, option)
20+
body.addEventListener("paste", disable, option)
21+
body.addEventListener("cut", disable, option)
22+
body.addEventListener("drop", disable, option)
23+
body.addEventListener("dragover", disable, option)
24+
body.ownerDocument.addEventListener("selectionchange", disable, option)
25+
26+
body.style.background = "lightgray"
27+
28+
controller.signal.addEventListener("abort", () => {
29+
body.style.removeProperty("background")
30+
})
31+
32+
return (): void => controller.abort()
33+
}
34+
}

0 commit comments

Comments
 (0)