mirror of
https://github.com/lxsang/antos-frontend.git
synced 2025-04-08 17:46:43 +02:00
Improve core API:
- improve OS exit API - improve VFS API
This commit is contained in:
parent
e6e727246d
commit
c23cb1bfa8
2
Makefile
2
Makefile
@ -5,7 +5,7 @@ DOCDIR?=/opt/www/htdocs/doc/antos
|
|||||||
BLUE=\033[1;34m
|
BLUE=\033[1;34m
|
||||||
NC=\033[0m
|
NC=\033[0m
|
||||||
|
|
||||||
VERSION=1.2.0
|
VERSION=1.2.1
|
||||||
|
|
||||||
GSED=sed
|
GSED=sed
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
|
4
d.ts/antos.d.ts
vendored
4
d.ts/antos.d.ts
vendored
@ -2445,7 +2445,7 @@ declare namespace OS {
|
|||||||
* to perform a particular task before shuting down the system
|
* to perform a particular task before shuting down the system
|
||||||
*/
|
*/
|
||||||
const cleanupHandles: {
|
const cleanupHandles: {
|
||||||
[index: string]: () => void;
|
[index: string]: () => Promise<any>;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Perform the system shutdown operation. This function calls all
|
* Perform the system shutdown operation. This function calls all
|
||||||
@ -2463,7 +2463,7 @@ declare namespace OS {
|
|||||||
* @param {() => void} f the callback handle
|
* @param {() => void} f the callback handle
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function onexit(n: string, f: () => void): () => void;
|
function onexit(n: string, f: () => Promise<any>): () => Promise<any>;
|
||||||
/**
|
/**
|
||||||
* The namespace API is dedicated to the definition of the core system APIs
|
* 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:
|
* used by AntOS and its applications. The following core APIs are defined:
|
||||||
|
BIN
release/antos-1.2.1.tar.gz
Normal file
BIN
release/antos-1.2.1.tar.gz
Normal file
Binary file not shown.
@ -1 +1 @@
|
|||||||
1.2.0
|
1.2.1
|
@ -843,7 +843,7 @@ namespace OS {
|
|||||||
* exits. These callbacks are useful when an application or service wants
|
* exits. These callbacks are useful when an application or service wants
|
||||||
* to perform a particular task before shuting down the system
|
* to perform a particular task before shuting down the system
|
||||||
*/
|
*/
|
||||||
export const cleanupHandles: { [index: string]: () => void } = {};
|
export const cleanupHandles: { [index: string]: () => Promise<any> } = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the system shutdown operation. This function calls all
|
* Perform the system shutdown operation. This function calls all
|
||||||
@ -854,15 +854,16 @@ namespace OS {
|
|||||||
*/
|
*/
|
||||||
export function exit(): void {
|
export function exit(): void {
|
||||||
//do clean up first
|
//do clean up first
|
||||||
|
const promises: Promise<any>[] = [];
|
||||||
for (let n in cleanupHandles) {
|
for (let n in cleanupHandles) {
|
||||||
const f = cleanupHandles[n];
|
promises.push(cleanupHandles[n]());
|
||||||
f();
|
|
||||||
}
|
}
|
||||||
API.handle
|
promises.push(API.handle.setting());
|
||||||
.setting()
|
Promise.all(promises)
|
||||||
.then(function (r: any) {
|
.then(async function (r: any) {
|
||||||
cleanup();
|
cleanup();
|
||||||
return API.handle.logout().then((d: any) => boot());
|
const d = await API.handle.logout();
|
||||||
|
return boot();
|
||||||
})
|
})
|
||||||
.catch((e: Error) => console.error(e));
|
.catch((e: Error) => console.error(e));
|
||||||
}
|
}
|
||||||
@ -875,7 +876,7 @@ namespace OS {
|
|||||||
* @param {() => void} f the callback handle
|
* @param {() => void} f the callback handle
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function onexit(n: string, f: () => void) {
|
export function onexit(n: string, f: () => Promise<any>) {
|
||||||
if (!cleanupHandles[n]) {
|
if (!cleanupHandles[n]) {
|
||||||
return (cleanupHandles[n] = f);
|
return (cleanupHandles[n] = f);
|
||||||
}
|
}
|
||||||
|
145
src/core/vfs.ts
145
src/core/vfs.ts
@ -355,7 +355,7 @@ namespace OS {
|
|||||||
if (re === "") {
|
if (re === "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.genealogy = re.split("/").filter(s=> s!="");
|
this.genealogy = re.split("/").filter(s => s != "");
|
||||||
this.path = `${this.protocol}://${this.genealogy.join("/")}`;
|
this.path = `${this.protocol}://${this.genealogy.join("/")}`;
|
||||||
if (!this.isRoot()) {
|
if (!this.isRoot()) {
|
||||||
this.basename = this.genealogy[
|
this.basename = this.genealogy[
|
||||||
@ -548,12 +548,8 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const d = await this._rd(t);
|
||||||
const d = await this._rd(t);
|
resolve(d);
|
||||||
return resolve(d);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -601,16 +597,12 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const d_1 = await this._mk(d);
|
||||||
const d_1 = await this._mk(d);
|
announcer.ostrigger("VFS", {
|
||||||
announcer.ostrigger("VFS", {
|
m: "mk",
|
||||||
m: "mk",
|
file: this,
|
||||||
file: this,
|
});
|
||||||
});
|
return resolve(d_1);
|
||||||
return resolve(d_1);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -629,16 +621,12 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const d = await this._rm();
|
||||||
const d = await this._rm();
|
announcer.ostrigger("VFS", {
|
||||||
announcer.ostrigger("VFS", {
|
m: "remove",
|
||||||
m: "remove",
|
file: this,
|
||||||
file: this,
|
});
|
||||||
});
|
return resolve(d);
|
||||||
return resolve(d);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -659,16 +647,12 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const d = await this._up();
|
||||||
const d = await this._up();
|
announcer.ostrigger("VFS", {
|
||||||
announcer.ostrigger("VFS", {
|
m: "upload",
|
||||||
m: "upload",
|
file: this,
|
||||||
file: this,
|
});
|
||||||
});
|
return resolve(d);
|
||||||
return resolve(d);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -689,16 +673,12 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const d = await this._pub();
|
||||||
const d = await this._pub();
|
announcer.ostrigger("VFS", {
|
||||||
announcer.ostrigger("VFS", {
|
m: "publish",
|
||||||
m: "publish",
|
file: this,
|
||||||
file: this,
|
});
|
||||||
});
|
return resolve(d);
|
||||||
return resolve(d);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -719,16 +699,12 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const d = await this._down();
|
||||||
const d = await this._down();
|
announcer.ostrigger("VFS", {
|
||||||
announcer.ostrigger("VFS", {
|
m: "download",
|
||||||
m: "download",
|
file: this,
|
||||||
file: this,
|
});
|
||||||
});
|
return resolve(d);
|
||||||
return resolve(d);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -748,16 +724,13 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const data = await this._mv(d);
|
||||||
const data = await this._mv(d);
|
announcer.ostrigger("VFS", {
|
||||||
announcer.ostrigger("VFS", {
|
m: "move",
|
||||||
m: "move",
|
file: d.asFileHandle(),
|
||||||
file: d.asFileHandle(),
|
});
|
||||||
});
|
return resolve(data);
|
||||||
return resolve(data);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -778,16 +751,12 @@ namespace OS {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const r = await this.onready();
|
const r = await this.onready();
|
||||||
try {
|
const d = await this._exec();
|
||||||
const d = await this._exec();
|
announcer.ostrigger("VFS", {
|
||||||
announcer.ostrigger("VFS", {
|
m: "execute",
|
||||||
m: "execute",
|
file: this,
|
||||||
file: this,
|
});
|
||||||
});
|
return resolve(d);
|
||||||
return resolve(d);
|
|
||||||
} catch (e) {
|
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} catch (e_1) {
|
} catch (e_1) {
|
||||||
return reject(__e(e_1));
|
return reject(__e(e_1));
|
||||||
}
|
}
|
||||||
@ -1066,8 +1035,8 @@ namespace OS {
|
|||||||
protected _wr(t: string): Promise<RequestResult> {
|
protected _wr(t: string): Promise<RequestResult> {
|
||||||
// t is base64 or undefined
|
// t is base64 or undefined
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (t === "base64") {
|
try {
|
||||||
try {
|
if (t === "base64") {
|
||||||
const d = await API.handle.write(
|
const d = await API.handle.write(
|
||||||
this.path,
|
this.path,
|
||||||
this.cache
|
this.cache
|
||||||
@ -1080,11 +1049,7 @@ namespace OS {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return resolve(d);
|
return resolve(d);
|
||||||
} catch (e) {
|
} else {
|
||||||
return reject(__e(e));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
const r = await this.b64(t);
|
const r = await this.b64(t);
|
||||||
const result = await API.handle.write(
|
const result = await API.handle.write(
|
||||||
this.path,
|
this.path,
|
||||||
@ -1102,9 +1067,9 @@ namespace OS {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return resolve(result);
|
return resolve(result);
|
||||||
} catch (e_2) {
|
|
||||||
return reject(__e(e_2));
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return reject(__e(e));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1945,14 +1910,12 @@ namespace OS {
|
|||||||
try {
|
try {
|
||||||
await API.requires("os://scripts/jszip.min.js");
|
await API.requires("os://scripts/jszip.min.js");
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
const fhd = src.asFileHandle();
|
const fhd = src.asFileHandle();
|
||||||
const meta = await fhd.onready();
|
const meta = await fhd.onready();
|
||||||
if(meta.type === "file")
|
if (meta.type === "file") {
|
||||||
{
|
|
||||||
await aradd([src], zip, "/");
|
await aradd([src], zip, "/");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
const ret = await fhd.read();
|
const ret = await fhd.read();
|
||||||
await aradd(
|
await aradd(
|
||||||
ret.result.map((v: API.FileInfoType) => v.path), zip, "/");
|
ret.result.map((v: API.FileInfoType) => v.path), zip, "/");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user