API improvement & bug fix:

- subscribed global event doesnt unsubcribed when process is killed
- process killall API doesnt work as expected
- improve core API
This commit is contained in:
Dany LE 2021-11-25 01:13:16 +01:00
parent 64094c29d5
commit 0624f421f7
6 changed files with 90 additions and 119 deletions

6
d.ts/antos.d.ts vendored
View File

@ -3225,12 +3225,11 @@ declare namespace OS {
* Update the application local from the system
* locale or application specific locale configuration
*
* @private
* @param {string} name locale name e.g. `en_GB`
* @returns {void}
* @memberof BaseApplication
*/
protected updateLocale(name: string): void;
updateLocale(name: string): void;
/**
* Execute the callback subscribed to a
* keyboard shortcut
@ -4559,11 +4558,10 @@ declare namespace OS {
/**
* Update the model locale
*
* @protected
* @param {string} name
* @memberof BaseModel
*/
protected updateLocale(name: string): void;
updateLocale(name: string): void;
/**
* Render the model's UI
*

Binary file not shown.

View File

@ -83,11 +83,6 @@ namespace OS {
}
this.setting = setting.applications[this.name];
this.keycomb = {};
this.subscribe("appregistry", (m) => {
if (m.name === this.name) {
this.applySetting(m.message as string);
}
});
}
/**
@ -135,6 +130,11 @@ namespace OS {
}
});
this.on("apptitlechange", () => this.sysdock.update(this));
this.subscribe("appregistry", (m) => {
if (m.name === this.name) {
this.applySetting(m.message as string);
}
});
this.updateLocale(this.systemsetting.system.locale);
return this.loadScheme();
}
@ -225,12 +225,11 @@ namespace OS {
* Update the application local from the system
* locale or application specific locale configuration
*
* @private
* @param {string} name locale name e.g. `en_GB`
* @returns {void}
* @memberof BaseApplication
*/
protected updateLocale(name: string): void {
updateLocale(name: string): void {
const meta = this.meta();
if (!meta || !meta.locales) {
return;

View File

@ -296,10 +296,6 @@ namespace OS {
this.on("exit", () => this.quit(false));
this.host = this._gui.workspace;
this.dialog = undefined;
this.subscribe("systemlocalechange", (d) => {
this.updateLocale(d.message as string);
return this.update();
});
}
/**
@ -315,11 +311,10 @@ namespace OS {
/**
* Update the model locale
*
* @protected
* @param {string} name
* @memberof BaseModel
*/
protected updateLocale(name: string) {}
updateLocale(name: string) {}
/**
* Render the model's UI
*
@ -532,7 +527,7 @@ namespace OS {
subscribe(e: string, f: (d: API.AnnouncementDataType<any>) => void): void {
return announcer.on(e, f, this);
}
/**
* Open a dialog
*
@ -676,7 +671,11 @@ namespace OS {
*/
update(): void {
if (this.scheme) {
return this.scheme.update();
this.scheme.update();
}
if(this.dialog)
{
this.dialog.update();
}
}

View File

@ -405,41 +405,33 @@ namespace OS {
const js = path + "/main.js";
try {
const d = await js.asFileHandle().read("script");
try {
const data: API.PackageMetaType = await `${path}/package.json`
.asFileHandle()
.read("json");
data.path = path;
if (application[app]) {
application[app].meta = data;
}
if (data.services) {
for (let v of data.services) {
application[v].meta = data;
}
}
//load css file
const css = `${path}/main.css`;
try {
const d_1 = await css.asFileHandle().onready();
const stamp = new Date().timestamp();
const el = $("<link>", {
rel: "stylesheet",
type: "text/css",
href: `${API.handle.get}/${css}?stamp=${stamp}`,
}).appendTo("head");
if (application[app]) {
application[app].style = el[0];
}
return resolve(app);
} catch (e) {
return resolve(app);
}
} catch (e_1) {
return reject(__e(e_1));
const data: API.PackageMetaType = await `${path}/package.json`
.asFileHandle()
.read("json");
data.path = path;
if (application[app]) {
application[app].meta = data;
}
} catch (e_2) {
return reject(__e(e_2));
if (data.services) {
for (let v of data.services) {
application[v].meta = data;
}
}
//load css file
const css = `${path}/main.css`;
const d_1 = await css.asFileHandle().onready();
const stamp = new Date().timestamp();
const el = $("<link>", {
rel: "stylesheet",
type: "text/css",
href: `${API.handle.get}/${css}?stamp=${stamp}`,
}).appendTo("head");
if (application[app]) {
application[app].style = el[0];
}
return resolve(app);
} catch (e) {
return reject(__e(e));
}
});
}
@ -459,37 +451,30 @@ namespace OS {
const arr = ph.split("/");
const srv = arr[1];
const app = arr[0];
if (application[srv]) {
try {
try {
if (application[srv]) {
const d = await OS.PM.createProcess(
srv,
application[srv]
);
return resolve(d);
} catch (e) {
return reject(__e(e));
}
} else {
try {
} else {
await loadApp(app);
if (!application[srv]) {
return reject(
API.throwe(__("Service not found: {0}", ph))
);
}
try {
const d_1 = await PM.createProcess(
srv,
application[srv]
);
return resolve(d_1);
} catch (e_1) {
return reject(__e(e_1));
}
} catch (e_2) {
return reject(__e(e_2));
const d_1 = await PM.createProcess(
srv,
application[srv]
);
return resolve(d_1);
}
}
catch (e) {
return reject(__e(e));
}
});
}
@ -529,59 +514,42 @@ namespace OS {
* @param {AppArgumentsType[]} args application arguments
*/
export function launch(app: string, args: AppArgumentsType[]): Promise<OS.PM.ProcessType> {
return new Promise((resolve, reject) => {
if (!application[app]) {
// first load it
loadApp(app)
.then((a) => {
if (!application[app]) {
const e = API.throwe(__("Application not found"));
announcer.oserror(
__("{0} is not an application", app),
e);
return reject(e);
}
PM.createProcess(
app,
application[app],
args
).catch((e) => {
announcer.osfail(
__("Unable to launch: {0}", app),
e
);
return reject(e);
}
).then((p: PM.ProcessType) => resolve(p));
return new Promise(async (resolve, reject) => {
try {
if (!application[app]) {
// first load it
await loadApp(app);
if (!application[app]) {
const e = API.throwe(__("Application not found"));
announcer.oserror(
__("{0} is not an application", app),
e);
return reject(e);
}
)
.catch((e) => {
announcer.osfail(__("Unable to launch: {0}", app), e);
reject(e);
}
);
} else {
// now launch it
if (application[app]) {
PM.createProcess(
const p = await PM.createProcess(
app,
application[app],
args
).catch((e: Error) => {
announcer.osfail(__("Unable to launch: {0}", app), e);
return reject(e);
}
);
resolve(p);
} else {
const e = API.throwe(__("Application not found"));
announcer.osfail(
__("Unable to find: {0}", app),
e
// now launch it
const p = await PM.createProcess(
app,
application[app],
args
);
return reject(e);
resolve(p);
}
}
catch (e) {
announcer.osfail(
__("Unable to launch: {0}", app),
e
);
return reject(__e(e));
}
});
}
@ -989,9 +957,8 @@ namespace OS {
// desktop[0].set "selected", -1
$(desktop).on("click", function (e) {
let el:any = $(e.target).closest("afx-app-window")[0];
if(el)
{
let el: any = $(e.target).closest("afx-app-window")[0];
if (el) {
return;
}
el = $(e.target).parent();

View File

@ -63,6 +63,10 @@ namespace OS {
obj.birth = new Date().getTime();
PM.pidalloc++;
obj.pid = PM.pidalloc;
obj.subscribe("systemlocalechange", (d) => {
obj.updateLocale(d.message as string);
return obj.update();
});
PM.processes[app].push(obj);
if (metaclass.type === ModelType.Application) {
GUI.dock(
@ -149,7 +153,11 @@ namespace OS {
if (!PM.processes[app]) {
return;
}
PM.processes[app].map((a) => a.quit(force));
const arr = PM.processes[app].map( e => e);
for(const p of arr)
{
p.quit(force);
}
}
}
}