mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-10-21 05:01:26 -07:00
fix(hachidori): drop busy-commit retry now that the engine queues imports
Upstream dfc5e0c (#578) queues dictionary imports behind a running change and removed ENGINE_BUSY_CODE, so a commit no longer replies engine-mutating.
This commit is contained in:
2 files changed
+3
-23
No files matched your search
@@ -38,7 +38,6 @@ function lookupResult(matched: string, expression: string, reading: string, dict
|
||||
type UploadReply = Record<string, unknown>;
|
||||
// The parts of vendor/hachidori/extension/linked-import.js the harness drives.
|
||||
type LinkedImportModule = {
|
||||
ENGINE_BUSY_CODE: string;
|
||||
createUploadHost(options: {
|
||||
store: {
|
||||
append(token: string, data: string): void;
|
||||
@@ -85,7 +84,6 @@ async function createHarness(emptyLibrary = false) {
|
||||
let proxyUrl: unknown;
|
||||
let loadingStatusReplies = 0;
|
||||
let busyEngineReplies = 0;
|
||||
let busyCommits = 0;
|
||||
const uploads: Array<{ fileName: string; replace: boolean; bytes: Buffer }> = [];
|
||||
const apiModule: unknown = await import(
|
||||
pathToFileURL(path.join(extensionPath, 'api-host.js')).href
|
||||
@@ -108,10 +106,6 @@ async function createHarness(emptyLibrary = false) {
|
||||
token: string,
|
||||
{ fileName, replace }: { fileName: string; replace: boolean },
|
||||
) => {
|
||||
if (busyCommits > 0) {
|
||||
busyCommits -= 1;
|
||||
return { ok: false, error: 'busy', errorCode: linkedImportModule.ENGINE_BUSY_CODE };
|
||||
}
|
||||
uploads.push({ fileName, replace, bytes: Buffer.concat(uploadParts.get(token) ?? []) });
|
||||
return { ok: true, report: { success: true } };
|
||||
},
|
||||
@@ -280,9 +274,6 @@ async function createHarness(emptyLibrary = false) {
|
||||
setBusyEngineReplies: (count: number) => {
|
||||
busyEngineReplies = count;
|
||||
},
|
||||
setBusyCommits: (count: number) => {
|
||||
busyCommits = count;
|
||||
},
|
||||
uploads: () => uploads,
|
||||
};
|
||||
}
|
||||
@@ -541,8 +532,6 @@ test('Hachidori mining requests render native dictionary aliases and frequency m
|
||||
|
||||
test('Hachidori settings automation uploads ZIP bytes as a replacement and removes the matching dictionary ID', async () => {
|
||||
const harness = await createHarness();
|
||||
// The engine is mid-change for the first commit; the same upload must still land once.
|
||||
harness.setBusyCommits(1);
|
||||
await harness.run(
|
||||
"__subminerYomitanSettingsAutomation.importDictionaryArchiveBase64('UEstdGVzdA==', 'characters.zip')",
|
||||
);
|
||||
|
||||
@@ -209,20 +209,11 @@ export const HACHIDORI_PARSER_BRIDGE_SCRIPT = String.raw`
|
||||
void invoke(action, params).then(result => callback({ result }), error => callback({ error: { message: error.message } }));
|
||||
};
|
||||
// Archives go through Hachidori's upload requests: an unlinked install imports
|
||||
// the ZIP itself and a linked one forwards it to its host. A busy engine keeps
|
||||
// the upload open, so the same commit is sent again.
|
||||
const sendUpload = async (type, fields) => {
|
||||
const deadline = Date.now() + 300000;
|
||||
for (;;) {
|
||||
const reply = await chrome.runtime.sendMessage({
|
||||
// the ZIP itself and a linked one forwards it to its host. The engine queues
|
||||
// an import behind any dictionary change already running.
|
||||
const sendUpload = (type, fields) => chrome.runtime.sendMessage({
|
||||
target: 'hachidori-linked-import', type, requestId: crypto.randomUUID(), ...fields,
|
||||
});
|
||||
if (type !== 'hd_import_commit' || reply?.errorCode !== 'engine-mutating' || Date.now() >= deadline) {
|
||||
return reply;
|
||||
}
|
||||
await sleep(500);
|
||||
}
|
||||
};
|
||||
async function importArchive(blob, fileName) {
|
||||
await waitForEngineReady();
|
||||
const reply = await uploadDictionary({ blob, fileName, replace: true, send: sendUpload });
|
||||
|
||||
Reference in new issue
Block a user