add more docs, fix minor bug on dialog registration

This commit is contained in:
lxsang
2020-06-15 18:10:13 +02:00
parent 218f6142c6
commit 977bf0c62f
7 changed files with 400 additions and 76 deletions

View File

@ -18,7 +18,14 @@
namespace OS {
export namespace application {
/**
* Services are processes that run in the background and
* are waken up in certain circumstances such as global
* events or user interactions.
*
* Each service takes an entry in the system tray menu
* located on the system panel. This menu entry is used
* to access to service visual contents such as: options,
* task performing based on user interaction, etc.
*
* @export
* @abstract
@ -26,18 +33,70 @@ namespace OS {
* @extends {BaseModel}
*/
export abstract class BaseService extends BaseModel {
/**
* The service icon shown in the system tray
*
* @type {string}
* @memberof BaseService
*/
icon: string;
/**
* CSS class of the service icon shown in the system tray
*
* @type {string}
* @memberof BaseService
*/
iconclass: string;
/**
* Text of the service shown in the system tray
*
* @type {string}
* @memberof BaseService
*/
text: string;
/**
* Reference to the menu entry DOM element attached
* to the service
*
* @type {HTMLElement}
* @memberof BaseService
*/
domel: HTMLElement;
/**
* Reference to the timer that periodically execute the callback
* defined in [[watch]].
*
* @private
* @type {number}
* @memberof BaseService
*/
private timer: number;
/**
* Reference to th system tray menu
*
* @type {HTMLElement}
* @memberof BaseService
*/
holder: HTMLElement;
onmenuselect: (d: OS.GUI.TagEventType<GUI.tag.MenuEventData>) => void;
/**
* Place holder for service select callback
*
* @memberof BaseService
*/
onmenuselect: (
d: OS.GUI.TagEventType<GUI.tag.MenuEventData>
) => void;
/**
*Creates an instance of BaseService.
* @param {string} name
* @param {AppArgumentsType[]} args
* @param {string} name service class name
* @param {AppArgumentsType[]} args service arguments
* @memberof BaseService
*/
constructor(name: string, args: AppArgumentsType[]) {
@ -53,25 +112,27 @@ namespace OS {
}
/**
*
* Do nothing
*
* @memberof BaseService
*/
hide(): void {}
/**
* Init the service before attaching it to
* the system tray: event subscribe, scheme
* loading.
*
* Should be implemented by all subclasses
*
* @abstract
* @memberof BaseService
*/
abstract init(): void;
//implement by user
// event registe, etc
// scheme loader
/**
*
* Refresh the service menu entry in the
* system tray
*
* @memberof BaseService
*/
@ -80,7 +141,7 @@ namespace OS {
}
/**
*
* Get the service meta-data
*
* @returns {API.PackageMetaType}
* @memberof BaseService
@ -90,7 +151,8 @@ namespace OS {
}
/**
*
* Attach the service to a menu element
* such as the system tray menu
*
* @param {HTMLElement} h
* @memberof BaseService
@ -99,30 +161,35 @@ namespace OS {
this.holder = h;
}
/**
* Set the callback that will be called periodically
* after a period of time.
*
* Each service should only have at most one watcher
*
* @protected
* @param {number} t
* @param {() => void} f
* @param {number} t period time in seconds
* @param {() => void} f callback function
* @returns {number}
* @memberof BaseService
*/
protected watch(t: number, f: () => void): number {
var func = () => {
f();
if (this.timer) {
clearTimeout(this.timer);
}
return (this.timer = setTimeout(() => func(), t));
};
return func();
}
/**
*
* This function is called when the service
* is exited
*
* @protected
* @param {BaseEvent} evt
* @param {BaseEvent} evt exit event
* @returns
* @memberof BaseService
*/
@ -140,32 +207,34 @@ namespace OS {
}
/**
*
* Do nothing
*
* @memberof BaseService
*/
main(): void {}
/**
*
* Do nothing
*
* @memberof BaseService
*/
show(): void {}
/**
* Awake the service, this function is usually called when
* the system tray menu entry attached to the service is
* selected.
*
* This function should be implemented by all subclasses
*
* @abstract
* @param {GUI.TagEventType} e
* @memberof BaseService
*/
abstract awake(e: GUI.TagEventType<GUI.tag.MenuEventData>): void;
//implement by user to tart the service
/**
*
* Do nothing
*
* @protected
* @param {BaseEvent} evt
@ -173,7 +242,7 @@ namespace OS {
*/
protected cleanup(evt: BaseEvent) {}
}
//implemeted by user
BaseService.type = ModelType.Service;
BaseService.singleton = true;
}