Commit 49c13820 authored by A's avatar A

add exec app

parent 00f50907
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</div> </div>
</div> </div>
<div *ngIf="isInstalled"> <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 type="button" class="btn btn-secondary">设置</button>
<button (click)="openDir(routingService.app)" 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> <button type="button" class="btn btn-secondary">联机</button>
......
...@@ -14,7 +14,10 @@ declare var $; ...@@ -14,7 +14,10 @@ declare var $;
export class AppDetailComponent { export class AppDetailComponent {
platform = process.platform; platform = process.platform;
fs = window['System']._nodeRequire('fs');
electron = window['System']._nodeRequire('electron'); electron = window['System']._nodeRequire('electron');
spawn = window['System']._nodeRequire('child_process').spawn;
path = window['System']._nodeRequire('path');
constructor(private appsService: AppsService, private routingService: RoutingService ) { constructor(private appsService: AppsService, private routingService: RoutingService ) {
} }
...@@ -58,7 +61,7 @@ export class AppDetailComponent { ...@@ -58,7 +61,7 @@ export class AppDetailComponent {
_mods; _mods;
get mods() { get mods() {
let contains = ["optional", "language"]; let contains = ["optional", "language", "emulator"];
if(this.currentApp) { if(this.currentApp) {
if(this.currentApp.references[process.platform] && this.currentApp.references[process.platform].length > 0) { if(this.currentApp.references[process.platform] && this.currentApp.references[process.platform].length > 0) {
...@@ -137,13 +140,51 @@ export class AppDetailComponent { ...@@ -137,13 +140,51 @@ export class AppDetailComponent {
return dir[0]; return dir[0];
} }
openDir(id) { openDir(id) {
this.appsService.data.map((v)=>{ this.electron.remote.shell.showItemInFolder(this.searchApp(id).local.path);
if(v.id == id) { }
this.electron.remote.shell.showItemInFolder(v.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 { ...@@ -37,7 +37,6 @@ export class AppsService {
mkdirp = window['System']._nodeRequire('mkdirp'); mkdirp = window['System']._nodeRequire('mkdirp');
electron = window['System']._nodeRequire('electron'); electron = window['System']._nodeRequire('electron');
Aria2 = window['System']._nodeRequire('aria2'); Aria2 = window['System']._nodeRequire('aria2');
spawn = window['System']._nodeRequire('child_process');
execFile = window['System']._nodeRequire('child_process').execFile; execFile = window['System']._nodeRequire('child_process').execFile;
//localStorage = window['localStorage']; //localStorage = window['localStorage'];
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
"actions": { "actions": {
"darwin": { "darwin": {
"main": { "main": {
"execute": "", "execute": "th13.exe",
"args": [], "args": [],
"env": "", "env": {"LC_ALL": "ja_JP"},
"open": "" "open": "wine"
} }
} }
}, },
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
"type": "language" "type": "language"
}, },
{ {
"id": "th12_mod2", "id": "wine",
"type": "runtime" "type": "emulator"
} }
] ]
}, },
...@@ -90,10 +90,6 @@ ...@@ -90,10 +90,6 @@
{ {
"id": "th12_mod1", "id": "th12_mod1",
"type": "language" "type": "language"
},
{
"id": "th12_mod2",
"type": "runtime"
} }
] ]
}, },
...@@ -146,20 +142,20 @@ ...@@ -146,20 +142,20 @@
} }
}, },
{ {
"id": "th12_mod2", "id": "wine",
"name": { "name": {
"zh-CN": "th12_mod2" "zh-CN": "wine"
}, },
"description": { "description": {
"zh-CN": "th12 desc" "zh-CN": "th12 desc"
}, },
"author": "ZUN", "author": "ZUN",
"homepage": "http://www.myacg.cc", "homepage": "http://www.myacg.cc",
"category": "runtime", "category": "emulator",
"actions": { "actions": {
"darwin": { "darwin": {
"main": { "main": {
"execute": "", "execute": "wine",
"args": [], "args": [],
"env": "", "env": "",
"open": "" "open": ""
...@@ -176,8 +172,8 @@ ...@@ -176,8 +172,8 @@
"STG" "STG"
], ],
"local": { "local": {
"path": "/foo/bar", "path": "/usr/local/bin",
"version": "10.3" "version": "1.8"
} }
}, },
{ {
...@@ -227,9 +223,9 @@ ...@@ -227,9 +223,9 @@
} }
}, },
{ {
"id": "th07", "id": "sublime",
"name": { "name": {
"zh-CN": "东方绯想天" "zh-CN": "sublime"
}, },
"description": { "description": {
"zh-CN": "fxt desc" "zh-CN": "fxt desc"
...@@ -240,7 +236,7 @@ ...@@ -240,7 +236,7 @@
"actions": { "actions": {
"darwin": { "darwin": {
"main": { "main": {
"execute": "", "execute": "Sublime Text",
"args": [], "args": [],
"env": "", "env": "",
"open": "" "open": ""
...@@ -268,7 +264,7 @@ ...@@ -268,7 +264,7 @@
"game" "game"
], ],
"local": { "local": {
"path": "", "path": "/Applications/Sublime Text.app/Contents/MacOS",
"version": "" "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