Skip to content

Commit d63688b

Browse files
authored
use wxt to build ime extension (#1)
1 parent fe94c75 commit d63688b

File tree

7 files changed

+172
-0
lines changed

7 files changed

+172
-0
lines changed

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-24.04
13+
steps:
14+
- uses: actions/checkout@v5
15+
16+
- uses: actions/setup-node@v5
17+
with:
18+
node-version: 24.x
19+
20+
- name: Install dependencies
21+
run: |
22+
npm i -g pnpm
23+
pnpm i
24+
25+
- name: Lint
26+
run: |
27+
pnpm run lint
28+
pnpm run check
29+
30+
- name: Build
31+
run: |
32+
pnpm run build
33+
34+
- name: Package zip
35+
working-directory: .output
36+
run:
37+
zip -r ../fcitx5-chrome.zip fcitx5-chrome
38+
39+
- name: Upload artifact
40+
if: ${{ github.ref != 'refs/heads/master' }}
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: artifact-chrome
44+
path: |
45+
fcitx5-chrome.zip
46+
47+
- name: Setup tmate session
48+
if: ${{ failure() }}
49+
uses: mxschmitt/action-tmate@v3
50+
51+
- name: Release
52+
if: ${{ github.ref == 'refs/heads/master' }}
53+
uses: 'marvinpinto/action-automatic-releases@latest'
54+
with:
55+
repo_token: ${{ secrets.GITHUB_TOKEN }}
56+
automatic_release_tag: latest
57+
prerelease: true
58+
title: "Nightly Build"
59+
files: |
60+
fcitx5-chrome.zip

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
node_modules
3+
pnpm-lock.yaml
4+
web-ext.config.ts
5+
.wxt
6+
.output
7+
*.zip

entrypoints/background.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
export default defineBackground(() => {
2+
if (!browser.input) {
3+
return
4+
}
5+
let contextID = 0
6+
const { ime } = browser.input
7+
8+
ime.onFocus.addListener((context) => {
9+
contextID = context.contextID
10+
})
11+
12+
ime.onBlur.addListener(() => {
13+
contextID = -1
14+
})
15+
16+
ime.onKeyEvent.addListener((engineID, keyData, requestId) => {
17+
if (keyData.type !== 'keydown') {
18+
return false
19+
}
20+
21+
if (/^[a-z]$/i.test(keyData.key)) {
22+
ime.setComposition({
23+
contextID,
24+
text: '',
25+
cursor: 0,
26+
})
27+
28+
const candidates = [
29+
{ candidate: 'foo', id: 0, label: '1' },
30+
{ candidate: 'bar', id: 1, label: '2' },
31+
]
32+
ime.setCandidates({
33+
contextID,
34+
candidates,
35+
})
36+
ime.setCandidateWindowProperties({
37+
engineID,
38+
properties: {
39+
visible: true,
40+
cursorVisible: true,
41+
vertical: true,
42+
pageSize: candidates.length,
43+
},
44+
})
45+
ime.keyEventHandled(requestId, true)
46+
return true
47+
}
48+
49+
ime.keyEventHandled(requestId, false)
50+
return false
51+
})
52+
53+
ime.onCandidateClicked.addListener((engineID, candidateID) => {
54+
ime.commitText({ contextID, text: candidateID.toString() })
55+
ime.setCandidates({
56+
contextID,
57+
candidates: [],
58+
})
59+
ime.setCandidateWindowProperties({ engineID, properties: { visible: false } })
60+
})
61+
})

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import antfu from '@antfu/eslint-config'
2+
3+
export default antfu()

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "fcitx5-chrome",
3+
"version": "0.1.0",
4+
"description": "Fcitx5 Chrome edition",
5+
"license": "AGPL-3.0-or-later",
6+
"scripts": {
7+
"build": "wxt build",
8+
"postinstall": "wxt prepare",
9+
"lint": "eslint entrypoints",
10+
"lint:fix": "eslint entrypoints --fix",
11+
"check": "tsc --noEmit"
12+
},
13+
"devDependencies": {
14+
"@antfu/eslint-config": "^5.3.0",
15+
"eslint": "^9.35.0",
16+
"typescript": "^5.9.2",
17+
"wxt": "^0.20.11"
18+
}
19+
}

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.wxt/tsconfig.json"
3+
}

wxt.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineConfig } from 'wxt'
2+
3+
export default defineConfig({
4+
manifest: {
5+
name: 'Fcitx5',
6+
permissions: [
7+
'input',
8+
],
9+
input_components: [{
10+
name: 'Fcitx5',
11+
type: 'ime',
12+
id: 'fcitx5',
13+
description: 'Fcitx5 input method framework',
14+
language: ['en-US'],
15+
layouts: ['us'],
16+
}],
17+
},
18+
outDirTemplate: 'fcitx5-chrome',
19+
})

0 commit comments

Comments
 (0)