minor improvement on GUI API

This commit is contained in:
lxsang 2021-03-15 11:01:57 +01:00
parent de5878c349
commit 9a12e9176f
3 changed files with 58 additions and 43 deletions

View File

@ -43,7 +43,7 @@ namespace OS {
* *
* @memberof ShortcutType * @memberof ShortcutType
*/ */
[propName: string]: GenericObject<(e: JQuery.KeyUpEvent) => void>; [propName: string]: GenericObject<(e: JQuery.KeyUpEvent) => void>;
} }
/** /**
@ -317,7 +317,8 @@ namespace OS {
return; return;
} }
if (it.type === "app" && it.app) { if (it.type === "app" && it.app) {
return launch(it.app, []); launch(it.app, []);
return;
} }
if (it.type === "app") { if (it.type === "app") {
return announcer.osinfo( return announcer.osinfo(
@ -331,7 +332,8 @@ namespace OS {
); );
} }
if (apps.length === 1) { if (apps.length === 1) {
return launch(apps[0].app, [it]); launch(apps[0].app, [it]);
return;
} }
const list = apps.map((e) => ({ const list = apps.map((e) => ({
text: e.app, text: e.app,
@ -364,7 +366,7 @@ namespace OS {
"This method is used for developing only, please use the launch method instead" "This method is used for developing only, please use the launch method instead"
); );
unloadApp(app); unloadApp(app);
return launch(app, args); launch(app, args);
} }
/** /**
@ -529,50 +531,61 @@ namespace OS {
* @param {string} app application class name * @param {string} app application class name
* @param {AppArgumentsType[]} args application arguments * @param {AppArgumentsType[]} args application arguments
*/ */
export function launch(app: string, args: AppArgumentsType[]): void { export function launch(app: string, args: AppArgumentsType[]): Promise<OS.PM.ProcessType> {
if (!application[app]) { return new Promise((resolve, reject) => {
// first load it if (!application[app]) {
loadApp(app) // first load it
.then((a) => loadApp(app)
{ .then((a) => {
if (!application[app]){ if (!application[app]) {
return announcer.oserror( const e = API.throwe(__("Application not found"));
announcer.oserror(
__("{0} is not an application", app), __("{0} is not an application", app),
API.throwe(__("Application not found")) e);
); return reject(e);
} }
PM.createProcess( PM.createProcess(
app, app,
application[app], application[app],
args args
).catch((e) => ).catch((e) => {
announcer.osfail( announcer.osfail(
__("Unable to launch: {0}", app), __("Unable to launch: {0}", app),
e e
) );
) return reject(e);
}
).then((p: PM.ProcessType) => resolve(p));
} }
) )
.catch((e) => .catch((e) => {
announcer.osfail(__("Unable to launch: {0}", app), e) announcer.osfail(__("Unable to launch: {0}", app), e);
); reject(e);
} else { }
// now launch it );
if (application[app]) {
PM.createProcess(
app,
application[app],
args
).catch((e: Error) =>
announcer.osfail(__("Unable to launch: {0}", app), e)
);
} else { } else {
announcer.osfail( // now launch it
__("Unable to find: {0}", app), if (application[app]) {
API.throwe("Application not found") PM.createProcess(
); app,
application[app],
args
).catch((e: Error) => {
announcer.osfail(__("Unable to launch: {0}", app), e);
return reject(e);
}
);
} else {
const e = API.throwe(__("Application not found"));
announcer.osfail(
__("Unable to find: {0}", app),
e
);
return reject(e);
}
} }
} });
} }
/** /**
@ -703,7 +716,7 @@ namespace OS {
var handle = function (e: HTMLElement) { var handle = function (e: HTMLElement) {
if (e.contextmenuHandle) { if (e.contextmenuHandle) {
const m = $("#contextmenu")[0] as tag.MenuTag; const m = $("#contextmenu")[0] as tag.MenuTag;
m.onmenuselect = () => {}; m.onmenuselect = () => { };
return e.contextmenuHandle(event, m); return e.contextmenuHandle(event, m);
} else { } else {
const p = $(e).parent().get(0); const p = $(e).parent().get(0);
@ -745,9 +758,9 @@ namespace OS {
} }
if (arr.includes("SHIFT")) { if (arr.includes("SHIFT")) {
fnk += "SHIFT"; fnk += "SHIFT";
} }
if ( fnk == "") { if (fnk == "") {
return; return;
} }
fnk = `fn_${fnk.hash()}`; fnk = `fn_${fnk.hash()}`;
@ -906,9 +919,9 @@ namespace OS {
} }
if (event.shiftKey) { if (event.shiftKey) {
fnk += "SHIFT"; fnk += "SHIFT";
} }
if ( fnk == "") { if (fnk == "") {
return; return;
} }
fnk = `fn_${fnk.hash()}`; fnk = `fn_${fnk.hash()}`;

2
src/libs/jquery-3.6.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -140,7 +140,7 @@ namespace OS {
* @memberof PushNotification * @memberof PushNotification
*/ */
private showLogReport(): void { private showLogReport(): void {
return this._gui.launch("Syslog", []); this._gui.launch("Syslog", []);
} }
/** /**