Skip to content

Commit

Permalink
[renderer] fix path problem
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Aug 15, 2018
1 parent dc04ff5 commit 628b488
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Webpack](https://img.shields.io/badge/dynamic/json.svg?label=webpack&url=https%3A%2F%2Fraw.githubusercontent.com%2Ftoyobayashi%2Fmishiro%2Fmaster%2Fapp%2Fpackage.json&query=%24.devDependencies.webpack&colorB=55a7dd)](https://webpack.js.org/) -->


[Release Download](https://github.com/toyobayashi/mishiro/releases) __(Windows Release Only)__
[Release Download](https://github.com/toyobayashi/mishiro/releases) __(Windows Release Only. Do not install mishiro in a path which includes Chinese or Japanese characters)__
[中文](https://github.com/toyobayashi/mishiro/blob/master/README_CN.md)


Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mishiro
[戳这里下载](https://github.com/toyobayashi/mishiro/releases) __(只提供Windwos的发布版,MacOS请按照下面的步骤和[Electron分发应用](http://electronjs.org/docs/tutorial/application-distribution)自行编译打包)__
[戳这里下载](https://github.com/toyobayashi/mishiro/releases) __(只提供Windwos的发布版,MacOS请按照下面的步骤和[Electron分发应用](http://electronjs.org/docs/tutorial/application-distribution)自行编译打包。请不要安装在有汉字的目录下__

## 用法

Expand Down
8 changes: 7 additions & 1 deletion app/script/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const renderer: webpack.Configuration = {
target: 'electron-renderer',
entry: {
'mishiro.renderer': path.join(__dirname, '../src/ts/renderer.ts'),
'mishiro.live': path.join(__dirname, '../src/ts/renderer-game.ts')
'mishiro.live': path.join(__dirname, '../src/ts/renderer-game.ts'),
'mishiro.back': path.join(__dirname, '../src/ts/renderer-back.ts')
},
output: {
path: path.join(__dirname, '../public'),
Expand Down Expand Up @@ -145,6 +146,11 @@ export const renderer: webpack.Configuration = {
inject: false,
template: path.join(__dirname, '../src/ts/template/game.template.ts'),
filename: 'game.html'
}),
new HtmlWebpackPlugin({
inject: false,
template: path.join(__dirname, '../src/ts/template/back.template.ts'),
filename: 'back.html'
})
],
optimization: {
Expand Down
15 changes: 15 additions & 0 deletions app/src/ts/renderer-back.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import './asar'
import { ipcRenderer, remote, Event } from 'electron'
import { util } from 'mishiro-core'
import { removeSync } from 'fs-extra'

const BrowserWindow = remote.BrowserWindow
ipcRenderer.on('texture2d', (_event: Event, assetbundle: string, randomId: string, fromWindowId: number) => {
const fromWindow = BrowserWindow.fromId(fromWindowId)
util.unpackTexture2D(assetbundle).then(result => {
removeSync(assetbundle)
fromWindow.webContents.send(randomId, null, result)
}).catch(e => {
fromWindow.webContents.send(randomId, e, [])
})
})
49 changes: 7 additions & 42 deletions app/src/ts/renderer/win.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,16 @@
import { remote, BrowserWindow, ipcRenderer } from 'electron'
import { join } from 'path'
import getPath from '../common/get-path'
import { format } from 'url'

let id = ipcRenderer.sendSync('mainWindowId')

let win: BrowserWindow | null = new remote.BrowserWindow({ width: 346, height: 346, show: false, parent: remote.BrowserWindow.fromId(id) })

win.loadURL(`data:text/html,
<html><script type="text/javascript">
(function () {
const Module = require('module');
const NODE_MODULES_PATH = ${JSON.stringify(join(__dirname, '../node_modules'))};
const NODE_MODULES_ASAR_PATH = NODE_MODULES_PATH + '.asar';
const originalResolveLookupPaths = Module._resolveLookupPaths;
Module._resolveLookupPaths = function (request, parent, newReturn) {
const result = originalResolveLookupPaths(request, parent, newReturn);
const paths = newReturn ? result : result[1];
for (let i = 0; i < paths.length; i++) {
if (paths[i] === NODE_MODULES_PATH) {
paths.splice(i, 0, NODE_MODULES_ASAR_PATH);
break;
}
}
return result;
};
})();
const ipcRenderer = require('electron').ipcRenderer;
const BrowserWindow = require('electron').remote.BrowserWindow;
const { util } = require('mishiro-core');
const { removeSync } = require('fs-extra');
ipcRenderer.on('texture2d', (event, assetbundle, randomId, fromWindowId) => {
const fromWindow = BrowserWindow.fromId(fromWindowId);
util.unpackTexture2D(assetbundle).then(result => {
removeSync(assetbundle);
fromWindow.webContents.send(randomId, null, result);
}).catch(e => {
fromWindow.webContents.send(randomId, e, []);
});
});
</script></html>
`)
win.loadURL(format({
pathname: getPath('./public/back.html'),
protocol: 'file:',
slashes: true
}))

window.addEventListener('beforeunload', () => {
if (win) win.close()
Expand Down
2 changes: 2 additions & 0 deletions app/src/ts/template/back.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default `<html><script src="./mishiro.back.js"></script></html>
`

0 comments on commit 628b488

Please sign in to comment.