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 {
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
*
@ -1063,10 +1114,10 @@ declare namespace OS {
*
* @export
* @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
*/
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
*
@ -1101,13 +1152,14 @@ declare namespace OS {
*/
function osinfo(m: string | FormattedString): void;
/**
* trigger a specific global event
*
*
* @export
* @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
* the global announcement system
@ -4664,11 +4716,11 @@ declare namespace OS {
*
* @protected
* @param {string} e event name
* @param {(d: any) => void} f event callback
* @param {(d: API.AnnouncementDataType) => void} f event callback
* @returns {void}
* @memberof BaseModel
*/
subscribe(e: string, f: (d: any) => void): void;
subscribe(e: string, f: (d: API.AnnouncementDataType) => void): void;
/**
* Open a dialog
*
@ -4695,19 +4747,20 @@ declare namespace OS {
* @protected
* @param {string} t event name
* @param {(string | FormattedString)} m event message
* @param {Error} [e] error object if any
* @param {any} u_data user data object if any
* @returns {void}
* @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
*
* @param {(string | FormattedString)} m notification string
* @param {any} u_data user data object if any
* @returns {void}
* @memberof BaseModel
*/
notify(m: string | FormattedString): void;
notify(m: string | FormattedString, data?: any): void;
/**
* Publish a global warning
*

Binary file not shown.

View File

@ -18,6 +18,63 @@
namespace OS {
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
*
@ -251,10 +308,10 @@ namespace OS {
*
* @export
* @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
*/
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]) {
announcer.listeners[a.pid] = [];
}
@ -282,7 +339,7 @@ namespace OS {
* @param {Error} e error to be reported
*/
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
*/
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
*/
export function osinfo(m: string | FormattedString): void {
announcer.ostrigger("info", { m, e: null });
announcer.ostrigger("info", m);
}
/**
* trigger a specific global event
*
*
* @export
* @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 {
announcer.trigger(e, { id: 0, data: d, name: "OS" });
export function ostrigger(e: string, m: string| FormattedString, d?: any): void {
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.subscribe("appregistry", (m) => {
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;
}
/**
* Enum definition of different model types
*
@ -295,8 +296,8 @@ namespace OS {
this.on("exit", () => this.quit(false));
this.host = this._gui.workspace;
this.dialog = undefined;
this.subscribe("systemlocalechange", (name) => {
this.updateLocale(name);
this.subscribe("systemlocalechange", (d) => {
this.updateLocale(d.message as string);
return this.update();
});
}
@ -524,11 +525,11 @@ namespace OS {
*
* @protected
* @param {string} e event name
* @param {(d: any) => void} f event callback
* @param {(d: API.AnnouncementDataType) => void} f event callback
* @returns {void}
* @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);
}
@ -587,41 +588,39 @@ namespace OS {
* @protected
* @param {string} t event name
* @param {(string | FormattedString)} m event message
* @param {Error} [e] error object if any
* @param {any} u_data user data object if any
* @returns {void}
* @memberof BaseModel
*/
protected publish(
t: string,
m: string | FormattedString,
e?: Error
u_data?: any
): void {
const mt = this.meta();
let icon: string = undefined;
const data: API.AnnouncementDataType = {} as API.AnnouncementDataType;
data.icon = undefined;
if (mt && mt.icon) {
icon = `${mt.path}/${mt.icon}`;
data.icon = `${mt.path}/${mt.icon}`;
}
return announcer.trigger(t, {
id: this.pid,
name: this.name,
data: {
m: m,
icon: icon,
iconclass: mt?mt.iconclass:undefined,
e: e,
},
});
data.id = this.pid;
data.name = this.name;
data.message = m;
data.iconclass = mt?mt.iconclass:undefined;
data.u_data = u_data;
return announcer.trigger(t, data);
}
/**
* Publish a global notification
*
* @param {(string | FormattedString)} m notification string
* @param {any} u_data user data object if any
* @returns {void}
* @memberof BaseModel
*/
notify(m: string | FormattedString): void {
return this.publish("notification", m);
notify(m: string | FormattedString, data?: any): void {
return this.publish("notification", m, data);
}
/**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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