Commit 49c13820 authored by A's avatar A

add exec app

parent 00f50907
......@@ -16,7 +16,7 @@
</div>
</div>
<div *ngIf="isInstalled">
<button type="button" class="btn btn-primary">运行</button>
<button (click)="startApp(routingService.app)" type="button" class="btn btn-primary">运行</button>
<button type="button" class="btn btn-secondary">设置</button>
<button (click)="openDir(routingService.app)" type="button" class="btn btn-secondary">游览本地文件</button>
<button type="button" class="btn btn-secondary">联机</button>
......
......@@ -14,7 +14,10 @@ declare var $;
export class AppDetailComponent {
platform = process.platform;
fs = window['System']._nodeRequire('fs');
electron = window['System']._nodeRequire('electron');
spawn = window['System']._nodeRequire('child_process').spawn;
path = window['System']._nodeRequire('path');
constructor(private appsService: AppsService, private routingService: RoutingService ) {
}
......@@ -58,7 +61,7 @@ export class AppDetailComponent {
_mods;
get mods() {
let contains = ["optional", "language"];
let contains = ["optional", "language", "emulator"];
if(this.currentApp) {
if(this.currentApp.references[process.platform] && this.currentApp.references[process.platform].length > 0) {
......@@ -137,13 +140,51 @@ export class AppDetailComponent {
return dir[0];
}
openDir(id) {
this.appsService.data.map((v)=>{
if(v.id == id) {
this.electron.remote.shell.showItemInFolder(v.local.path);
this.electron.remote.shell.showItemInFolder(this.searchApp(id).local.path);
}
startApp(id) {
let execute = this.path.join(this.searchApp(id).local.path, this.searchApp(id).actions[process.platform]["main"].execute);
let args = this.searchApp(id).actions[process.platform]["main"].args;
let env = this.searchApp(id).actions[process.platform]["main"].env;
let opt = {
env: env
};
let open = '';
let openId = this.searchApp(id).actions[process.platform]["main"].open;
if(openId) {
this.searchApp(openId).actions[process.platform]["main"].execute;
if(this.checkInstall(openId)) {
open = this.path.join(this.searchApp(openId).local.path, this.searchApp(openId).actions[process.platform]["main"].execute);
args.push(execute);
} else {
console.error('open app not found');
}
} else {
//没有需要通过open启动依赖,直接启动程序
open = execute;
}
let handle = this.spawn(open, args, opt);
handle.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
handle.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
handle.on('close', (code) => {
console.log(`child process exited with code ${code}`);
this.electron.remote.getCurrentWindow().restore();
});
this.electron.remote.getCurrentWindow().minimize();
}
}
......@@ -37,7 +37,6 @@ export class AppsService {
mkdirp = window['System']._nodeRequire('mkdirp');
electron = window['System']._nodeRequire('electron');
Aria2 = window['System']._nodeRequire('aria2');
spawn = window['System']._nodeRequire('child_process');
execFile = window['System']._nodeRequire('child_process').execFile;
//localStorage = window['localStorage'];
......
......@@ -13,10 +13,10 @@
"actions": {
"darwin": {
"main": {
"execute": "",
"execute": "th13.exe",
"args": [],
"env": "",
"open": ""
"env": {"LC_ALL": "ja_JP"},
"open": "wine"
}
}
},
......@@ -31,8 +31,8 @@
"type": "language"
},
{
"id": "th12_mod2",
"type": "runtime"
"id": "wine",
"type": "emulator"
}
]
},
......@@ -90,10 +90,6 @@
{
"id": "th12_mod1",
"type": "language"
},
{
"id": "th12_mod2",
"type": "runtime"
}
]
},
......@@ -146,20 +142,20 @@
}
},
{
"id": "th12_mod2",
"id": "wine",
"name": {
"zh-CN": "th12_mod2"
"zh-CN": "wine"
},
"description": {
"zh-CN": "th12 desc"
},
"author": "ZUN",
"homepage": "http://www.myacg.cc",
"category": "runtime",
"category": "emulator",
"actions": {
"darwin": {
"main": {
"execute": "",
"execute": "wine",
"args": [],
"env": "",
"open": ""
......@@ -176,8 +172,8 @@
"STG"
],
"local": {
"path": "/foo/bar",
"version": "10.3"
"path": "/usr/local/bin",
"version": "1.8"
}
},
{
......@@ -227,9 +223,9 @@
}
},
{
"id": "th07",
"id": "sublime",
"name": {
"zh-CN": "东方绯想天"
"zh-CN": "sublime"
},
"description": {
"zh-CN": "fxt desc"
......@@ -240,7 +236,7 @@
"actions": {
"darwin": {
"main": {
"execute": "",
"execute": "Sublime Text",
"args": [],
"env": "",
"open": ""
......@@ -268,7 +264,7 @@
"game"
],
"local": {
"path": "",
"path": "/Applications/Sublime Text.app/Contents/MacOS",
"version": ""
}
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment