Skip to content

Commit

Permalink
separate user and shared data directory
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Jul 15, 2023
1 parent b810e8f commit 76e6662
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions checksum
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
185429368a2ee8a18ef1437e88de4b56 public/rime.data
9eb1e7b57b665f9cdb82d0aa5b866407 public/rime.js
f44908380a0f747edc0f20693393af94 public/rime.wasm
ebbb49f63e95479887b70c0de04f3d2a public/rime.data
fc04446bfceb2450f05c201d1c204295 public/rime.js
e77712e8aff7bd886fb3b647282e98ce public/rime.wasm
8 changes: 4 additions & 4 deletions doc/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Either provide

or
* a plum target
(e.g. rime/rime-luna-pinyin)
(e.g. `rime/rime-luna-pinyin`)
and a list of schema Ids
(e.g. luna_pinyin).
(e.g. `luna_pinyin`, `luna_pinyin_fluency`).

Click `Install`.

Expand All @@ -29,6 +29,6 @@ After making changes, click `Deploy`.
> **_NOTE:_** Because MEMFS is used, all changes will be lost after refresh.
Some conventions:
* The rime directory is `/rime`.
* The user data directory is `/rime`.
* The shared data directory is `/usr/share/rime-data`.
* OpenCC files are at `/usr/share/opencc`.
* All files in [rime-config](../rime-config/) will be available at `/rime` after you execute `pnpm run wasm`.
2 changes: 1 addition & 1 deletion scripts/build_wasm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const compileArgs = [
'-s', 'EXPORTED_FUNCTIONS=_init,_set_schema_name,_set_option,_set_ime,_process,_select_candidate_on_current_page,_deploy',
'-s', 'EXPORTED_RUNTIME_METHODS=["ccall","FS"]',
'--preload-file', `${OPENCC_HOST}@${OPENCC_TARGET}`,
'--preload-file', `${RIME_PATH}/build/default.yaml@rime/build/default.yaml`,
'--preload-file', `${RIME_PATH}/build/default.yaml@/usr/share/rime-data/build/default.yaml`,
'-I', 'build/sysroot/usr/include',
'-o', 'public/rime.js'
]
Expand Down
3 changes: 2 additions & 1 deletion src/components/MyEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ onMounted(() => {
'/rime/',
'/usr/',
'/usr/share/',
'/usr/share/opencc/'
'/usr/share/opencc/',
'/usr/share/rime-data/'
].forEach(wc.value!.expandFolder)
})
</script>
Expand Down
3 changes: 1 addition & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function fetchPrebuilt (schemaId: string) {
}
const files = getFiles(schemaId)
await Promise.all(files.map(async ({ name, target, md5 }) => {
const path = `build/${name}`
const path = `/usr/share/rime-data/build/${name}`
try {
Module.FS.lookupPath(path)
} catch (e) { // not exists
Expand All @@ -71,7 +71,6 @@ async function setIME (schemaId: string) {
const readyPromise = loadWasm('rime.js', {
url: '__LIBRESERVICE_CDN__',
init () {
Module.FS.chdir('rime') // set up user/shared dir for init
Module.ccall('init', 'null', [], [])
for (const [schema, name] of Object.entries(schemaName)) {
Module.ccall('set_schema_name', 'null', ['string', 'string'], [schema, name])
Expand Down
5 changes: 4 additions & 1 deletion wasm/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ void handler(void *context_object, RimeSessionId session_id,
std::string get_schema_name(std::string schema) { return schema_name[schema]; }

void startRime() {
RimeInitialize(NULL);
RIME_STRUCT(RimeTraits, traits);
traits.user_data_dir = "/rime";
traits.shared_data_dir = "/usr/share/rime-data";
RimeInitialize(&traits);
RimeSetNotificationHandler(handler, NULL);
}

Expand Down

0 comments on commit 76e6662

Please sign in to comment.