Skip to content

Commit

Permalink
正在尝试逐步修改插件注入方式
Browse files Browse the repository at this point in the history
  • Loading branch information
iamapig120 committed Jan 21, 2019
1 parent 9f7d274 commit 220f0be
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 2 deletions.
38 changes: 38 additions & 0 deletions bin/main/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="zh-hans">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>雀魂Plus</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
overflow: hidden;
width: 100vw;
height: 100vh;
}
#mainWindow {
overflow: hidden;
width: 100%;
height: 100%;
}
#mainWindowBox {
overflow: hidden;
display: block;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="mainWindowBox">
<webview id="mainWindow" src="./loading,html"></webview>
</div>
<script src="./mainLoader.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions bin/main/loading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="zh-hans">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>雀魂Plus</title>
<style>
body {
height: 100vh;
width: 100vw;
overflow: hidden;
background-color: #000;
background-image: url('./logo.svg');
background-size: cover;
background-repeat: no-repeat;
}
</style>
</head>
<body></body>
</html>
21 changes: 21 additions & 0 deletions bin/main/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions bin/main/mainLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*eslint no-console: ["error", { allow: ["warn", "error"] }] */

const electron = require('electron')
const { ipcRenderer } = electron

/**
* @type {Electron.WebviewTag}
*/
const mainWindow = document.getElementById('mainWindow')

/**
* @type {HTMLDivElement}
*/
const mainWindowBox = document.getElementById('mainWindowBox')

const scalePercent = 400

ipcRenderer.on('load-url', (event, ...args) => {
const url = args[0]
console.warn('LoadURL', url)
mainWindow.loadURL(url)
mainWindowBox.style.width = '100%'
mainWindowBox.style.height = '100%'
mainWindowBox.style.transform = 'none'
})

let webContents
mainWindow.addEventListener('dom-ready', () => {
if (!webContents) {
webContents = mainWindow.getWebContents()
ipcRenderer.send('main-loader-message', 'main-loader-ready')

if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools({ mode: 'detach' })
}
}
mainWindowBox.style.width = `${scalePercent}vw`
mainWindowBox.style.height = `${scalePercent}vh`
mainWindowBox.style.transform = `scale(${100 /
scalePercent}) translate(${(100 - scalePercent) / 2}%, ${(100 -
scalePercent) /
2}%)`
})
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ const windowControl = {
console.warn('Console', msg)
}
})
gameWindow.loadURL(`https://localhost:${sererHttps.address().port}/0/`)
// gameWindow.loadURL(`https://localhost:${sererHttps.address().port}/0/`)
gameWindow.loadURL('file://' + path.join(__dirname, 'bin/main/index.html'))

// Add environment config to open developer tools
if (process.env.NODE_ENV === 'development') {
Expand Down Expand Up @@ -382,6 +383,13 @@ const windowControl = {
windowControl.windowMap['game'] = gameWindow
},

mainLoaderReady(){
windowControl.windowMap['game'].webContents.send(
'load-url',
`https://localhost:${sererHttps.address().port}/0/`
)
},

closeManagerWindow: () => {
const managerWindow = windowControl.windowMap['manager']
managerWindow && managerWindow.close()
Expand Down Expand Up @@ -454,7 +462,18 @@ const windowControl = {
),
buffer
)

break
}
default:
break
}
}
})
ipcMain.on('main-loader-message', (evt, ...args) => {
if (args && args.length > 0) {
switch (args[0]) {
case 'main-loader-ready': {
windowControl.mainLoaderReady()
break
}
default:
Expand Down

0 comments on commit 220f0be

Please sign in to comment.