From 5dbf9ef2fbaa7c5f4a677ff1e33a35304e1e0c9b Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Fri, 19 Jan 2024 23:57:05 +0800 Subject: [PATCH] =?UTF-8?q?initReadWriteFunction=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=8F=AF=E4=BB=A5=E8=BF=9B=E8=A1=8C=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=AF=BB=E5=86=99=E7=9A=84=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 208 ++++++++++++---------- node_modules/noname-typings/windowEx.d.ts | 4 +- noname/init/index.js | 6 +- 3 files changed, 116 insertions(+), 102 deletions(-) diff --git a/index.html b/index.html index abe49f125..6ec89d172 100755 --- a/index.html +++ b/index.html @@ -18,118 +18,130 @@ diff --git a/node_modules/noname-typings/windowEx.d.ts b/node_modules/noname-typings/windowEx.d.ts index 3d82e2a0f..aebf594b6 100644 --- a/node_modules/noname-typings/windowEx.d.ts +++ b/node_modules/noname-typings/windowEx.d.ts @@ -68,8 +68,8 @@ declare interface Window { get: Get; ai: AI; } - - initReadWriteFunction?(game: Game): void; + /** 为其他自定义平台提供文件读写函数赋值的一种方式 */ + initReadWriteFunction?(game: Game): Promise; bannedKeyWords: string[]; } diff --git a/noname/init/index.js b/noname/init/index.js index 02835a5f8..13f148ef7 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -106,7 +106,7 @@ export async function boot() { else if (!Reflect.has(lib, 'device')) { Reflect.set(lib, 'path', (await import('../library/path.js')).default); //为其他自定义平台提供文件读写函数赋值的一种方式。 - //但这种方式只能修改game的文件读写函数。 + //但这种方式只允许修改game的文件读写函数。 if (typeof window.initReadWriteFunction == 'function') { const g = {}; const ReadWriteFunctionName = ['download', 'readFile', 'readFileAsText', 'writeFile', 'removeFile', 'getFileList', 'ensureDirectory', 'createDir']; @@ -123,7 +123,9 @@ export async function boot() { }); }); // @ts-ignore - window.initReadWriteFunction(g); + await window.initReadWriteFunction(g).catch(e => { + console.error('文件读写函数初始化失败:', e); + }); } window.onbeforeunload = function () { if (config.get('confirm_exit') && !_status.reloading) {