diff --git a/Makefile b/Makefile index 15b3130..fa57d36 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ DOCDIR?=/opt/www/htdocs/doc/antos BLUE=\033[1;34m NC=\033[0m -VERSION=1.2.0 +VERSION=1.2.1 GSED=sed UNAME_S := $(shell uname -s) diff --git a/d.ts/antos.d.ts b/d.ts/antos.d.ts index cc9fa93..2da83df 100644 --- a/d.ts/antos.d.ts +++ b/d.ts/antos.d.ts @@ -2445,7 +2445,7 @@ declare namespace OS { * to perform a particular task before shuting down the system */ const cleanupHandles: { - [index: string]: () => void; + [index: string]: () => Promise; }; /** * Perform the system shutdown operation. This function calls all @@ -2463,7 +2463,7 @@ declare namespace OS { * @param {() => void} f the callback handle * @returns */ - function onexit(n: string, f: () => void): () => void; + function onexit(n: string, f: () => Promise): () => Promise; /** * The namespace API is dedicated to the definition of the core system APIs * used by AntOS and its applications. The following core APIs are defined: diff --git a/release/antos-1.2.1.tar.gz b/release/antos-1.2.1.tar.gz new file mode 100644 index 0000000..2c8db67 Binary files /dev/null and b/release/antos-1.2.1.tar.gz differ diff --git a/release/latest b/release/latest index 867e524..cb174d5 100644 --- a/release/latest +++ b/release/latest @@ -1 +1 @@ -1.2.0 \ No newline at end of file +1.2.1 \ No newline at end of file diff --git a/src/core/core.ts b/src/core/core.ts index bc2de37..0d9dbbe 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -843,7 +843,7 @@ namespace OS { * exits. These callbacks are useful when an application or service wants * to perform a particular task before shuting down the system */ - export const cleanupHandles: { [index: string]: () => void } = {}; + export const cleanupHandles: { [index: string]: () => Promise } = {}; /** * Perform the system shutdown operation. This function calls all @@ -854,15 +854,16 @@ namespace OS { */ export function exit(): void { //do clean up first + const promises: Promise[] = []; for (let n in cleanupHandles) { - const f = cleanupHandles[n]; - f(); + promises.push(cleanupHandles[n]()); } - API.handle - .setting() - .then(function (r: any) { + promises.push(API.handle.setting()); + Promise.all(promises) + .then(async function (r: any) { cleanup(); - return API.handle.logout().then((d: any) => boot()); + const d = await API.handle.logout(); + return boot(); }) .catch((e: Error) => console.error(e)); } @@ -875,7 +876,7 @@ namespace OS { * @param {() => void} f the callback handle * @returns */ - export function onexit(n: string, f: () => void) { + export function onexit(n: string, f: () => Promise) { if (!cleanupHandles[n]) { return (cleanupHandles[n] = f); } diff --git a/src/core/vfs.ts b/src/core/vfs.ts index 7085b05..63d7014 100644 --- a/src/core/vfs.ts +++ b/src/core/vfs.ts @@ -355,7 +355,7 @@ namespace OS { if (re === "") { return; } - this.genealogy = re.split("/").filter(s=> s!=""); + this.genealogy = re.split("/").filter(s => s != ""); this.path = `${this.protocol}://${this.genealogy.join("/")}`; if (!this.isRoot()) { this.basename = this.genealogy[ @@ -548,12 +548,8 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const d = await this._rd(t); - return resolve(d); - } catch (e) { - return reject(__e(e)); - } + const d = await this._rd(t); + resolve(d); } catch (e_1) { return reject(__e(e_1)); } @@ -601,16 +597,12 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const d_1 = await this._mk(d); - announcer.ostrigger("VFS", { - m: "mk", - file: this, - }); - return resolve(d_1); - } catch (e) { - return reject(__e(e)); - } + const d_1 = await this._mk(d); + announcer.ostrigger("VFS", { + m: "mk", + file: this, + }); + return resolve(d_1); } catch (e_1) { return reject(__e(e_1)); } @@ -629,16 +621,12 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const d = await this._rm(); - announcer.ostrigger("VFS", { - m: "remove", - file: this, - }); - return resolve(d); - } catch (e) { - return reject(__e(e)); - } + const d = await this._rm(); + announcer.ostrigger("VFS", { + m: "remove", + file: this, + }); + return resolve(d); } catch (e_1) { return reject(__e(e_1)); } @@ -659,16 +647,12 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const d = await this._up(); - announcer.ostrigger("VFS", { - m: "upload", - file: this, - }); - return resolve(d); - } catch (e) { - return reject(__e(e)); - } + const d = await this._up(); + announcer.ostrigger("VFS", { + m: "upload", + file: this, + }); + return resolve(d); } catch (e_1) { return reject(__e(e_1)); } @@ -689,16 +673,12 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const d = await this._pub(); - announcer.ostrigger("VFS", { - m: "publish", - file: this, - }); - return resolve(d); - } catch (e) { - return reject(__e(e)); - } + const d = await this._pub(); + announcer.ostrigger("VFS", { + m: "publish", + file: this, + }); + return resolve(d); } catch (e_1) { return reject(__e(e_1)); } @@ -719,16 +699,12 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const d = await this._down(); - announcer.ostrigger("VFS", { - m: "download", - file: this, - }); - return resolve(d); - } catch (e) { - return reject(__e(e)); - } + const d = await this._down(); + announcer.ostrigger("VFS", { + m: "download", + file: this, + }); + return resolve(d); } catch (e_1) { return reject(__e(e_1)); } @@ -748,16 +724,13 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const data = await this._mv(d); - announcer.ostrigger("VFS", { - m: "move", - file: d.asFileHandle(), - }); - return resolve(data); - } catch (e) { - return reject(__e(e)); - } + const data = await this._mv(d); + announcer.ostrigger("VFS", { + m: "move", + file: d.asFileHandle(), + }); + return resolve(data); + } catch (e_1) { return reject(__e(e_1)); } @@ -778,16 +751,12 @@ namespace OS { return new Promise(async (resolve, reject) => { try { const r = await this.onready(); - try { - const d = await this._exec(); - announcer.ostrigger("VFS", { - m: "execute", - file: this, - }); - return resolve(d); - } catch (e) { - return reject(__e(e)); - } + const d = await this._exec(); + announcer.ostrigger("VFS", { + m: "execute", + file: this, + }); + return resolve(d); } catch (e_1) { return reject(__e(e_1)); } @@ -1066,8 +1035,8 @@ namespace OS { protected _wr(t: string): Promise { // t is base64 or undefined return new Promise(async (resolve, reject) => { - if (t === "base64") { - try { + try { + if (t === "base64") { const d = await API.handle.write( this.path, this.cache @@ -1080,11 +1049,7 @@ namespace OS { ); } return resolve(d); - } catch (e) { - return reject(__e(e)); - } - } else { - try { + } else { const r = await this.b64(t); const result = await API.handle.write( this.path, @@ -1102,9 +1067,9 @@ namespace OS { ); } return resolve(result); - } catch (e_2) { - return reject(__e(e_2)); } + } catch (e) { + return reject(__e(e)); } }); } @@ -1945,14 +1910,12 @@ namespace OS { try { await API.requires("os://scripts/jszip.min.js"); const zip = new JSZip(); - const fhd = src.asFileHandle(); + const fhd = src.asFileHandle(); const meta = await fhd.onready(); - if(meta.type === "file") - { + if (meta.type === "file") { await aradd([src], zip, "/"); } - else - { + else { const ret = await fhd.read(); await aradd( ret.result.map((v: API.FileInfoType) => v.path), zip, "/");