Skip to content

Commit

Permalink
loadZip
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Dec 22, 2024
1 parent adcbc2f commit 172772d
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: ci

on:
push:
branches:
- master
pull_request:

jobs:
build:
runs-on: ubuntu-24.04
env:
EMSCRIPTEN_VERSION: '3.1.74'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Install dependencies
run: |
sudo apt install -y \
ninja-build \
gettext
npm i -g pnpm
pnpm i
./scripts/install-deps.sh
- name: Install emsdk
run: |
git clone https://github.com/emscripten-core/emsdk
cd emsdk
./emsdk install ${{ env.EMSCRIPTEN_VERSION }}
./emsdk activate ${{ env.EMSCRIPTEN_VERSION }}
- name: Build
run: |
. emsdk/emsdk_env.sh
pnpm run configure
pnpm run build
npm pack
- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3

- name: Release
if: ${{ github.ref == 'refs/heads/master' }}
uses: 'marvinpinto/action-automatic-releases@latest'
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: latest
prerelease: true
title: "Nightly Build"
files: |
fcitx5-rime.js-*.tgz
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.27)

project(fcitx5-rime-js VERSION 0.1.0)

option(RIME_ONLY "" ON)
add_subdirectory(fcitx5-js)
target_link_libraries(Fcitx5
"--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/lib/fcitx5/librime.so@/usr/lib/fcitx5/librime.so"
"--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/fcitx5/addon/rime.conf@/usr/share/fcitx5/addon/rime.conf"
"--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/fcitx5/inputmethod/rime.conf@/usr/share/fcitx5/inputmethod/rime.conf"
"--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/rime-data/opencc@/usr/share/rime-data/opencc"
"--embed-file ${PROJECT_SOURCE_DIR}/cache/placeholder.yaml@/usr/share/rime-data/default.yaml" # fcitx5-rime requires this file.
"--extern-post-js ${PROJECT_SOURCE_DIR}/src/rime.js"
)
Empty file added README.md
Empty file.
Empty file added cache/placeholder.yaml
Empty file.
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="module">
import { loadZip } from "./dist/Fcitx5.js"
await loadZip('./rime-ice.zip')
</script>
<textarea></textarea>
</body>
</html>
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "fcitx5-rime.js",
"version": "0.1.0",
"description": "Fcitx5 Rime as a JavaScript library",
"type": "module",
"files": [
"dist"
],
"author": {
"name": "Qijia Liu",
"email": "[email protected]",
"url": "https://github.com/eagleoflqj"
},
"scripts": {
"configure": "emcmake cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug",
"build": "EMCC_FORCE_STDLIBS=libc++ FCITX_DISTRIBUTION=fcitx5-js cmake --build build",
"preview": "serve -S",
"prepack": "bash scripts/prepack.sh"
},
"license": "AGPL-3.0-or-later",
"devDependencies": {
"serve": "^14.2.4"
}
}
13 changes: 13 additions & 0 deletions scripts/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

pnpm i --prefix=fcitx5-js
pnpm i --prefix=fcitx5-js/fcitx5-webview

./fcitx5-js/scripts/install-deps.sh
file=rime.zip
[[ -f cache/$file ]] || wget -P cache https://github.com/fcitx-contrib/fcitx5-plugins/releases/download/js/$file
unzip -d build/sysroot/usr cache/$file

mkdir -p build/fcitx5-js
ln -sf ../sysroot build/fcitx5-js
ln -sf ../build/fcitx5-js fcitx5-js/build
8 changes: 8 additions & 0 deletions scripts/prepack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set -e

rm -rf dist/*
mkdir -p dist

cp build/sysroot/usr/lib/libFcitx5* dist
cp build/fcitx5-js/src/Fcitx5.* dist
cp fcitx5-js/page/Fcitx5.d.ts dist
9 changes: 9 additions & 0 deletions src/rime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export async function loadZip(url) {
const [_, schema] = await Promise.all([
fcitxReady,
fetch(url).then(res => res.arrayBuffer())
])
window.fcitx.unzip(schema, '/usr/share/rime-data')
window.fcitx.enable()
window.fcitx.setInputMethods(['rime'])
}

0 comments on commit 172772d

Please sign in to comment.