mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-11-08 14:08:22 +01:00
App name now can differ from pkgname
This commit is contained in:
parent
b381294064
commit
9b5da170e7
@ -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) {
|
|
||||||
path = setting.system.packages[app].path;
|
|
||||||
}
|
|
||||||
const js = path + "/main.js";
|
|
||||||
try {
|
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;
|
||||||
|
}
|
||||||
|
if(!path)
|
||||||
|
{
|
||||||
|
throw __("Unable to locate package of {0}", app).__();
|
||||||
|
}
|
||||||
|
const js = path + "/main.js";
|
||||||
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()
|
||||||
|
@ -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
|
@ -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,7 +329,25 @@ 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)
|
||||||
|
{
|
||||||
|
const mt = {
|
||||||
|
pkgname: v.pkgname ? v.pkgname : v.app,
|
||||||
|
app: v.app,
|
||||||
|
name: v.name,
|
||||||
|
text: `${v.name} ${v.version}`,
|
||||||
|
icon: v.icon,
|
||||||
|
iconclass: v.iconclass,
|
||||||
|
category: v.category,
|
||||||
|
author: v.info.author,
|
||||||
|
version: v.version,
|
||||||
|
description: `${v.path}/README.md`,
|
||||||
|
dependencies: v.dependencies ? Array.from(v.dependencies) : [],
|
||||||
|
dependBy: []
|
||||||
|
};
|
||||||
|
this.apps_meta[`${k}@${v.version}`] = mt;
|
||||||
|
return mt;
|
||||||
|
}
|
||||||
fetchApps(): Promise<GenericObject<any>> {
|
fetchApps(): Promise<GenericObject<any>> {
|
||||||
return new Promise((resolve, _reject) => {
|
return new Promise((resolve, _reject) => {
|
||||||
let v: API.PackageMetaType;
|
let v: API.PackageMetaType;
|
||||||
@ -336,19 +355,7 @@ namespace OS {
|
|||||||
const pkgcache = this.systemsetting.system.packages;
|
const pkgcache = this.systemsetting.system.packages;
|
||||||
for (let k in pkgcache) {
|
for (let k in pkgcache) {
|
||||||
v = pkgcache[k];
|
v = pkgcache[k];
|
||||||
this.apps_meta[`${k}@${v.version}`] = {
|
this.add_meta_from(k,v);
|
||||||
pkgname: v.pkgname ? v.pkgname : v.app,
|
|
||||||
name: v.name,
|
|
||||||
text: `${v.name} ${v.version}`,
|
|
||||||
icon: v.icon,
|
|
||||||
iconclass: v.iconclass,
|
|
||||||
category: v.category,
|
|
||||||
author: v.info.author,
|
|
||||||
version: v.version,
|
|
||||||
description: `${v.path}/README.md`,
|
|
||||||
dependencies: v.dependencies ? Array.from(v.dependencies) : [],
|
|
||||||
dependBy: []
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
if (!meta) {
|
|
||||||
return reject(this._api.throwe(__("Unable to find application meta-data: {0}", pkgname)));
|
|
||||||
}
|
|
||||||
const app = this.systemsetting.system.packages[meta.pkgname];
|
|
||||||
if (!app) {
|
|
||||||
return reject(this._api.throwe(__("Application {0} is not installed", pkgname)));
|
|
||||||
}
|
|
||||||
// got the app meta
|
// got the app meta
|
||||||
try {
|
try {
|
||||||
|
if (!meta) {
|
||||||
|
throw __("Unable to find application meta-data: {0}", pkgname).__();
|
||||||
|
}
|
||||||
|
const app = this.systemsetting.system.packages[meta.pkgname];
|
||||||
|
if (!app) {
|
||||||
|
throw __("Application {0} is not installed", pkgname).__();
|
||||||
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -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"],
|
||||||
|
Loading…
Reference in New Issue
Block a user