From 7c0a6d7bef2edb4824ae94761eecaaf9360e375f Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Sat, 6 Apr 2024 21:50:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0get.promises.zip=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B1=BB=E5=9E=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/game/index.js | 33 +++++++------ noname/get/index.js | 9 +++- noname/get/promises.js | 11 +++++ noname/library/index.js | 62 ++++++++++++------------ noname/library/update.js | 4 +- noname/status/index.js | 4 ++ noname/ui/click/index.js | 8 +++ noname/ui/create/index.js | 4 ++ noname/ui/create/menu/pages/otherMenu.js | 57 ++++++++++++++-------- noname/ui/index.js | 12 +++++ 10 files changed, 136 insertions(+), 68 deletions(-) create mode 100644 noname/get/promises.js diff --git a/noname/game/index.js b/noname/game/index.js index 7a38fc12a..e971b0536 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -1910,55 +1910,60 @@ export class Game extends Uninstantable { } /** * 下载文件 - * @type { (url: string, folder: string, onsuccess?: Function, onerror?: (e: Error) => void) => void, dev?: 'nodev', onprogress?: Function) => void } + * @type { undefined | ((url: string, folder: string, onsuccess?: Function, onerror?: (e: Error) => void) => void, dev?: 'nodev', onprogress?: Function) => void) } */ static download; /** * 读取文件为arraybuffer - * @type { (filename: string, callback?: (data: Buffer | ArrayBuffer) => any, onerror?: (e: Error) => void) => void } + * @type { undefined | ((filename: string, callback?: (data: Buffer | ArrayBuffer) => any, onerror?: (e: Error) => void) => void) } */ static readFile; /** * 读取文件为文本 - * @type { (filename: string, callback?: (data: string) => any, onerror?: (e: Error) => void) => void } + * @type { undefined | ((filename: string, callback?: (data: string) => any, onerror?: (e: Error) => void) => void) } */ static readFileAsText; /** * 将数据写入文件 - * @type { (data: File | ArrayBuffer, path: string, name: string, callback?: (e: Error) => void) => void } + * @type { undefined | ((data: File | ArrayBuffer, path: string, name: string, callback?: (e: Error) => void) => void) } */ static writeFile; /** * 移除文件 - * @type { (filename: string, callback?: (e: Error) => void) => void } + * @type { undefined | ((filename: string, callback?: (e: Error) => void) => void) } */ static removeFile; /** * 获取文件列表 - * @type { (dir: string, success: (folders: string[], files: string[]) => any, failure: (e: Error) => void) => void } + * @type { undefined | ((dir: string, success: (folders: string[], files: string[]) => any, failure: (e: Error) => void) => void) } */ static getFileList; /** * 按路径依次创建文件夹 - * @type { (list: string | string[], callback: Function, file?: boolean) => void } + * @type { undefined | ((list: string | string[], callback: Function, file?: boolean) => void) } */ static ensureDirectory; /** * 创建文件夹 - * @type { (directory: string, successCallback?: Function, errorCallback?: Function) => void } + * @type { undefined | ((directory: string, successCallback?: Function, errorCallback?: Function) => void) } */ static createDir; /** * 删除文件夹 - * @type { (directory: string, successCallback?: Function, errorCallback?: Function) => void } + * @type { undefined | ((directory: string, successCallback?: Function, errorCallback?: Function) => void) } */ static removeDir; + /** + * @type { (forcecheck?: boolean | null, dev?: boolean) => Promise } + */ + static checkForUpdate; + /** + * @type { () => Promise } + */ + static checkForAssetUpdate; static async importExtension(data, finishLoad, exportExtension, extensionPackage) { - //by 来瓶可乐加冰、Rintim、Tipx-L - if (!window.JSZip) - await new Promise((resolve, reject) => lib.init.js(`${lib.assetURL}game`, "jszip", resolve, reject)); - - const zip = new JSZip(); + //by 来瓶可乐加冰、Rintim、Tipx-L、诗笺 + const zip = await get.promises.zip(); if (get.objtype(data) == 'object') { //导出 const _filelist = data._filelist, filelist2 = _filelist || []; diff --git a/noname/get/index.js b/noname/get/index.js index 31b44caba..02c4903a4 100644 --- a/noname/get/index.js +++ b/noname/get/index.js @@ -6,11 +6,12 @@ import { status as _status } from '../status/index.js'; import { UI as ui } from '../ui/index.js'; import { GNC as gnc } from '../gnc/index.js'; import { CacheContext } from "../library/cache/cacheContext.js"; - import { Is } from "./is.js"; +import { Promises } from "./promises.js"; export class Get extends Uninstantable { static is = Is; + static promises = Promises; /** * 获取当前内核版本信息 * @@ -627,6 +628,9 @@ export class Get extends Uninstantable { } static sort(arr, method, arg) { return method == "seat" ? arr.sortBySeat(arg) : void 0; } static sortSeat(arr, target) { return arr.sortBySeat(target); } + /** + * @param { (zip: JSZip) => any } callback + */ static zip(callback) { if (!window.JSZip) { lib.init.js(lib.assetURL + 'game', 'jszip', function () { @@ -4748,5 +4752,6 @@ export class Get extends Uninstantable { export const get = Get; export { - Is + Is, + Promises }; diff --git a/noname/get/promises.js b/noname/get/promises.js new file mode 100644 index 000000000..5c417f95b --- /dev/null +++ b/noname/get/promises.js @@ -0,0 +1,11 @@ +import { get } from "./index.js"; +import { Uninstantable } from "../util/index.js"; + +export class Promises extends Uninstantable { + /** + * @returns { Promise } + */ + static zip() { + return new Promise(resolve => get.zip(resolve)); + } +} \ No newline at end of file diff --git a/noname/library/index.js b/noname/library/index.js index d788b961a..f5aac07b3 100644 --- a/noname/library/index.js +++ b/noname/library/index.js @@ -123,36 +123,38 @@ export class Library extends Uninstantable { */ static tempSortSeat; /** - * @returns { never } - */ - static typeAnnotation() { - /** - * @type { Videos[] } - */ - // @ts-ignore - this.videos; - /** - * @type { { - * fs: typeof import("fs"), - * path: typeof import("path"), - * debug: () => void, - * clients: Element.Client[], - * banned:[], - * observing:[], - * torespond:{}, - * torespondtimeout:{}, - * } } - */ - // @ts-ignore - this.node; - /** - * @type { { [key: string]: string } } - */ - // @ts-ignore - this.playerOL; - throw new Error('Do not call this method'); - } - + * @type { 'android' | 'ios' | undefined } + */ + static device; + /** + * @type { string } + */ + static version; + /** + * @type { Videos[] } + */ + static videos; + /** + * @type { { + * fs: typeof import("fs"), + * path: typeof import("path"), + * debug: () => void, + * clients: Element.Client[], + * banned:[], + * observing:[], + * torespond:{}, + * torespondtimeout:{}, + * } } + */ + static node; + /** + * @type { { [key: string]: string } } + */ + static playerOL; + /** + * @type { IDBRequest } + */ + static db; //函数钩子 /** * 你可以往这里加入{钩子名:函数数组},并在数组里增加你的自定义函数 diff --git a/noname/library/update.js b/noname/library/update.js index 5e1de91ff..9845366ce 100644 --- a/noname/library/update.js +++ b/noname/library/update.js @@ -292,7 +292,7 @@ export async function getRepoFilesList(path = '', branch, options = { username: /** * - * 获取仓库指定分支和指定目录内的所有文件和目录 + * 获取仓库指定分支和指定目录内的所有文件(包含子目录的文件) * @param { string } [path = ''] 路径名称(可放参数) * @param { string } [branch = ''] 仓库分支名称 * @param { Object } options @@ -335,7 +335,7 @@ export async function flattenRepositoryFiles(path = '', branch, options = { user // 返回不含文件夹的扁平化文件列表 return allFiles; -} +}; /** * 请求一个文件而不是直接储存为文件 diff --git a/noname/status/index.js b/noname/status/index.js index 92bdcdd2c..eba68cd36 100644 --- a/noname/status/index.js +++ b/noname/status/index.js @@ -49,6 +49,10 @@ export const status = { * @type { boolean | void } */ touchconfirmed: undefined, + /** + * @type { boolean | void } + */ + connectMode: undefined, }; export const _status = status; \ No newline at end of file diff --git a/noname/ui/click/index.js b/noname/ui/click/index.js index f215f3dd7..6f69b66f6 100644 --- a/noname/ui/click/index.js +++ b/noname/ui/click/index.js @@ -2,6 +2,14 @@ import { ui, game, get, lib, _status } from "../../../noname.js"; import { Uninstantable } from "../../util/index.js"; export class Click extends Uninstantable { + /** + * @type {() => void} + */ + static consoleMenu; + /** + * @type {(arg0: string) => void} + */ + static menuTab; static identitycircle() { var list = []; this.classList.toggle('transparent'); diff --git a/noname/ui/create/index.js b/noname/ui/create/index.js index 24adc3e05..61d228821 100644 --- a/noname/ui/create/index.js +++ b/noname/ui/create/index.js @@ -9,6 +9,10 @@ import { otherMenu } from "./menu/pages/otherMenu.js"; import { startMenu } from "./menu/pages/startMenu.js"; export class Create extends Uninstantable { + /** + * @type {(video: Videos, before: boolean) => void} + */ + static videoNode; /** * 创建身份牌实例 */ diff --git a/noname/ui/create/menu/pages/otherMenu.js b/noname/ui/create/menu/pages/otherMenu.js index f71e44d90..0126e4798 100644 --- a/noname/ui/create/menu/pages/otherMenu.js +++ b/noname/ui/create/menu/pages/otherMenu.js @@ -29,7 +29,7 @@ import { gainAuthorization } from "../../../../library/update.js" -export const otherMenu = function (connectMenu) { +export const otherMenu = function (/** @type { boolean | undefined } */ connectMenu) { if (connectMenu) return; /** * 由于联机模式会创建第二个菜单,所以需要缓存一下可变的变量 @@ -147,7 +147,18 @@ export const otherMenu = function (connectMenu) { li3.style.whiteSpace = 'nowrap'; li3.style.display = 'none';// coding - var checkVersionButton, checkAssetButton, checkDevVersionButton/*, button4, button5*/; + /** + * @type {HTMLButtonElement} + */ + var checkVersionButton; + /** + * @type {HTMLButtonElement} + */ + var checkAssetButton; + /** + * @type {HTMLButtonElement} + */ + var checkDevVersionButton; game.checkForUpdate = async function (forcecheck, dev) { if (!dev && checkVersionButton.disabled) { @@ -236,8 +247,14 @@ export const otherMenu = function (connectMenu) { refresh(); } } + /** + * @param {{ assets: any; author?: { login: string; avatar_url: string; html_url: string; }; body?: string; html_url?: string; name: any; published_at?: string; zipball_url: any; }} description + */ function download(description) { const progress = createProgress('正在更新' + description.name, 1, description.name + '.zip'); + /** + * @type {progress} + */ let unZipProgress; let url = description.zipball_url; if (Array.isArray(description.assets) && description.assets.length > 0) { @@ -262,8 +279,8 @@ export const otherMenu = function (connectMenu) { progress.setProgressValue(received); }).then(async blob => { progress.remove(); - await import('../../../../../game/jszip.js'); - const zip = new window.JSZip().load(await blob.arrayBuffer()); + const zip = await get.promises.zip(); + zip.load(await blob.arrayBuffer()); const entries = Object.entries(zip.files); let root; const hiddenFileFlags = ['.', '_']; @@ -317,11 +334,13 @@ export const otherMenu = function (connectMenu) { }); } unZipProgress.remove(); - // await import('../../../../../game/update.js'); - // if (Array.isArray(window.noname_asset_list)) { - // game.saveConfig('asset_version', window.noname_asset_list[0]); - // delete window.noname_asset_list; - // } + if (url === description.zipball_url) { + await lib.init.promises.js('game', 'update.js'); + if (Array.isArray(window.noname_asset_list)) { + game.saveConfig('asset_version', window.noname_asset_list[0]); + delete window.noname_asset_list; + } + } if (confirm('更新完成,是否重启?')) { game.reload(); } @@ -397,18 +416,14 @@ export const otherMenu = function (connectMenu) { }) }).then(async blob => { progress.remove(); - await import('../../../../../game/jszip.js'); - const zip = new window.JSZip().load(await blob.arrayBuffer()); + const zip = await get.promises.zip(); + zip.load(await blob.arrayBuffer()); const entries = Object.entries(zip.files); let root; const hiddenFileFlags = ['.', '_']; unZipProgress = createProgress('正在解压' + progress.getFileName(), entries.length); let i = 0; for (const [key, value] of entries) { - // 第一个是文件夹的话,就是根文件夹 - // if (i == 0 && value.dir && !description.name.includes('noname.core.zip')) { - // root = key; - // } unZipProgress.setProgressValue(i++); const fileName = typeof root == 'string' && key.startsWith(root) ? key.replace(root, '') : key; if (hiddenFileFlags.includes(fileName[0])) continue; @@ -422,11 +437,11 @@ export const otherMenu = function (connectMenu) { await game.promises.writeFile(value.asArrayBuffer(), path, name); } unZipProgress.remove(); - // await import('../../../../../game/update.js'); - // if (Array.isArray(window.noname_asset_list)) { - // game.saveConfig('asset_version', window.noname_asset_list[0]); - // delete window.noname_asset_list; - // } + await lib.init.promises.js('game', 'update.js'); + if (Array.isArray(window.noname_asset_list)) { + game.saveConfig('asset_version', window.noname_asset_list[0]); + delete window.noname_asset_list; + } if (confirm('更新完成,是否重启?')) { game.reload(); } @@ -459,6 +474,8 @@ export const otherMenu = function (connectMenu) { // } (function () { + /** @type { HTMLParagraphElement } */ + // @ts-ignore var updatep1 = li1.querySelector('p'); var updatep2 = li2; var updatep3 = li3; diff --git a/noname/ui/index.js b/noname/ui/index.js index e1306abcc..ebbcc0bd8 100644 --- a/noname/ui/index.js +++ b/noname/ui/index.js @@ -111,6 +111,18 @@ export class UI extends Uninstantable { * @type { HTMLDivElement } 挑战模式下正在操作的角色 */ static mebg; + /** + * @type { Function | undefined } + */ + static updateUpdate; + /** + * @type {HTMLDivElement} + */ + static commandnode; + /** + * @type {() => void} + */ + static updateVideoMenu; static refresh(node) { void window.getComputedStyle(node, null).getPropertyValue("opacity"); }