Skip to content

Commit

Permalink
Merge pull request #25 from molingyu/master
Browse files Browse the repository at this point in the history
 fix mod install bug && publish new version
  • Loading branch information
Handle authored Feb 6, 2019
2 parents 56c1f99 + 7c1c11a commit cdcc4f7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 39 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ function jsonKeyUpdate (ja, jb) {
jsonKeyUpdate(userConfigs, require(path.join(__dirname, '/configs-user.json')))

userConfigs.userData.userLibPath = electronApp.getPath('userData')
const paths = [
configs.EXECUTES_DIR,
configs.MODS_DIR,
configs.TOOLS_DIR
]
paths.map(dir => path.join(userConfigs.userData.userLibPath, dir)).forEach(dir => !fs.existsSync(dir) && fs.mkdirSync(dir))
fs.writeFileSync(configs.USER_CONFIG_PATH, JSON.stringify(userConfigs))

if (userConfigs.chromium.isInProcessGpuOn) {
Expand Down
15 changes: 0 additions & 15 deletions jsonDiff.js

This file was deleted.

42 changes: 21 additions & 21 deletions manager/Ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,52 @@ const NetworkUtil = require('./Network')
const tcpPing = require('tcp-ping')

class Ping {
constructor() {
constructor () {
this.services = null
this.currentService = null
this.serviceList = []
this.interval = null
}

_getRandomUrl(url) {
_getRandomUrl (url) {
return `${url}?randv=${Math.random()
.toString()
.substring(2, 17)
.padStart(16, '0')}`
}

_getVersion() {
_getVersion () {
const url = this._getRandomUrl(
'https://majsoul.union-game.com/0/version.json'
)
return NetworkUtil.getJson(url).then(res => res.version)
}

_getResVersion(version) {
_getResVersion (version) {
const originUrl = `https://majsoul.union-game.com/0/resversion${version}.json`
const url = this._getRandomUrl(originUrl)
return NetworkUtil.getJson(url).then(res => res.res['config.json'].prefix)
}

_getConfig(prefix) {
_getConfig (prefix) {
const originUrl = `https://majsoul.union-game.com/0/${prefix}/config.json`
const url = this._getRandomUrl(originUrl)
return NetworkUtil.getJson(url).then(res => res.ip)
}

_saveServices(ips) {
_saveServices (ips) {
this.services = ips[0].region_urls
this.serviceList = Object.keys(this.services)
}

_getServices() {
_getServices () {
return this._getVersion()
.then(this._getResVersion)
.then(this._getConfig)
.then(this._saveServices)
}

_getService() {
_getService () {
if (!this.services) return Promise.reject(new Error('services is null'))
const choseService = localStorage.getItem('choseService')
if (choseService) {
Expand All @@ -60,7 +60,7 @@ class Ping {
return Promise.resolve()
}

_getServiceName(service) {
_getServiceName (service) {
const map = {
mainland: '中国大陆',
hk: '中国香港',
Expand All @@ -77,7 +77,7 @@ class Ping {
return map[service] || service
}

_getChildService() {
_getChildService () {
return new Promise((resolve, reject) => {
if (this.services) {
const originUrl = `${this.services[this.currentService]}`
Expand All @@ -95,13 +95,13 @@ class Ping {
})
}

_renderError(err) {
_renderError (err) {
console.error(err)
const serverTextDom = document.getElementById('serverText')
serverTextDom.innerText = '加载失败'
}

_renderService() {
_renderService () {
const serverTextDom = document.getElementById('serverText')
const pingInfoDom = document.getElementById('pingInfo')
const pingTextDom = document.getElementById('pingText')
Expand All @@ -111,14 +111,14 @@ class Ping {
return Promise.resolve()
}

_renderPing(time) {
_renderPing (time) {
const pingTextDom = document.getElementById('pingText')
const pingInfoDom = document.getElementById('pingInfo')
pingTextDom.innerText = time >> 0
pingInfoDom.className = time < 150 ? 'green' : time < 500 ? 'orange' : 'red'
}

_ping(service) {
_ping (service) {
return new Promise((resolve, reject) => {
const address = service.split(':')[0]
const port = service.split(':')[1]
Expand All @@ -139,7 +139,7 @@ class Ping {
})
}

_initPing() {
_initPing () {
this._getServices()
.then(this._getService)
.then(this._renderService)
Expand All @@ -148,43 +148,43 @@ class Ping {
.catch(console.error)
}

_getNextService() {
_getNextService () {
let index = this.serviceList.indexOf(this.currentService)
index = index > this.serviceList.length ? 0 : index + 1
this.currentService = this.serviceList[index]
localStorage.setItem('choseService', this.currentService)
return Promise.resolve()
}

_changeService() {
_changeService () {
this._getNextService()
.then(this._renderService)
.then(this._getChildService)
.then(this.ping)
.catch(console.error)
}

addEventListener() {
addEventListener () {
const serverInfoDom = document.getElementById('serverInfo')
serverInfoDom.addEventListener('click', this._changeService)
}

_refresh() {
_refresh () {
this._getService()
.then(this._renderService)
.then(this._getChildService)
.then(this.ping)
.catch(console.error)
}

ping(service) {
ping (service) {
clearInterval(this.interval)
this.interval = setInterval(() => {
this._ping(service).then(this._renderPing)
}, 5000)
}

init() {
init () {
this._initPing()
this.addEventListener()
}
Expand Down
5 changes: 3 additions & 2 deletions manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ const installResources = () => {
let installDir
switch (extname) {
case '.mspm':
installDir = executeRootDirs[1]
installDir = modRootDirs[1]
break
case '.mspe':
installDir = executeRootDirs[1]
Expand Down Expand Up @@ -1022,7 +1022,7 @@ const userConfigInit = () => {
{
const inputName = getKeyText(keyConfig)
const input = document.createElement('input')
input.type = 'button'
input.type = 'number'
const label = document.createElement('label')
input.id = 'config' + keyGroup + keyConfig + index
label.setAttribute('for', input.id)
Expand All @@ -1039,6 +1039,7 @@ const userConfigInit = () => {
break
case 'string': {
{
// TODO 待完成
}
break
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "majsoul-plus-client",
"version": "1.10.4-alpha.4",
"version": "1.10.4-alpha.5",
"productName": "Majsoul Plus",
"author": "MajsoulPlus Team",
"description": "Majsoul Plus",
Expand Down

0 comments on commit cdcc4f7

Please sign in to comment.