add GUI application

This commit is contained in:
lxsang 2021-05-06 17:26:01 +02:00
parent 12c55d1735
commit 2fc1a8cee4
11 changed files with 73 additions and 82 deletions

View File

@ -2,5 +2,6 @@
AntOSDK: development API for AntOS based applications/projects
## Change logs
- 0.0.6: add GUI application for building a JSON build file
- 0.0.5: add API that supports running Linux commands on server
- 0.0.4: support automatic locale generation

View File

@ -4,7 +4,7 @@
"jobs": [
{
"name": "vfs-rm",
"data": ["build/debug/scheme.html"]
"data": ["build"]
}
]
},
@ -15,7 +15,7 @@
"name":"locale-gen",
"data": {
"src": "",
"exclude": ["build/debug/", "core/", "ts/test\\.ts", "scheme\\.html"],
"exclude": ["build/debug/", "core/"],
"locale": "en_GB",
"dest": "package.json"
}
@ -36,7 +36,7 @@
{
"name": "ts-compile",
"data": {
"src": ["ts/main.ts"],
"src": ["ts/main.ts", "ts/app.ts"],
"dest": "build/debug/main.js"
}
}
@ -59,13 +59,19 @@
"src": [
"core",
"package.json",
"README.md"
"README.md",
"main.css",
"scheme.html"
],
"dest":"build/debug"
}
}
]
},
"debug": {
"depend": ["build","copy"],
"jobs": []
},
"release": {
"depend": ["build","uglify", "copy"],
"require": ["zip"],

View File

@ -2,5 +2,6 @@
AntOSDK: development API for AntOS based applications/projects
## Change logs
- 0.0.6: add GUI application for building a JSON build file
- 0.0.5: add API that supports running Linux commands on server
- 0.0.4: support automatic locale generation

View File

@ -1 +1 @@
var OS;!function(e){let t;!function(t){class r{constructor(t){this.worker=new Worker(t.asFileHandle().getlink()),this.jobs={},this.worker.onmessage=e=>{let t=e.data,r=this.jobs[t.id];r?"log"===t.type?r.logger&&(t.error?r.logger.error(t.result):!1===t.show_time&&r.logger.print?r.logger.print(t.result):r.logger.info(t.result)):(r.callback(t),delete this.jobs[t.id]):console.log("Unable to identify result of job",t.id,t)};const r={};for(const t in e.setting.system.packages){const o=e.setting.system.packages[t];r[t]={path:o.path,name:o.pkgname}}this.submit("sdk-setup",{REST:e.API.REST,pkgs:r})}newJobID(){return"job_"+Math.random().toString(36).replace(".","")}exectue_job(e,t,r,o,s){const i=this.newJobID(),n={id:i,cmd:e,data:t,root:r};this.jobs[i]={callback:o,logger:s},this.worker.postMessage(n)}submit(e,t,r,o){return new Promise((s,i)=>{this.exectue_job(e,t,r,e=>{if(e.error)return i(e.error);s(e.result)},o)})}terminate(){this.worker.terminate()}}class o{constructor(e,t){this.root=t,this.logger=e,o.worker||(o.worker=new r("pkg://libantosdk/core/worker.js"))}require(e){return this.run("sdk-import",e.map(e=>e+".worker.js"))}compile(e,t){return new Promise(async(r,o)=>{try{await this.require([e]),r(await this.run(e+"-compile",t))}catch(e){o(__e(e))}})}run(t,r){return"sdk-run-app"===t?new Promise(async(t,o)=>{try{let o=r;1==o.split("://").length&&(o=`${this.root}/${r}`);const s=await(o+"/package.json").asFileHandle().read("json");return s.text=s.name,s.path=o,s.filename=s.pkgname,s.type="app",s.mime="antos/app",s.icon&&(s.icon=`${s.path}/${s.icon}`),s.iconclass||s.icon||(s.iconclass="fa fa-adn"),this.logger.info(__("Installing...")),e.setting.system.packages[s.pkgname]=s,s.app?(this.logger.info(__("Running {0}...",s.app)),e.GUI.forceLaunch(s.app,[])):this.logger.error(__("{0} is not an application",s.pkgname)),t(void 0)}catch(e){o(e)}}):o.worker.submit(t,r,this.root,this.logger)}batch(e,t){return t.root&&(this.root=t.root),new Promise(async(r,o)=>{try{t.targets||o("No target found");for(const r of e){const e=t.targets[r];if(!e)return o(__("No target: {0}",r));if(e.depend&&await this.batch(e.depend,t),e.require&&await this.require(e.require),this.logger&&this.logger.info(__("### RUNNING STAGE: {0}###",r).__()),e.jobs)for(const t of e.jobs)await this.run(t.name,t.data)}r(void 0)}catch(e){o(e)}})}}let s;t.AntOSDKBuilder=o,function(e){class t extends e.RemoteFileHandle{constructor(e){super(e);const t="pkg://libantosdk/"+this.genealogy.join("/");this.setPath(t.asFileHandle().path)}}e.SDKFileHandle=t,e.register("^sdk$",t)}(s=t.VFS||(t.VFS={}))}(t=e.API||(e.API={}))}(OS||(OS={}));
var OS;!function(t){let e;!function(e){class i{constructor(e){this.worker=new Worker(e.asFileHandle().getlink()),this.jobs={},this.worker.onmessage=t=>{let e=t.data,i=this.jobs[e.id];i?"log"===e.type?i.logger&&(e.error?i.logger.error(e.result):!1===e.show_time&&i.logger.print?i.logger.print(e.result):i.logger.info(e.result)):(i.callback(e),delete this.jobs[e.id]):console.log("Unable to identify result of job",e.id,e)};const i={};for(const e in t.setting.system.packages){const s=t.setting.system.packages[e];i[e]={path:s.path,name:s.pkgname}}this.submit("sdk-setup",{REST:t.API.REST,pkgs:i})}newJobID(){return"job_"+Math.random().toString(36).replace(".","")}exectue_job(t,e,i,s,r){const o=this.newJobID(),n={id:o,cmd:t,data:e,root:i};this.jobs[o]={callback:s,logger:r},this.worker.postMessage(n)}submit(t,e,i,s){return new Promise((r,o)=>{this.exectue_job(t,e,i,t=>{if(t.error)return o(t.error);r(t.result)},s)})}terminate(){this.worker.terminate()}}class s{constructor(t,e){this.root=e,this.logger=t,s.worker||(s.worker=new i("pkg://libantosdk/core/worker.js"))}require(t){return this.run("sdk-import",t.map(t=>t+".worker.js"))}compile(t,e){return new Promise(async(i,s)=>{try{await this.require([t]),i(await this.run(t+"-compile",e))}catch(t){s(__e(t))}})}run(e,i){return"sdk-run-app"===e?new Promise(async(e,s)=>{try{let s=i;1==s.split("://").length&&(s=`${this.root}/${i}`);const r=await(s+"/package.json").asFileHandle().read("json");return r.text=r.name,r.path=s,r.filename=r.pkgname,r.type="app",r.mime="antos/app",r.icon&&(r.icon=`${r.path}/${r.icon}`),r.iconclass||r.icon||(r.iconclass="fa fa-adn"),this.logger.info(__("Installing...")),t.setting.system.packages[r.pkgname]=r,r.app?(this.logger.info(__("Running {0}...",r.app)),t.GUI.forceLaunch(r.app,[])):this.logger.error(__("{0} is not an application",r.pkgname)),e(void 0)}catch(t){s(t)}}):s.worker.submit(e,i,this.root,this.logger)}batch(t,e){return e.root&&(this.root=e.root),new Promise(async(i,s)=>{try{e.targets||s("No target found");for(const i of t){const t=e.targets[i];if(!t)return s(__("No target: {0}",i));if(t.depend&&await this.batch(t.depend,e),t.require&&await this.require(t.require),this.logger&&this.logger.info(__("### RUNNING STAGE: {0}###",i).__()),t.jobs)for(const e of t.jobs)await this.run(e.name,e.data)}i(void 0)}catch(t){s(t)}})}}let r;e.AntOSDKBuilder=s,function(t){class e extends t.RemoteFileHandle{constructor(t){super(t);const e="pkg://libantosdk/"+this.genealogy.join("/");this.setPath(e.asFileHandle().path)}}t.SDKFileHandle=e,t.register("^sdk$",e)}(r=e.VFS||(e.VFS={}))}(e=t.API||(t.API={}))}(OS||(OS={})),function(t){let e;!function(e){class i{constructor(t){this.target=t}info(t){this.log("info",t,!0)}warn(t){this.log("warn",t,!0)}error(t){this.log("error",t,!0)}log(t,e,i){let s=$("<pre></pre>").attr("class","sdk-log-"+t);if(i){let t=new Date,i=t.getDate()+"/"+(t.getMonth()+1)+"/"+t.getFullYear()+" "+t.getHours()+":"+t.getMinutes()+":"+t.getSeconds();s.text(`[${i}]: ${e.__()}`)}else s.text(e.__());$(this.target).append(s),$(this.target).scrollTop($(this.target)[0].scrollHeight)}print(t){t.match(/warn/i)?this.log("warn",t,!1):t.match(/error/i)?this.log("error",t,!1):this.log("info",t,!1)}clear(){$(this.target).empty()}}class s extends e.BaseApplication{constructor(t){super("libantosdk",t)}main(){this.logger=new i(this.find("container")),this.sdk=new t.API.AntOSDKBuilder(this.logger,""),this.filehandle=void 0,this.options=void 0,this.targets=this.find("target-list"),this.args&&this.args.length>0&&(this.filehandle=this.args[0].path.asFileHandle()),this.find("btnbuild").onbtclick=t=>{const e=this.targets.selectedItem;e&&this.load(this.compile([e.data.text]))},this.find("btnclear").onbtclick=t=>{this.logger.clear()},this.find("btnrefresh").onbtclick=t=>{this.open()},this.find("btnopen").onbtclick=async t=>{try{const t=await this.openDialog("FileDialog",{title:__("Select build file"),mimes:this.meta().mimes});this.filehandle=t.file.path.asFileHandle(),this.open()}catch(t){this.logger.error(t.toString())}},this.open()}open(){void 0!==this.filehandle&&this.filehandle.read("json").then(t=>{if(!t.targets)return this.logger.error(__("Invalid build file: {0}",this.filehandle.path));const e=Object.keys(t.targets).map(t=>({text:t}));this.scheme.apptitle=this.filehandle.path,this.options=t,this.options.root=this.filehandle.parent().path,this.targets.data=e,this.logger.info(__("Loaded: {0}",this.filehandle.path))}).catch(t=>this.logger.error(__("Unable to load build file: {0}: {1}",this.filehandle.path,t.toString())))}compile(t){return new Promise(async(e,i)=>{try{this.logger.clear(),await this.sdk.batch(t,this.options),e("OK")}catch(t){i(__e(t))}})}}e.libantosdk=s}(e=t.application||(t.application={}))}(OS||(OS={}));

View File

@ -1,25 +1,33 @@
{
"pkgname": "libantosdk",
"name": "AntOSDK",
"name": "AntOS SDK builder",
"app": "libantosdk",
"description": "AntOS Software Development Kit",
"info": {
"author": "Xuan Sang LE",
"email": "mrsang@iohub.dev"
},
"version": "0.0.5-a",
"category": "Other",
"version": "0.0.6-a",
"category": "Development",
"iconclass": "fa fa-cog",
"mimes": [
"none"
"application/json"
],
"dependencies": [],
"locale": {
"en_GB": {
"Select build file": "Select build file",
"Invalid build file: {0}": "Invalid build file: {0}",
"Loaded: {0}": "Loaded: {0}",
"Unable to load build file: {0}: {1}": "Unable to load build file: {0}: {1}",
"Installing...": "Installing...",
"Running {0}...": "Running {0}...",
"{0} is not an application": "{0} is not an application",
"No target: {0}": "No target: {0}",
"### RUNNING STAGE: {0}###": "### RUNNING STAGE: {0}###"
"### RUNNING STAGE: {0}###": "### RUNNING STAGE: {0}###",
"AntOSDK Builder": "AntOSDK Builder",
"Run": "Run",
"Clear log": "Clear log"
}
}
}

View File

@ -1,25 +1,33 @@
{
"pkgname": "libantosdk",
"name": "AntOSDK",
"name": "AntOS SDK builder",
"app": "libantosdk",
"description": "AntOS Software Development Kit",
"info": {
"author": "Xuan Sang LE",
"email": "mrsang@iohub.dev"
},
"version": "0.0.5-a",
"category": "Other",
"version": "0.0.6-a",
"category": "Development",
"iconclass": "fa fa-cog",
"mimes": [
"none"
"application/json"
],
"dependencies": [],
"locale": {
"en_GB": {
"Select build file": "Select build file",
"Invalid build file: {0}": "Invalid build file: {0}",
"Loaded: {0}": "Loaded: {0}",
"Unable to load build file: {0}: {1}": "Unable to load build file: {0}: {1}",
"Installing...": "Installing...",
"Running {0}...": "Running {0}...",
"{0} is not an application": "{0} is not an application",
"No target: {0}": "No target: {0}",
"### RUNNING STAGE: {0}###": "### RUNNING STAGE: {0}###"
"### RUNNING STAGE: {0}###": "### RUNNING STAGE: {0}###",
"AntOSDK Builder": "AntOSDK Builder",
"Run": "Run",
"Clear log": "Clear log"
}
}
}

View File

@ -1,8 +1,8 @@
{
"name": "libantosdk",
"css": [],
"css": ["main.css"],
"javascripts": [],
"coffees": [],
"ts": ["ts/main.ts", "ts/test.ts"],
"ts": ["ts/main.ts", "ts/app.ts"],
"copies": ["core","package.json","scheme.html", "README.md"]
}

View File

@ -1,16 +1,30 @@
<afx-app-window apptitle="__(Test SDK)" width="450" height="500" data-id="TestSDK">
<afx-vbox >
<div data-height="10"></div>
<afx-hbox data-id="wrapper">
<div data-width="10"></div>
<div data-id="container"></div>
<div data-width="10"></div>
</afx-hbox>
<div data-height="5"></div>
<afx-hbox data-height="23" style="text-align: right;">
<afx-button data-id="btnsend" text="__(Send)"></afx-button>
<div data-width="5"></div>
</afx-hbox>
<div data-height="10"></div>
</afx-vbox>
<afx-app-window apptitle="__(AntOSDK Builder)" width="600" height="500" data-id="SDKBuilder">
<afx-hbox>
<afx-vbox data-width="150">
<div data-height="10"></div>
<afx-list-view data-id="target-list"></afx-list-view>
<div data-height="5"></div>
<afx-hbox data-height="23" style="text-align: left;">
<afx-button data-id="btnopen" data-width="25" iconclass ="bi bi-file-arrow-up-fill"></afx-button>
<afx-button data-id="btnrefresh" data-width="25" iconclass ="fa fa-refresh"></afx-button>
<afx-button data-id="btnbuild" text="__(Run)"></afx-button>
<div data-width="5"></div>
</afx-hbox>
<div data-height="10"></div>
</afx-vbox>
<afx-resizer data-width="3"></afx-resizer>
<afx-vbox data-id="right-pannel">
<div data-height="10"></div>
<afx-hbox data-id="wrapper">
<div data-width="10"></div>
<div data-id="container"></div>
</afx-hbox>
<div data-height="5"></div>
<afx-hbox data-height="23" style="text-align: right;">
<afx-button data-id="btnclear" iconclass="fa fa-trash" text="__(Clear log)"></afx-button>
<div data-width="5"></div>
</afx-hbox>
<div data-height="10"></div>
</afx-vbox>
</afx-hbox>
</afx-app-window>

View File

@ -1,47 +0,0 @@
namespace OS {
export namespace application {
/**
*
* @class libantosdk
* @extends {BaseApplication}
*/
export class libantosdk extends BaseApplication {
private sdk: API.AntOSDKBuilder;
constructor(args: AppArgumentsType[]) {
super("libantosdk", args);
}
main(): void {
this.sdk = new API.AntOSDKBuilder(
{
info: (d) => console.log(d),
error: (d) => console.error(d)
},
"home://workspace/antosdk-apps/libantosdk");
(this.find("btnsend") as GUI.tag.ButtonTag).onbtclick = (e) => {
this.openDialog("PromptDialog", {
label: "Stages",
value: "build,uglify,copy"
}).then(v => {
this.load(this.compile(v.split(",")));
})
}
}
compile(stages): Promise<string> {
return new Promise( async (resolve, reject) => {
try {
const options = await "home://workspace/antosdk-apps/libantosdk/build.json".asFileHandle().read("json");
await this.sdk.batch(stages,options);
resolve("OK");
}
catch(e)
{
reject(__e(e));
}
})
}
}
}
}

View File

@ -191,11 +191,11 @@
},
{
"pkgname": "libantosdk",
"name": "AntOSDK",
"name": "AntOS SDK builder",
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libantosdk/README.md",
"category": "Other",
"category": "Development",
"author": "Xuan Sang LE",
"version": "0.0.5-a",
"version": "0.0.6-a",
"dependencies": [],
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libantosdk/build/release/libantosdk.zip"
},