App name now can differ from pkgname

This commit is contained in:
DanyLE 2022-08-25 01:20:51 +02:00
parent b381294064
commit 9b5da170e7
4 changed files with 71 additions and 51 deletions

View File

@ -448,17 +448,36 @@ namespace OS {
* definition in the [[application]] namespace, then update * definition in the [[application]] namespace, then update
* the system packages meta-data * the system packages meta-data
* *
* First it tries to load the package with the app name is also the
* pkgname, if its fail, it will search the app name by pkg name and load
* it
*
* @param {string} app application class name * @param {string} app application class name
* @returns {Promise<string>} * @returns {Promise<string>}
*/ */
function loadApp(app: string): Promise<string> { function loadApp(app: string): Promise<string> {
return new Promise(async function (resolve, reject) { return new Promise(async function (resolve, reject) {
let path: string; let path: string = undefined;
if (setting.system.packages[app].path) { try {
if(!setting.system.packages[app])
{
for(const key in setting.system.packages)
{
const pkg = setting.system.packages[key];
if(pkg.app == app && pkg.path)
{
path = pkg.path;
}
}
}
else if (setting.system.packages[app].path) {
path = setting.system.packages[app].path; path = setting.system.packages[app].path;
} }
if(!path)
{
throw __("Unable to locate package of {0}", app).__();
}
const js = path + "/main.js"; const js = path + "/main.js";
try {
const d = await js.asFileHandle().read("script"); const d = await js.asFileHandle().read("script");
const data: API.PackageMetaType = await `${path}/package.json` const data: API.PackageMetaType = await `${path}/package.json`
.asFileHandle() .asFileHandle()

View File

@ -5,5 +5,6 @@ This application is icluded in the AntOS delivery
and cannot be removed/uinstalled by regular user and cannot be removed/uinstalled by regular user
## Change logs ## Change logs
- 0.2.7-b: only launch application
- 0.2.6-b: improve install process - 0.2.6-b: improve install process
- v0.2.5-b: add README.md - v0.2.5-b: add README.md

View File

@ -41,7 +41,7 @@ namespace OS {
main(): void { main(): void {
this.installdir = this.systemsetting.system.pkgpaths.user; this.installdir = this.systemsetting.system.pkgpaths.user;
// test repository // test repository
this.apps_meta = []; this.apps_meta = {};
this.applist = this.find("applist") as GUI.tag.ListViewTag; this.applist = this.find("applist") as GUI.tag.ListViewTag;
this.catlist = this.find("catlist") as GUI.tag.ListViewTag; this.catlist = this.find("catlist") as GUI.tag.ListViewTag;
@ -108,8 +108,8 @@ namespace OS {
return; return;
} }
const app = el.data; const app = el.data;
if (app.pkgname) { if (app.app) {
return this._gui.launch(app.pkgname, []); return this._gui.launch(app.app, []);
} }
}; };
@ -273,6 +273,7 @@ namespace OS {
if (this.apps_meta[name]) { if (this.apps_meta[name]) {
pkg.icon = this.apps_meta[name].icon; pkg.icon = this.apps_meta[name].icon;
pkg.iconclass = this.apps_meta[name].iconclass; pkg.iconclass = this.apps_meta[name].iconclass;
pkg.app = this.apps_meta[name].app;
} }
this.apps_meta[name] = pkg; this.apps_meta[name] = pkg;
} }
@ -328,16 +329,11 @@ namespace OS {
this.catlist.data = cat_list_data; this.catlist.data = cat_list_data;
this.catlist.selected = 0; this.catlist.selected = 0;
} }
private add_meta_from(k:string, v: API.PackageMetaType)
fetchApps(): Promise<GenericObject<any>> { {
return new Promise((resolve, _reject) => { const mt = {
let v: API.PackageMetaType;
this.apps_meta = {};
const pkgcache = this.systemsetting.system.packages;
for (let k in pkgcache) {
v = pkgcache[k];
this.apps_meta[`${k}@${v.version}`] = {
pkgname: v.pkgname ? v.pkgname : v.app, pkgname: v.pkgname ? v.pkgname : v.app,
app: v.app,
name: v.name, name: v.name,
text: `${v.name} ${v.version}`, text: `${v.name} ${v.version}`,
icon: v.icon, icon: v.icon,
@ -349,6 +345,17 @@ namespace OS {
dependencies: v.dependencies ? Array.from(v.dependencies) : [], dependencies: v.dependencies ? Array.from(v.dependencies) : [],
dependBy: [] dependBy: []
}; };
this.apps_meta[`${k}@${v.version}`] = mt;
return mt;
}
fetchApps(): Promise<GenericObject<any>> {
return new Promise((resolve, _reject) => {
let v: API.PackageMetaType;
this.apps_meta = {};
const pkgcache = this.systemsetting.system.packages;
for (let k in pkgcache) {
v = pkgcache[k];
this.add_meta_from(k,v);
} }
const list: string[] = [] const list: string[] = []
@ -551,7 +558,8 @@ namespace OS {
return reject(this._api.throwe(__("Unable to find package: {0}", pkgname))); return reject(this._api.throwe(__("Unable to find package: {0}", pkgname)));
} }
try { try {
const n = await this.install(meta.download + "?_=" + new Date().getTime(), meta); const mt = await this.install(meta.download + "?_=" + new Date().getTime(), meta);
meta.app = mt.app;
return resolve(meta); return resolve(meta);
} catch (e_1) { } catch (e_1) {
return reject(__e(e_1)); return reject(__e(e_1));
@ -621,13 +629,19 @@ namespace OS {
mimes: [".*/zip"], mimes: [".*/zip"],
}); });
const n = await this.install(d.file.path); const n = await this.install(d.file.path);
const name = n.pkgname?n.pkgname:n.app;
const apps = this.applist.data.map( const apps = this.applist.data.map(
(v) => v.pkgname (v) => v.pkgname
); );
const idx = apps.indexOf(n); const idx = apps.indexOf(name);
if (idx >= 0) { if (idx >= 0) {
this.applist.selected = idx; this.applist.selected = idx;
} }
else
{
const mt = this.add_meta_from(name,n);
this.appDetail(mt);
}
return resolve(n.name); return resolve(n.name);
} catch (error) { } catch (error) {
reject(__e(error)); reject(__e(error));
@ -638,7 +652,7 @@ namespace OS {
private install( private install(
zfile: string, zfile: string,
meta?: GenericObject<any> meta?: GenericObject<any>
): Promise<GenericObject<any>> { ): Promise<API.PackageMetaType> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
let v: API.PackageMetaType; let v: API.PackageMetaType;
@ -657,22 +671,6 @@ namespace OS {
}); });
}); });
const app_meta = {
pkgname: v.pkgname ? v.pkgname : v.app,
name: v.name,
text: v.name,
icon: v.icon,
iconclass: v.iconclass,
category: v.category,
author: v.info.author,
version: v.version,
description: meta
? meta.description
: undefined,
download: meta
? meta.download
: undefined,
};
v.text = v.name; v.text = v.name;
v.filename = v.pkgname ? v.pkgname : v.app; v.filename = v.pkgname ? v.pkgname : v.app;
v.type = "app"; v.type = "app";
@ -692,7 +690,7 @@ namespace OS {
this.systemsetting.system.packages[ this.systemsetting.system.packages[
v.pkgname ? v.pkgname : v.app v.pkgname ? v.pkgname : v.app
] = v; ] = v;
return resolve(app_meta); return resolve(v);
} catch (error) { } catch (error) {
reject(__e(error)); reject(__e(error));
} }
@ -708,20 +706,21 @@ namespace OS {
private uninstallPkg(pkgname: string): Promise<any> { private uninstallPkg(pkgname: string): Promise<any> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const meta = this.apps_meta[pkgname]; const meta = this.apps_meta[pkgname];
// got the app meta
try {
if (!meta) { if (!meta) {
return reject(this._api.throwe(__("Unable to find application meta-data: {0}", pkgname))); throw __("Unable to find application meta-data: {0}", pkgname).__();
} }
const app = this.systemsetting.system.packages[meta.pkgname]; const app = this.systemsetting.system.packages[meta.pkgname];
if (!app) { if (!app) {
return reject(this._api.throwe(__("Application {0} is not installed", pkgname))); throw __("Application {0} is not installed", pkgname).__();
} }
// got the app meta
try {
const r = await app.path const r = await app.path
.asFileHandle() .asFileHandle()
.remove(); .remove();
if (r.error) { if (r.error) {
return reject(this._api.throwe(__("Cannot uninstall package: {0}", r.error))); throw __("Cannot uninstall package: {0}", r.error).__();
} }
this.notify(__("Package uninstalled")); this.notify(__("Package uninstalled"));
// stop all the services if any // stop all the services if any
@ -739,6 +738,7 @@ namespace OS {
if (meta.domel) if (meta.domel)
this.applist.delete(meta.domel); this.applist.delete(meta.domel);
$(this.container).css("visibility", "hidden"); $(this.container).css("visibility", "hidden");
delete this.apps_meta[pkgname];
} }
return resolve(meta); return resolve(meta);
} }

View File

@ -7,7 +7,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.2.6-b", "version":"0.2.7-b",
"category":"System", "category":"System",
"iconclass":"fa fa-shopping-bag", "iconclass":"fa fa-shopping-bag",
"mimes":["none"], "mimes":["none"],