Skip to content

Commit

Permalink
add default proxy in game window
Browse files Browse the repository at this point in the history
  • Loading branch information
biuuu committed May 12, 2018
1 parent 64efe3f commit 9e1876f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
12 changes: 11 additions & 1 deletion main/gameWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ module.exports = () => {
const ses = session.fromPartition('persist:gameWindow')
ses.setUserAgent('Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3071.115 Safari/537.36')

ipcMain.on('clear-game-window', (event, type) => {
if (type === 'cache') {
ses.clearCache(() => console.log('cache cleared'))
} else if (type === 'cookie') {
ses.clearStorageData({
storages: ['cookies']
}, () => console.log('cookies cleared'))
}
})

ipcMain.on('show-win-game', () => {
ses.setProxy({
pacScript: `http://127.0.0.1:${CONFIG.port}/pac`,
Expand Down Expand Up @@ -76,6 +86,6 @@ module.exports = () => {
gameWin = null
})

gameWin.loadURL('http://game.granbluefantasy.jp')
gameWin.loadURL('http://game.granbluefantasy.jp/#mypage')
})
}
12 changes: 12 additions & 0 deletions proxy/pac.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
const someHostList = [
'www.google.com',
'csp.withgoogle.com',
'www.gstatic.com'
]

module.exports = function ({ apiHostNames, staticHostNames, staticServer, frontAgent, port, frontAgentHost, frontAgentPort }) {
const condition1 = apiHostNames.map(name => {
return `shExpMatch(host, "${name}")`
}).join('||')
const condition2 = staticHostNames.map(name => {
return `shExpMatch(host, "${name}")`
}).join('||')
const condition3 = someHostList.map(name => {
return `shExpMatch(host, "${name}")`
}).join('||')

const getScript = (condition) => (conditionEx) => (result) => {
const template = `
function FindProxyForURL(url, host) {
if (${condition} || ${conditionEx}) {
return "PROXY 127.0.0.1:${port}; DIRECT";
}
if (!${frontAgent} && (${condition3})) {
return "PROXY 127.0.0.1:1080; PROXY 127.0.0.1:8094; PROXY 127.0.0.1:8099; DIRECT";
}
return "${result}";
}
`
Expand Down
9 changes: 8 additions & 1 deletion renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ <h3>碧蓝幻想翻译启动!</h3>
<el-dropdown-item command="static">静态文件目录</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-button icon="el-icon-mobile-phone" size="small" type="primary" @click="openGameWin" style="margin-left:8px">开始游戏</el-button>
<el-dropdown style="margin-left:8px" type="primary" @command="clearWhat" size="small" :split-button="true" @click="openGameWin">
<i class="el-icon-mobile-phone"></i>
开始游戏
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="cookie">清除Cookie</el-dropdown-item>
<el-dropdown-item command="cache">清除缓存</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<p>代理地址:<br>127.0.0.1:{{port}}(本机访问)
<br>{{ip}}:{{port}}(局域网其它设备)</p>
<p>查看代理监控:<a href="#" @click="openProxyWeb">http://localhost:{{webPort}}</a></p>
Expand Down
7 changes: 7 additions & 0 deletions renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ vueApp = new Vue({
this.openStaticFolder()
}
},
clearWhat (type) {
if (type === 'cache') {
ipcRenderer.send('clear-game-window', 'cache')
} else if (type === 'cookie') {
ipcRenderer.send('clear-game-window', 'cookie')
}
},
openGameWin () {
ipcRenderer.send('show-win-game')
},
Expand Down

0 comments on commit 9e1876f

Please sign in to comment.