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

Binary file not shown.

View File

@ -83,11 +83,6 @@ namespace OS {
} }
this.setting = setting.applications[this.name]; this.setting = setting.applications[this.name];
this.keycomb = {}; 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.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); this.updateLocale(this.systemsetting.system.locale);
return this.loadScheme(); return this.loadScheme();
} }
@ -225,12 +225,11 @@ namespace OS {
* Update the application local from the system * Update the application local from the system
* locale or application specific locale configuration * locale or application specific locale configuration
* *
* @private
* @param {string} name locale name e.g. `en_GB` * @param {string} name locale name e.g. `en_GB`
* @returns {void} * @returns {void}
* @memberof BaseApplication * @memberof BaseApplication
*/ */
protected updateLocale(name: string): void { updateLocale(name: string): void {
const meta = this.meta(); const meta = this.meta();
if (!meta || !meta.locales) { if (!meta || !meta.locales) {
return; return;

View File

@ -296,10 +296,6 @@ namespace OS {
this.on("exit", () => this.quit(false)); this.on("exit", () => this.quit(false));
this.host = this._gui.workspace; this.host = this._gui.workspace;
this.dialog = undefined; 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 * Update the model locale
* *
* @protected
* @param {string} name * @param {string} name
* @memberof BaseModel * @memberof BaseModel
*/ */
protected updateLocale(name: string) {} updateLocale(name: string) {}
/** /**
* Render the model's UI * Render the model's UI
* *
@ -532,7 +527,7 @@ namespace OS {
subscribe(e: string, f: (d: API.AnnouncementDataType<any>) => void): void { subscribe(e: string, f: (d: API.AnnouncementDataType<any>) => void): void {
return announcer.on(e, f, this); return announcer.on(e, f, this);
} }
/** /**
* Open a dialog * Open a dialog
* *
@ -676,7 +671,11 @@ namespace OS {
*/ */
update(): void { update(): void {
if (this.scheme) { 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"; const js = path + "/main.js";
try { try {
const d = await js.asFileHandle().read("script"); const d = await js.asFileHandle().read("script");
try { const data: API.PackageMetaType = await `${path}/package.json`
const data: API.PackageMetaType = await `${path}/package.json` .asFileHandle()
.asFileHandle() .read("json");
.read("json"); data.path = path;
data.path = path; if (application[app]) {
if (application[app]) { application[app].meta = data;
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));
} }
} catch (e_2) { if (data.services) {
return reject(__e(e_2)); 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 arr = ph.split("/");
const srv = arr[1]; const srv = arr[1];
const app = arr[0]; const app = arr[0];
if (application[srv]) { try {
try { if (application[srv]) {
const d = await OS.PM.createProcess( const d = await OS.PM.createProcess(
srv, srv,
application[srv] application[srv]
); );
return resolve(d); return resolve(d);
} catch (e) { } else {
return reject(__e(e));
}
} else {
try {
await loadApp(app); await loadApp(app);
if (!application[srv]) { if (!application[srv]) {
return reject( return reject(
API.throwe(__("Service not found: {0}", ph)) API.throwe(__("Service not found: {0}", ph))
); );
} }
try { const d_1 = await PM.createProcess(
const d_1 = await PM.createProcess( srv,
srv, application[srv]
application[srv] );
); return resolve(d_1);
return resolve(d_1);
} catch (e_1) {
return reject(__e(e_1));
}
} catch (e_2) {
return reject(__e(e_2));
} }
} }
catch (e) {
return reject(__e(e));
}
}); });
} }
@ -529,59 +514,42 @@ namespace OS {
* @param {AppArgumentsType[]} args application arguments * @param {AppArgumentsType[]} args application arguments
*/ */
export function launch(app: string, args: AppArgumentsType[]): Promise<OS.PM.ProcessType> { export function launch(app: string, args: AppArgumentsType[]): Promise<OS.PM.ProcessType> {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
if (!application[app]) { try {
// first load it if (!application[app]) {
loadApp(app) // first load it
.then((a) => { await loadApp(app);
if (!application[app]) { if (!application[app]) {
const e = API.throwe(__("Application not found")); const e = API.throwe(__("Application not found"));
announcer.oserror( announcer.oserror(
__("{0} is not an application", app), __("{0} is not an application", app),
e); e);
return reject(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));
} }
) const p = await PM.createProcess(
.catch((e) => {
announcer.osfail(__("Unable to launch: {0}", app), e);
reject(e);
}
);
} else {
// now launch it
if (application[app]) {
PM.createProcess(
app, app,
application[app], application[app],
args args
).catch((e: Error) => {
announcer.osfail(__("Unable to launch: {0}", app), e);
return reject(e);
}
); );
resolve(p);
} else { } else {
const e = API.throwe(__("Application not found")); // now launch it
announcer.osfail( const p = await PM.createProcess(
__("Unable to find: {0}", app), app,
e 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[0].set "selected", -1
$(desktop).on("click", function (e) { $(desktop).on("click", function (e) {
let el:any = $(e.target).closest("afx-app-window")[0]; let el: any = $(e.target).closest("afx-app-window")[0];
if(el) if (el) {
{
return; return;
} }
el = $(e.target).parent(); el = $(e.target).parent();

View File

@ -63,6 +63,10 @@ namespace OS {
obj.birth = new Date().getTime(); obj.birth = new Date().getTime();
PM.pidalloc++; PM.pidalloc++;
obj.pid = PM.pidalloc; obj.pid = PM.pidalloc;
obj.subscribe("systemlocalechange", (d) => {
obj.updateLocale(d.message as string);
return obj.update();
});
PM.processes[app].push(obj); PM.processes[app].push(obj);
if (metaclass.type === ModelType.Application) { if (metaclass.type === ModelType.Application) {
GUI.dock( GUI.dock(
@ -149,7 +153,11 @@ namespace OS {
if (!PM.processes[app]) { if (!PM.processes[app]) {
return; 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);
}
} }
} }
} }