Commit 0a5ddc82 authored by 神楽坂玲奈's avatar 神楽坂玲奈

optimize import

parent ee74a9a4
<h1>{{appsService.currentApp.name}}</h1>
<div *ngIf="!isInstalled">
<div *ngIf="!appsService.getDownloadInfo(appsService.currentApp)">
<button type="button" (click)="updateInstallConfig()" class="btn btn-primary" data-toggle="modal"
data-target="#install-modal">安装
<button type="button" (click)="updateInstallConfig()" class="btn btn-primary" data-toggle="modal" data-target="#install-modal">安装
</button>
<button type="button" class="btn btn-secondary">导入</button>
<!--<button type="button" class="btn btn-secondary">正版代购</button>-->
......@@ -10,10 +9,7 @@
<div *ngIf="appsService.getDownloadInfo(appsService.currentApp)">
<div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'install'">正在安装...</div>
<div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'wait'">等待安装...</div>
<progress *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'active'"
class="progress progress-striped progress-animated"
value="{{appsService.getDownloadInfo(appsService.currentApp).progress}}" max="100">
</progress>
<progress *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'active'" class="progress progress-striped progress-animated" value="{{appsService.getDownloadInfo(appsService.currentApp).progress}}" max="100"></progress>
</div>
</div>
<div *ngIf="isInstalled && (appsService.currentApp.id != 'ygopro')">
......@@ -23,7 +19,7 @@
<div id="network" *ngIf="appsService.currentApp.network && appsService.currentApp.network.protocol == 'maotama'">
<div class="input-group">
<input *ngIf="appsService.connections.get(appsService.currentApp)" [value]="appsService.connections.get(appsService.currentApp).address || 'Loading...'" readonly type="text" class="form-control" aria-label="Text input with dropdown button">
<input *ngIf="appsService.connections.get(appsService.currentApp)" [value]="appsService.connections.get(appsService.currentApp).address || 'Loading...'" readonly type="text" class="form-control" aria-label="Text input with dropdown button" title="address">
<div class="input-group-btn">
<button *ngIf="!appsService.connections.get(appsService.currentApp)" (click)="appsService.network(appsService.currentApp, appsService.currentApp.network.servers[0])" type="button" class="btn btn-secondary">
联机
......@@ -31,14 +27,12 @@
<button *ngIf="appsService.connections.get(appsService.currentApp)" (click)="copy(appsService.connections.get(appsService.currentApp).address)" [disabled]="!appsService.connections.get(appsService.currentApp).address" type="button" class="btn btn-secondary">
复制
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="height: 38px;">
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="height: 38px;">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu" [class.dropdown-menu-right]="appsService.connections.get(appsService.currentApp)">
<h6 class="dropdown-header">选择服务器</h6>
<a *ngFor="let server of appsService.currentApp.network.servers"
(click)="appsService.network(appsService.currentApp, server)" class="dropdown-item" href="#">{{server.id}}</a>
<a *ngFor="let server of appsService.currentApp.network.servers" (click)="appsService.network(appsService.currentApp, server)" class="dropdown-item" href="#">{{server.id}}</a>
</div>
</div>
</div>
......@@ -88,13 +82,9 @@
<button type="button" class="btn btn-danger btn-sm">卸载</button>
</td>
<td *ngIf="!checkInstall(mod.id)">
<button *ngIf="!appsService.getDownloadInfo(mod.id)" (click)="install(mod.id)" type="button"
class="btn btn-primary btn-sm">安装
<button *ngIf="!appsService.getDownloadInfo(mod.id)" (click)="install(mod.id)" type="button" class="btn btn-primary btn-sm">安装
</button>
<progress
*ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'active'"
class="progress progress-striped progress-animated"
value="{{appsService.getDownloadInfo(mod.id).progress}}" max="100"></progress>
<progress *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'active'" class="progress progress-striped progress-animated" value="{{appsService.getDownloadInfo(mod.id).progress}}" max="100"></progress>
<div *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'wait'">
等待安装...
</div>
......@@ -117,26 +107,19 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">{{'settings'|translate}}</h4>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#general">
{{'general'|translate}}
</a>
<a class="nav-link active" data-toggle="tab" href="#general"> {{'general'|translate}} </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#updates">
{{'updates'|translate}}
</a>
<a class="nav-link" data-toggle="tab" href="#updates"> {{'updates'|translate}} </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#local-files">
{{'local files'|translate}}
</a>
<a class="nav-link" data-toggle="tab" href="#local-files"> {{'local files'|translate}} </a>
</li>
</ul>
</div>
......@@ -164,10 +147,8 @@
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true" *ngIf="installConfig">
</div><!-- Modal -->
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" *ngIf="installConfig">
<div class="modal-dialog" role="document">
<form id="install-form" class="modal-content" (ngSubmit)="install()" #theForm="ngForm">
<div class="modal-header">
......@@ -181,7 +162,7 @@
<!-- 安装位置选择只在 windows 下存在, 为了方便调试暂时不加ngif -->
<h4>{{'install_path'|translate}}</h4>
<div class="form-group">
<select class="form-control" name="installPath" [(ngModel)]="installConfig.installPath">
<select class="form-control" name="installPath" [(ngModel)]="installConfig.installPath" title="path">
<option *ngFor="let library of settingsService.getLibraries()" value="{{library['path']}}">
{{ library['path']}}
</option>
......@@ -190,22 +171,18 @@
<h4>{{'shortcut'|translate}}</h4>
<div class="checkbox">
<label>
<input type="checkbox" name="application" [(ngModel)]="installConfig.createShortcut">
{{'create_shortcut'|translate}}
<input type="checkbox" name="application" [(ngModel)]="installConfig.createShortcut"> {{'create_shortcut'|translate}}
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="desktop" [(ngModel)]="installConfig.createDesktopShortcut">
{{'create_desktop_shortcut'|translate}}
<input type="checkbox" name="desktop" [(ngModel)]="installConfig.createDesktopShortcut"> {{'create_desktop_shortcut'|translate}}
</label>
</div>
<h4>{{'additions'|translate}}</h4>
<div *ngFor="let reference of installConfig.references">
<label>
<input type="checkbox" [(ngModel)]="reference.id" name="references"
value="{{reference.id}}">
{{reference.name}}
<input type="checkbox" [(ngModel)]="reference.id" name="references" value="{{reference.id}}"> {{reference.name}}
</label>
</div>
</div>
......
......@@ -4,31 +4,12 @@ import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices";
import {App} from "./app";
import {DownloadService} from "./download.service";
import {clipboard, remote} from "electron";
import * as path from "path";
import * as child_process from "child_process";
declare var System;
declare var $;
import * as readline from 'readline';
import * as os from 'os';
import {clipboard, remote} from 'electron';
const sudo = new (System._nodeRequire('electron-sudo').default)({name: 'MyCard'});
sudo.fork = function (modulePath, args, options) {
return sudo.spawn(remote.app.getPath('exe'), ['-e', modulePath]).then((child)=> {
readline.createInterface({input: child.stdout}).on('line', (line) => {
child.emit('message', JSON.parse(line));
});
child.send = (message, sendHandle, options, callback)=> {
child.stdin.write(JSON.stringify(message) + os.EOL);
if (callback) {
callback()
}
};
return child
})
};
@Component({
selector: 'app-detail',
templateUrl: 'app/app-detail.component.html',
......@@ -37,12 +18,6 @@ sudo.fork = function (modulePath, args, options) {
})
export class AppDetailComponent implements OnInit {
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');
installConfig: InstallConfig;
constructor(private appsService: AppsService, private settingsService: SettingsService,
......@@ -146,7 +121,7 @@ export class AppDetailComponent implements OnInit {
}
startApp(app: App) {
let execute = this.path.join(app.local.path, app.actions.get("main").execute);
let execute = path.join(app.local.path, app.actions.get("main").execute);
let args = app.actions.get("main").args;
let env = app.actions.get("main").env;
let opt = {
......@@ -158,7 +133,7 @@ export class AppDetailComponent implements OnInit {
let openApp = app.actions.get("main").open;
if (openApp) {
if (this.isInstalled) {
open = this.path.join(openApp.local.path, openApp.actions.get("main").execute);
open = path.join(openApp.local.path, openApp.actions.get("main").execute);
args.push(execute);
} else {
console.error('open app not found');
......@@ -168,7 +143,7 @@ export class AppDetailComponent implements OnInit {
open = execute;
}
let handle = this.spawn(open, args, opt);
let handle = child_process.spawn(open, args, opt);
handle.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
......
......@@ -3,20 +3,19 @@ import {Http} from "@angular/http";
import {App} from "./app";
import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices";
declare var process;
declare var System;
const os = System._nodeRequire('os');
const fs = System._nodeRequire('fs');
const path = System._nodeRequire('path');
const readline = System._nodeRequire('readline');
const mkdirp = System._nodeRequire('mkdirp');
const electron = System._nodeRequire('electron');
const Aria2 = System._nodeRequire('aria2');
const execFile = System._nodeRequire('child_process').execFile;
const sudo = new (System._nodeRequire('electron-sudo').default)({name: 'MyCard'});
sudo.fork = function (modulePath, args, options) {
return sudo.spawn(electron.remote.app.getPath('exe'), ['-e', modulePath]).then((child)=> {
import * as os from "os";
import * as fs from "fs";
import * as path from "path";
import * as readline from "readline";
import * as mkdirp from "mkdirp";
import * as child_process from "child_process";
import {remote} from "electron";
const Aria2 = require('aria2');
const Sudo = require('electron-sudo').default;
Sudo.prototype.fork = function (modulePath, args, options) {
return this.spawn(remote.app.getPath('exe'), ['-e', modulePath].concat(args), options).then((child)=> {
readline.createInterface({input: child.stdout}).on('line', (line) => {
child.emit('message', JSON.parse(line));
});
......@@ -30,8 +29,6 @@ sudo.fork = function (modulePath, args, options) {
})
};
//const sudo = System._nodeRequire('sudo-prompt');
@Injectable()
export class AppsService {
......@@ -101,7 +98,7 @@ export class AppsService {
xzFile: res.files[0].path,
installDir: this.installConfig.installPath
};
let promise = new Promise((resolve, reject)=> {
new Promise((resolve)=> {
let refs = this.searchApp(this.downloadsInfo[index].id).references;
console.log(refs);
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
......@@ -127,7 +124,7 @@ export class AppsService {
// }
// });
// }
console.log("wait obj:", waitObj);
//console.log("wait obj:", waitObj);
if (waitObj) {
this.waitInstallQueue.push(waitObj);
......@@ -148,16 +145,16 @@ export class AppsService {
}
});
};
this._aria2.onmessage = (m)=> {
//console.log('IN:', m);
//console.log('download infoi:', this.downloadsInfo);
//this._aria2.onmessage = (m)=> {
//console.log('IN:', m);
//console.log('download infoi:', this.downloadsInfo);
}
//}
}
if (!this.aria2IsOpen) {
this._aria2.open().then(()=> {
console.log('aria2 websocket open')
console.log('aria2 websocket open');
this.aria2IsOpen = true;
});
}
......@@ -166,9 +163,9 @@ export class AppsService {
}
_download_dir;
//_download_dir;
get download_dir() {
const dir = path.join(electron.remote.app.getAppPath(), 'cache');
const dir = path.join(remote.app.getAppPath(), 'cache');
if (!fs.existsSync(dir)) {
console.log('cache not exists');
......@@ -189,7 +186,7 @@ export class AppsService {
.map(response => {
let apps = response.json();
let localAppData = JSON.parse(localStorage.getItem("localAppData"));
apps = apps.map((app)=> {
apps = apps.map((app: any)=> {
if (localAppData) {
localAppData.map((v)=> {
if (v.id === app.id) {
......@@ -252,7 +249,7 @@ export class AppsService {
// 设置App关系
for (let id of Array.from(apps.keys())) {
let temp = apps.get(id)["actions"]
let temp = apps.get(id)["actions"];
let map = new Map<string,any>();
for (let action of Object.keys(temp)) {
let openId = temp[action]["open"];
......@@ -312,7 +309,7 @@ export class AppsService {
}
uninstall(id: string) {
let current = this;
//let current = this;
if (this.checkInstall(id)) {
let files: string[] = this.searchApp(id).local.files.sort().reverse();
// 删除本目录
......@@ -362,7 +359,7 @@ export class AppsService {
getInstallConfig(app: App): InstallConfig {
let id = app.id;
//let id = app.id;
this.installConfig = new InstallConfig(app);
let platform = process.platform;
let references: InstallConfig[] = [];
......@@ -440,7 +437,7 @@ export class AppsService {
});
}
let tar = execFile(tarPath, ['xvf', xzFile, '-C', installDir], opt, (err, stdout, stderr)=> {
let tar = child_process.execFile(tarPath, ['xvf', xzFile, '-C', installDir], opt, (err, stdout, stderr)=> {
if (err) {
throw err;
}
......@@ -494,11 +491,7 @@ export class AppsService {
}
});
this.waitInstallQueue = this.waitInstallQueue.filter((waitObj)=> {
if (waitObj) {
return true;
} else {
return false;
}
return waitObj
});
console.log(tmp);
......@@ -511,15 +504,8 @@ export class AppsService {
}
isEmptyObject(e) {
let t;
for (t in e)
return !1;
return !0
}
browse(app: App) {
electron.remote.shell.showItemInFolder(app.local.path);
remote.shell.showItemInFolder(app.local.path);
}
connections = new Map<App, {connection: WebSocket, address: string}>();
......@@ -527,7 +513,7 @@ export class AppsService {
network(app: App, server) {
if (!this.maotama) {
this.maotama = sudo.fork('maotama')
this.maotama = new Sudo({name: 'MyCard'}).fork('maotama')
}
this.maotama.then((child)=> {
let connection = this.connections.get(app);
......
......@@ -3,10 +3,9 @@
*/
import {Component} from "@angular/core";
import {LoginService} from "./login.service";
declare var System;
const crypto = System._nodeRequire('crypto');
const querystring = System._nodeRequire('querystring');
const url = System._nodeRequire('url');
import * as crypto from "crypto";
import * as querystring from "querystring";
import * as url from "url";
@Component({
selector: 'login',
......
import {Component, Renderer} from "@angular/core";
import {TranslateService} from "ng2-translate";
import {LoginService} from "./login.service";
const electron = System._nodeRequire('electron');
declare var process;
declare var System;
import {remote} from "electron";
@Component({
selector: 'mycard',
......@@ -18,7 +14,7 @@ export class MyCardComponent {
platform = process.platform;
constructor(private renderer: Renderer, private translate: TranslateService, private loginService: LoginService) {
constructor(private renderer: Renderer, private translate: TranslateService) {
renderer.listenGlobal('window', 'message', (event) => {
console.log(event);
// Do something with 'event'
......@@ -28,12 +24,12 @@ export class MyCardComponent {
translate.setDefaultLang('en-US');
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use(electron.remote.app.getLocale());
translate.use(remote.app.getLocale());
}
refresh() {
electron.remote.getCurrentWindow().reload()
remote.getCurrentWindow().reload()
}
}
......@@ -3,19 +3,16 @@
*/
import {Component, OnInit, ChangeDetectorRef} from "@angular/core";
import {AppsService} from "./apps.service";
import * as fs from "fs";
import * as path from "path";
import * as crypto from "crypto";
import * as child_process from "child_process";
import {remote} from "electron";
import * as ini from "ini";
import {EncodeOptions} from "ini";
declare var process;
declare var System;
declare var $;
const fs = System._nodeRequire('fs');
const path = System._nodeRequire('path');
const crypto = System._nodeRequire('crypto');
const child_process = System._nodeRequire('child_process');
const ini = System._nodeRequire('ini');
const electron = System._nodeRequire('electron');
@Component({
selector: 'ygopro',
templateUrl: 'app/ygopro.component.html',
......@@ -170,7 +167,7 @@ export class YGOProComponent implements OnInit {
save_system_conf = (data) => {
return new Promise((resolve, reject)=> {
fs.writeFile(this.system_conf, ini.stringify(data, {whitespace: true}), (error) => {
fs.writeFile(this.system_conf, ini.stringify(data, <EncodeOptions>{whitespace: true}), (error) => {
if (error) return reject(error);
resolve(data);
});
......@@ -186,7 +183,7 @@ export class YGOProComponent implements OnInit {
data['lastport'] = server.port;
data['roompass'] = name;
data['nickname'] = this.user.username;
console.log(data)
console.log(data);
return data
})
.then(this.save_system_conf)
......@@ -200,10 +197,10 @@ export class YGOProComponent implements OnInit {
}
start_game = (args) => {
let win = electron.remote.getCurrentWindow();
let win = remote.getCurrentWindow();
win.minimize();
return new Promise((resolve, reject)=> {
let child = child_process.spawn(path.join(this.app.local.path, this.app.actions[process.platform]['main']['execute']), args, {cwd: this.app.local.path});
let child = child_process.spawn(path.join(this.app.local.path, this.app.actions.get('main').execute), args, {cwd: this.app.local.path});
child.on('error', (error)=> {
reject(error);
win.restore()
......@@ -235,7 +232,7 @@ export class YGOProComponent implements OnInit {
}
let password = options_buffer.toString('base64') + options.title.replace(/\s/, String.fromCharCode(0xFEFF));
let room_id = crypto.createHash('md5').update(password + this.user.username).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_')
let room_id = crypto.createHash('md5').update(password + this.user.username).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_');
this.join(password, this.servers[0]);
}
......
......@@ -2,7 +2,6 @@
* System configuration for Angular 2 samples
* Adjust as necessary for your application needs.
*/
(function (global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
......@@ -11,8 +10,7 @@
'rxjs': 'node_modules/rxjs',
'ng2-translate': 'node_modules/ng2-translate/bundles/index.js',
"electron": "@node/electron",
"readline": "@node/readline",
"os":"@node/os"
"ini": "@node/ini",
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
......@@ -20,6 +18,12 @@
'rxjs': {defaultExtension: 'js'},
'angular2-in-memory-web-api': {main: 'index.js', defaultExtension: 'js'}
};
let builtin_modules = ["buffer", "querystring", "events", "http", "cluster", "zlib", "os", "https", "punycode", "repl", "readline", "vm", "child_process", "url", "dns", "net", "dgram", "fs", "path", "string_decoder", "tls", "crypto", "stream", "util", "assert", "tty", "domain", "constants", "process", "v8", "timers", "console"];
for (let mod of builtin_modules) {
map[mod] = `@node/${mod}`;
}
var ngPackageNames = [
'common',
'compiler',
......@@ -51,4 +55,3 @@
packages: packages
};
System.config(config);
})(this);
......@@ -2,7 +2,11 @@
"globalDependencies": {
"core-js": "registry:dt/core-js",
"electron/github-electron": "registry:dt/electron/github-electron",
"ini": "registry:dt/ini",
"jasmine": "registry:dt/jasmine",
"node": "registry:dt/node"
},
"dependencies": {
"mkdirp": "registry:npm/mkdirp"
}
}
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