From b1649016f4d87dbc320da806afc33f67f83666c4 Mon Sep 17 00:00:00 2001 From: lxsang Date: Tue, 4 Aug 2020 19:51:32 +0200 Subject: [PATCH] add PackageFileHandle + support for library definition + minor fix --- src/core/gui.ts | 26 +++++--- src/core/vfs.ts | 60 ++++++++++++++++++- src/packages/CodePad/main.ts | 8 +-- .../CodePad/templates/sdk-package.tpl | 1 + src/packages/MarketPlace/main.ts | 10 ++-- src/packages/MarketPlace/package.json | 2 +- 6 files changed, 87 insertions(+), 20 deletions(-) diff --git a/src/core/gui.ts b/src/core/gui.ts index 70718b0..595079d 100644 --- a/src/core/gui.ts +++ b/src/core/gui.ts @@ -571,16 +571,24 @@ namespace OS { // first load it loadApp(app) .then((a) => - PM.createProcess( - app, - application[app], - args - ).catch((e) => - announcer.osfail( - __("Unable to launch: {0}", app), - e + { + if (!application[app]){ + return announcer.oserror( + __("{0} is not an application", app), + API.throwe(__("Application not found")) + ); + } + PM.createProcess( + app, + application[app], + args + ).catch((e) => + announcer.osfail( + __("Unable to launch: {0}", app), + e + ) ) - ) + } ) .catch((e) => announcer.osfail(__("Unable to launch: {0}", app), e) diff --git a/src/core/vfs.ts b/src/core/vfs.ts index 7f2473c..1f3bb28 100644 --- a/src/core/vfs.ts +++ b/src/core/vfs.ts @@ -1298,6 +1298,61 @@ namespace OS { register("^(home|desktop|os|Untitled)$", RemoteFileHandle); + + /** + * Package file is remote file ([[RemoteFileHandle]]) located either in + * the local user packages location or system packages + * location, it should be in the following format: + * + * ``` + * pkg://PKG_NAME/path/to/file + * + * ``` + * + * The system will locale the package name PKG_NAME either in the system domain + * or in user domain and return the correct path to the package + * + * @export + * @class PackageFileHandle + * @extends {RemoteFileHandle} + */ + export class PackageFileHandle extends RemoteFileHandle + { + + /** + *Creates an instance of PackageFileHandle. + * @param {string} pkg_path package path in string + * @memberof PackageFileHandle + */ + constructor(pkg_path: string) { + var error:FormattedString|string; + var pkg_name: string; + super(pkg_path); + // now find the correct path + if(!this.genealogy || this.genealogy.length == 0) + { + error = __("Invalid package path"); + announcer.oserror(error, API.throwe(error)); + throw new Error(error.__()); + } + else { + // get the correct path of the package + pkg_name = this.genealogy[0]; + if(OS.setting.system.packages[pkg_name]) + { + this.setPath(OS.setting.system.packages[pkg_name].path); + } + else + { + error = __("Package not found {0}", pkg_name); + announcer.oserror(error,API.throwe(error)); + throw new Error(error.__()); + } + } + } + } + register("^pkg$", PackageFileHandle); + /** * Application file is an AntOS special file allowing to * refer to an application as a regular file. Its protocol @@ -1372,7 +1427,10 @@ namespace OS { const result = []; for (let k in OS.setting.system.packages) { const v = OS.setting.system.packages[k]; - result.push(v); + if(v.app) + { + result.push(v); + } } return resolve({ result: result, diff --git a/src/packages/CodePad/main.ts b/src/packages/CodePad/main.ts index 238bf87..8201efb 100644 --- a/src/packages/CodePad/main.ts +++ b/src/packages/CodePad/main.ts @@ -1038,14 +1038,14 @@ namespace OS { * @returns {void} * @memberof CodePad */ - private menuAction(dataid: string, r?: CodePad): void { - let me: any = this; + private menuAction(dataid: string, r?: CodePad): any { + let me: CodePad = this; if (r) { me = r; } switch (dataid) { case "new": - return me.openFile("Untitled".asFileHandle()); + return me.openFile("Untitled".asFileHandle() as CodePadFileHandle); case "open": return me .openDialog("FileDialog", { @@ -1065,7 +1065,7 @@ namespace OS { }) .then(function (f: API.FileInfoType) { me.currdir = f.file.path.asFileHandle(); - return me.initSideBar(); + return me.toggleSideBar(); }); case "save": me.currfile.cache = me.editor.getValue(); diff --git a/src/packages/CodePad/templates/sdk-package.tpl b/src/packages/CodePad/templates/sdk-package.tpl index d853cbe..638139a 100644 --- a/src/packages/CodePad/templates/sdk-package.tpl +++ b/src/packages/CodePad/templates/sdk-package.tpl @@ -1,4 +1,5 @@ { + "pkgname": "{0}", "app":"{0}", "name":"{0}", "description":"{0}", diff --git a/src/packages/MarketPlace/main.ts b/src/packages/MarketPlace/main.ts index cb221f6..e1baa74 100644 --- a/src/packages/MarketPlace/main.ts +++ b/src/packages/MarketPlace/main.ts @@ -393,7 +393,7 @@ namespace OS { .then((d: string) => { let name: string; const v = JSON.parse(d); - const pth = `${this.installdir}/${v.app}`; + const pth = `${this.installdir}/${v.pkgname?v.pkgname:v.app}`; const dir = [pth]; const files = []; for (name in zip.files) { @@ -408,13 +408,13 @@ namespace OS { return this.mkdirs(dir) .then(() => { return this.installFile( - v.app, + v.pkgname?v.pkgname:v.app, zip, files ) .then(() => { const app_meta = { - pkgname: v.app, + pkgname: v.pkgname?v.pkgname:v.app, name: v.name, text: v.name, icon: v.icon, @@ -430,7 +430,7 @@ namespace OS { : undefined, }; v.text = v.name; - v.filename = v.app; + v.filename = v.pkgname?v.pkgname:v.app; v.type = "app"; v.mime = "antos/app"; if ( @@ -442,7 +442,7 @@ namespace OS { } v.path = pth; this.systemsetting.system.packages[ - v.app + v.pkgname?v.pkgname:v.app ] = v; this.appDetail(app_meta); return resolve(v.name); diff --git a/src/packages/MarketPlace/package.json b/src/packages/MarketPlace/package.json index 3e7ad9b..c8d2db5 100644 --- a/src/packages/MarketPlace/package.json +++ b/src/packages/MarketPlace/package.json @@ -6,7 +6,7 @@ "author": "Xuan Sang LE", "email": "xsang.le@gmail.com" }, - "version":"0.0.1-a", + "version":"0.1.5-a", "category":"System", "iconclass":"fa fa-adn", "mimes":["none"],