update announcement system

This commit is contained in:
Dany LE 2021-11-24 22:15:25 +01:00
parent e345a61269
commit 3a24df169c
11 changed files with 182 additions and 91 deletions

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

@ -913,6 +913,57 @@ declare namespace OS {
} }
declare namespace OS { declare namespace OS {
namespace API { namespace API {
/**
* Data type exchanged via
* the global Announcement interface
*
* @export
* @interface AnnouncementDataType
*/
interface AnnouncementDataType {
/**
* message string
*
* @type {string| FormattedString}
* @memberof AppAnnouncementDataType
*/
message: string | FormattedString;
/**
* Process ID
*
* @type {number}
* @memberof AppAnnouncementDataType
*/
id: number;
/**
* App name
*
* @type {string | FormattedString}
* @memberof AppAnnouncementDataType
*/
name: string | FormattedString;
/**
* Icon file
*
* @type {string}
* @memberof AppAnnouncementDataType
*/
icon?: string;
/**
* App icon class
*
* @type {string}
* @memberof AppAnnouncementDataType
*/
iconclass?: string;
/**
* User specific data
*
* @type {*}
* @memberof AppAnnouncementDataType
*/
u_data?: any;
}
/** /**
* Observable entry type definition * Observable entry type definition
* *
@ -1063,10 +1114,10 @@ declare namespace OS {
* *
* @export * @export
* @param {string} e event name * @param {string} e event name
* @param {(d: any) => void} f event callback * @param {(d: API.AnnouncementDataType) => void} f event callback
* @param {GUI.BaseModel} a the process (Application/service) related to the callback * @param {GUI.BaseModel} a the process (Application/service) related to the callback
*/ */
function on(e: string, f: (d: any) => void, a: BaseModel): void; function on(e: string, f: (d: API.AnnouncementDataType) => void, a: BaseModel): void;
/** /**
* Trigger a global event * Trigger a global event
* *
@ -1101,13 +1152,14 @@ declare namespace OS {
*/ */
function osinfo(m: string | FormattedString): void; function osinfo(m: string | FormattedString): void;
/** /**
* trigger a specific global event *
* *
* @export * @export
* @param {string} e event name * @param {string} e event name
* @param {*} d event data * @param {(string| FormattedString)} m event message
* @param {*} [d] user data
*/ */
function ostrigger(e: string, d: any): void; function ostrigger(e: string, m: string | FormattedString, d?: any): void;
/** /**
* Unregister a process (application/service) from * Unregister a process (application/service) from
* the global announcement system * the global announcement system
@ -4664,11 +4716,11 @@ declare namespace OS {
* *
* @protected * @protected
* @param {string} e event name * @param {string} e event name
* @param {(d: any) => void} f event callback * @param {(d: API.AnnouncementDataType) => void} f event callback
* @returns {void} * @returns {void}
* @memberof BaseModel * @memberof BaseModel
*/ */
subscribe(e: string, f: (d: any) => void): void; subscribe(e: string, f: (d: API.AnnouncementDataType) => void): void;
/** /**
* Open a dialog * Open a dialog
* *
@ -4695,19 +4747,20 @@ declare namespace OS {
* @protected * @protected
* @param {string} t event name * @param {string} t event name
* @param {(string | FormattedString)} m event message * @param {(string | FormattedString)} m event message
* @param {Error} [e] error object if any * @param {any} u_data user data object if any
* @returns {void} * @returns {void}
* @memberof BaseModel * @memberof BaseModel
*/ */
protected publish(t: string, m: string | FormattedString, e?: Error): void; protected publish(t: string, m: string | FormattedString, u_data?: any): void;
/** /**
* Publish a global notification * Publish a global notification
* *
* @param {(string | FormattedString)} m notification string * @param {(string | FormattedString)} m notification string
* @param {any} u_data user data object if any
* @returns {void} * @returns {void}
* @memberof BaseModel * @memberof BaseModel
*/ */
notify(m: string | FormattedString): void; notify(m: string | FormattedString, data?: any): void;
/** /**
* Publish a global warning * Publish a global warning
* *

Binary file not shown.

View File

@ -18,6 +18,63 @@
namespace OS { namespace OS {
export namespace API { export namespace API {
/**
* Data type exchanged via
* the global Announcement interface
*
* @export
* @interface AnnouncementDataType
*/
export interface AnnouncementDataType {
/**
* message string
*
* @type {string| FormattedString}
* @memberof AppAnnouncementDataType
*/
message: string | FormattedString;
/**
* Process ID
*
* @type {number}
* @memberof AppAnnouncementDataType
*/
id: number;
/**
* App name
*
* @type {string | FormattedString}
* @memberof AppAnnouncementDataType
*/
name: string | FormattedString;
/**
* Icon file
*
* @type {string}
* @memberof AppAnnouncementDataType
*/
icon?: string;
/**
* App icon class
*
* @type {string}
* @memberof AppAnnouncementDataType
*/
iconclass?: string;
/**
* User specific data
*
* @type {*}
* @memberof AppAnnouncementDataType
*/
u_data?: any;
}
/** /**
* Observable entry type definition * Observable entry type definition
* *
@ -251,10 +308,10 @@ namespace OS {
* *
* @export * @export
* @param {string} e event name * @param {string} e event name
* @param {(d: any) => void} f event callback * @param {(d: API.AnnouncementDataType) => void} f event callback
* @param {GUI.BaseModel} a the process (Application/service) related to the callback * @param {GUI.BaseModel} a the process (Application/service) related to the callback
*/ */
export function on(e: string, f: (d: any) => void, a: BaseModel): void { export function on(e: string, f: (d: API.AnnouncementDataType) => void, a: BaseModel): void {
if (!announcer.listeners[a.pid]) { if (!announcer.listeners[a.pid]) {
announcer.listeners[a.pid] = []; announcer.listeners[a.pid] = [];
} }
@ -282,7 +339,7 @@ namespace OS {
* @param {Error} e error to be reported * @param {Error} e error to be reported
*/ */
export function osfail(m: string | FormattedString, e: Error): void { export function osfail(m: string | FormattedString, e: Error): void {
announcer.ostrigger("fail", { m, e }); announcer.ostrigger("fail", m, e );
} }
/** /**
@ -294,7 +351,7 @@ namespace OS {
* @param {Error} e error to be reported * @param {Error} e error to be reported
*/ */
export function oserror(m: string | FormattedString, e: Error): void { export function oserror(m: string | FormattedString, e: Error): void {
announcer.ostrigger("error", { m, e }); announcer.ostrigger("error", m, e );
} }
/** /**
@ -304,18 +361,24 @@ namespace OS {
* @param {(string | FormattedString)} m notification message * @param {(string | FormattedString)} m notification message
*/ */
export function osinfo(m: string | FormattedString): void { export function osinfo(m: string | FormattedString): void {
announcer.ostrigger("info", { m, e: null }); announcer.ostrigger("info", m);
} }
/** /**
* trigger a specific global event *
* *
* @export * @export
* @param {string} e event name * @param {string} e event name
* @param {*} d event data * @param {(string| FormattedString)} m event message
* @param {*} [d] user data
*/ */
export function ostrigger(e: string, d: any): void { export function ostrigger(e: string, m: string| FormattedString, d?: any): void {
announcer.trigger(e, { id: 0, data: d, name: "OS" }); const aob: API.AnnouncementDataType = {} as API.AnnouncementDataType;
aob.id = 0;
aob.message = m;
aob.u_data = d;
aob.name = "OS";
announcer.trigger(e, aob);
} }
/** /**

View File

@ -85,7 +85,7 @@ namespace OS {
this.keycomb = {}; this.keycomb = {};
this.subscribe("appregistry", (m) => { this.subscribe("appregistry", (m) => {
if (m.name === this.name) { if (m.name === this.name) {
this.applySetting(m.data.m); this.applySetting(m.message as string);
} }
}); });
} }

View File

@ -43,6 +43,7 @@ namespace OS {
*/ */
[propName: string]: any; [propName: string]: any;
} }
/** /**
* Enum definition of different model types * Enum definition of different model types
* *
@ -295,8 +296,8 @@ 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", (name) => { this.subscribe("systemlocalechange", (d) => {
this.updateLocale(name); this.updateLocale(d.message as string);
return this.update(); return this.update();
}); });
} }
@ -524,11 +525,11 @@ namespace OS {
* *
* @protected * @protected
* @param {string} e event name * @param {string} e event name
* @param {(d: any) => void} f event callback * @param {(d: API.AnnouncementDataType) => void} f event callback
* @returns {void} * @returns {void}
* @memberof BaseModel * @memberof BaseModel
*/ */
subscribe(e: string, f: (d: any) => void): void { subscribe(e: string, f: (d: API.AnnouncementDataType) => void): void {
return announcer.on(e, f, this); return announcer.on(e, f, this);
} }
@ -587,41 +588,39 @@ namespace OS {
* @protected * @protected
* @param {string} t event name * @param {string} t event name
* @param {(string | FormattedString)} m event message * @param {(string | FormattedString)} m event message
* @param {Error} [e] error object if any * @param {any} u_data user data object if any
* @returns {void} * @returns {void}
* @memberof BaseModel * @memberof BaseModel
*/ */
protected publish( protected publish(
t: string, t: string,
m: string | FormattedString, m: string | FormattedString,
e?: Error u_data?: any
): void { ): void {
const mt = this.meta(); const mt = this.meta();
let icon: string = undefined; const data: API.AnnouncementDataType = {} as API.AnnouncementDataType;
data.icon = undefined;
if (mt && mt.icon) { if (mt && mt.icon) {
icon = `${mt.path}/${mt.icon}`; data.icon = `${mt.path}/${mt.icon}`;
} }
return announcer.trigger(t, { data.id = this.pid;
id: this.pid, data.name = this.name;
name: this.name, data.message = m;
data: { data.iconclass = mt?mt.iconclass:undefined;
m: m, data.u_data = u_data;
icon: icon, return announcer.trigger(t, data);
iconclass: mt?mt.iconclass:undefined,
e: e,
},
});
} }
/** /**
* Publish a global notification * Publish a global notification
* *
* @param {(string | FormattedString)} m notification string * @param {(string | FormattedString)} m notification string
* @param {any} u_data user data object if any
* @returns {void} * @returns {void}
* @memberof BaseModel * @memberof BaseModel
*/ */
notify(m: string | FormattedString): void { notify(m: string | FormattedString, data?: any): void {
return this.publish("notification", m); return this.publish("notification", m, data);
} }
/** /**

View File

@ -1603,7 +1603,7 @@ namespace OS {
const d = await API.get(path, "json"); const d = await API.get(path, "json");
OS.setting.system.locale = name; OS.setting.system.locale = name;
API.lang = d; API.lang = d;
announcer.trigger("systemlocalechange", name); announcer.ostrigger("systemlocalechange", name);
return resolve(d); return resolve(d);
} catch (e) { } catch (e) {
return reject(__e(e)); return reject(__e(e));

View File

@ -1145,7 +1145,7 @@ namespace OS {
loadTheme(setting.appearance.theme, true); loadTheme(setting.appearance.theme, true);
wallpaper(undefined); wallpaper(undefined);
OS.announcer.observable.one("syspanelloaded", async function () { OS.announcer.observable.one("syspanelloaded", async function () {
OS.announcer.observable.on("systemlocalechange", (name) => OS.announcer.observable.on("systemlocalechange", (_) =>
$("#syspanel")[0].update() $("#syspanel")[0].update()
); );
@ -1197,10 +1197,10 @@ namespace OS {
// initDM // initDM
API.setLocale(setting.system.locale).then(() => initDM()); API.setLocale(setting.system.locale).then(() => initDM());
Ant.OS.announcer.observable.on("error", function (d) { Ant.OS.announcer.observable.on("error", function (d) {
console.log(d.data.e); console.log(d.u_data);
}); });
Ant.OS.announcer.observable.on("fail", function (d) { Ant.OS.announcer.observable.on("fail", function (d) {
console.log(d.data.e); console.log(d.u_data);
}); });
} }
/** /**

View File

@ -595,10 +595,7 @@ namespace OS {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const r: RequestResult = await this._wr(t); const r: RequestResult = await this._wr(t);
announcer.ostrigger("VFS", { announcer.ostrigger("VFS", "write",this);
m: "write",
file: this,
});
return resolve(r); return resolve(r);
} catch (e) { } catch (e) {
return reject(__e(e)); return reject(__e(e));
@ -620,10 +617,7 @@ namespace OS {
try { try {
const r = await this.onready(); const r = await this.onready();
const d_1 = await this._mk(d); const d_1 = await this._mk(d);
announcer.ostrigger("VFS", { announcer.ostrigger("VFS","mk",this);
m: "mk",
file: this,
});
return resolve(d_1); return resolve(d_1);
} catch (e_1) { } catch (e_1) {
return reject(__e(e_1)); return reject(__e(e_1));
@ -644,10 +638,7 @@ namespace OS {
try { try {
const r = await this.onready(); const r = await this.onready();
const d = await this._rm(); const d = await this._rm();
announcer.ostrigger("VFS", { announcer.ostrigger("VFS", "remove",this);
m: "remove",
file: this,
});
return resolve(d); return resolve(d);
} catch (e_1) { } catch (e_1) {
return reject(__e(e_1)); return reject(__e(e_1));
@ -670,10 +661,7 @@ namespace OS {
try { try {
const r = await this.onready(); const r = await this.onready();
const d = await this._up(); const d = await this._up();
announcer.ostrigger("VFS", { announcer.ostrigger("VFS", "upload", this);
m: "upload",
file: this,
});
return resolve(d); return resolve(d);
} catch (e_1) { } catch (e_1) {
return reject(__e(e_1)); return reject(__e(e_1));
@ -696,10 +684,7 @@ namespace OS {
try { try {
const r = await this.onready(); const r = await this.onready();
const d = await this._pub(); const d = await this._pub();
announcer.ostrigger("VFS", { announcer.ostrigger("VFS", "publish",this);
m: "publish",
file: this,
});
return resolve(d); return resolve(d);
} catch (e_1) { } catch (e_1) {
return reject(__e(e_1)); return reject(__e(e_1));
@ -722,10 +707,7 @@ namespace OS {
try { try {
const r = await this.onready(); const r = await this.onready();
const d = await this._down(); const d = await this._down();
announcer.ostrigger("VFS", { announcer.ostrigger("VFS", "download",this);
m: "download",
file: this,
});
return resolve(d); return resolve(d);
} catch (e_1) { } catch (e_1) {
return reject(__e(e_1)); return reject(__e(e_1));
@ -747,10 +729,7 @@ namespace OS {
try { try {
const r = await this.onready(); const r = await this.onready();
const data = await this._mv(d); const data = await this._mv(d);
announcer.ostrigger("VFS", { announcer.ostrigger("VFS", "move",d.asFileHandle());
m: "move",
file: d.asFileHandle(),
});
return resolve(data); return resolve(data);
} catch (e_1) { } catch (e_1) {
@ -774,10 +753,7 @@ namespace OS {
try { try {
const r = await this.onready(); const r = await this.onready();
const d = await this._exec(); const d = await this._exec();
announcer.ostrigger("VFS", { announcer.ostrigger("VFS", "execute", this);
m: "execute",
file: this,
});
return resolve(d); return resolve(d);
} catch (e_1) { } catch (e_1) {
return reject(__e(e_1)); return reject(__e(e_1));

View File

@ -300,12 +300,12 @@ namespace OS {
if (!this.vfs_event_flag) { if (!this.vfs_event_flag) {
return; return;
} }
if (["read", "publish", "download"].includes(d.data.m)) { if (["read", "publish", "download"].includes(d.message as string)) {
return; return;
} }
if ( if (
d.data.file.hash() === this.currdir.hash() || d.u_data.hash() === this.currdir.hash() ||
d.data.file.parent().hash() === this.currdir.hash() d.u_data.file.parent().hash() === this.currdir.hash()
) { ) {
return this.view.path = this.currdir.path; return this.view.path = this.currdir.path;
} }

View File

@ -160,7 +160,7 @@ namespace OS {
} }
return result1; return result1;
})(); })();
announcer.ostrigger("app-pinned", this.applist.data); announcer.ostrigger("app-pinned", "app-pinned", this.applist.data);
} }
} }
App.AppAndServiceHandle = AppAndServiceHandle; App.AppAndServiceHandle = AppAndServiceHandle;

View File

@ -112,19 +112,19 @@ namespace OS {
* *
* @private * @private
* @param {string} s * @param {string} s
* @param {GenericObject<any>} o * @param {API.AnnouncementDataType} o
* @memberof PushNotification * @memberof PushNotification
*/ */
private addLog(s: string, o: GenericObject<any>): void { private addLog(s: string, o: API.AnnouncementDataType): void {
const logtime = new Date(); const logtime = new Date();
const log = { const log = {
type: s, type: s,
name: o.name, name: o.name,
text: `${o.data.m}`, text: `${o.message}`,
id: o.id, id: o.id,
icon: o.data.icon, icon: o.icon,
iconclass: o.data.iconclass, iconclass: o.iconclass,
error: o.data.e, error: o.u_data,
time: logtime, time: logtime,
closable: true, closable: true,
tag: "afx-bug-list-item", tag: "afx-bug-list-item",
@ -141,14 +141,14 @@ namespace OS {
* *
* @private * @private
* @param {string} s * @param {string} s
* @param {GenericObject<any>} o * @param {API.AnnouncementDataType} o
* @memberof PushNotification * @memberof PushNotification
*/ */
private pushout(s: string, o: GenericObject<any>): void { private pushout(s: string, o: API.AnnouncementDataType): void {
const d = { const d = {
text: `[${s}] ${o.name} (${o.id}): ${o.data.m}`, text: `[${s}] ${o.name} (${o.id}): ${o.message}`,
icon: o.data.icon, icon: o.icon,
iconclass: o.data.iconclass, iconclass: o.iconclass,
closable: true, closable: true,
}; };
if (s !== "INFO") { if (s !== "INFO") {