Skip to content

Commit

Permalink
Merge pull request #33 from project-yuki/b0.10
Browse files Browse the repository at this point in the history
version 0.10
  • Loading branch information
tinyAdapter authored Nov 16, 2019
2 parents 7381eeb + cc1fe03 commit 73f2a50
Show file tree
Hide file tree
Showing 29 changed files with 567 additions and 2,619 deletions.
47 changes: 47 additions & 0 deletions .electron-vue/dev-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@ const webpackHotMiddleware = require("webpack-hot-middleware");
const mainConfig = require("./webpack.main.config");
const rendererConfig = require("./webpack.renderer.config");
const translatorConfig = require("./webpack.translator.config");
const ProgressPlugin = require("webpack/lib/ProgressPlugin");

let electronProcess = null;
let manualRestart = false;
let hotMiddleware;

const threadLoader = require("thread-loader");

threadLoader.warmup({}, [
// modules to load
// can be any module, i. e.
"ts-loader",
"babel-loader",
"vue-loader",
"vue-style-loader",
"css-loader",
"sass-loader"
]
);

function logStats(proc, data) {
let log = "";

Expand Down Expand Up @@ -50,6 +65,38 @@ function startRenderer() {
heartbeat: 2500
});

// rendererCompiler.apply(
// new ProgressPlugin(function(
// percentage,
// msg,
// current,
// active,
// modulepath
// ) {
// if (process.stdout.isTTY && percentage < 1) {
// // process.stdout.cursorTo(0);
// // modulepath = modulepath
// // ? " …" + modulepath.substr(modulepath.length - 30)
// // : "";
// current = current ? " " + current : "";
// active = active ? " " + active : "";
// process.stdout.write(
// (percentage * 100).toFixed(0) +
// "% " +
// msg +
// current +
// active +
// modulepath +
// "\n"
// );
// // process.stdout.clearLine(1);
// } else if (percentage === 1) {
// process.stdout.write("\n");
// console.log("webpack: done.");
// }
// })
// );

rendererCompiler.hooks.compilation.tap("compilation", compilation => {
compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync(
"html-webpack-plugin-after-emit",
Expand Down
6 changes: 5 additions & 1 deletion .electron-vue/webpack.main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ process.env.BABEL_ENV = "main";
const path = require("path");
const { dependencies, devDependencies } = require("../package.json");
const webpack = require("webpack");
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");

let mainConfig = {
optimization: {
Expand Down Expand Up @@ -58,7 +59,10 @@ let mainConfig = {
libraryTarget: "commonjs2",
path: path.join(__dirname, "../dist/electron")
},
plugins: [new webpack.NoEmitOnErrorsPlugin()],
plugins: [
new HardSourceWebpackPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
resolve: {
extensions: [".ts", ".js", ".json", ".node"]
},
Expand Down
12 changes: 4 additions & 8 deletions .electron-vue/webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const webpack = require("webpack");

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const VuetifyLoaderPlugin = require("vuetify-loader/lib/plugin");
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");

/**
* List of node_modules to include in webpack bundle
Expand Down Expand Up @@ -97,13 +98,7 @@ let rendererConfig = {
{
loader: "vue-loader",
options: {
extractCSS: process.env.NODE_ENV === "production",
loaders: {
sass:
"vue-style-loader!css-loader!sass-loader?indentedSyntax=1",
scss: "vue-style-loader!css-loader!sass-loader",
less: "vue-style-loader!css-loader!less-loader"
}
extractCSS: process.env.NODE_ENV === "production"
}
}
]
Expand Down Expand Up @@ -150,6 +145,7 @@ let rendererConfig = {
__filename: process.env.NODE_ENV !== "production"
},
plugins: [
new HardSourceWebpackPlugin(),
new VuetifyLoaderPlugin(),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({ filename: "styles.css" }),
Expand Down
12 changes: 4 additions & 8 deletions .electron-vue/webpack.translator.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const webpack = require("webpack");

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const VuetifyLoaderPlugin = require("vuetify-loader/lib/plugin");
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");

/**
* List of node_modules to include in webpack bundle
Expand Down Expand Up @@ -97,13 +98,7 @@ let translatorConfig = {
{
loader: "vue-loader",
options: {
extractCSS: process.env.NODE_ENV === "production",
loaders: {
sass:
"vue-style-loader!css-loader!sass-loader?indentedSyntax=1",
scss: "vue-style-loader!css-loader!sass-loader",
less: "vue-style-loader!css-loader!less-loader"
}
extractCSS: process.env.NODE_ENV === "production"
}
}
]
Expand Down Expand Up @@ -148,6 +143,7 @@ let translatorConfig = {
__filename: process.env.NODE_ENV !== "production"
},
plugins: [
new HardSourceWebpackPlugin(),
new VuetifyLoaderPlugin(),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({ filename: "styles-translator.css" }),
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"editor.tabSize": 2
"editor.tabSize": 2,
"typescript.tsdk": "node_modules\\typescript\\lib"
}
10 changes: 5 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"localeChangers": {
"alphaROMdiE": {
"enable": false,
"exec": "D:\\software\\AlphaROMdiE.exe %GAME_PATH%",
"exec": "C:\\Resources\\Games\\AlphaROMdiE.exe %GAME_PATH%",
"name": "AlphaROMdiE"
},
"localeEmulator": {
"enable": true,
"exec": "D:\\LocaleEmulator\\LEProc.exe %GAME_PATH%",
"exec": "C:\\LocaleEmulator\\LEProc.exe %GAME_PATH%",
"name": "Locale Emulator"
},
"noChanger": {
Expand All @@ -19,7 +19,7 @@
},
"ntleas": {
"enable": false,
"exec": "D:\\ntleas046_x64\\x86\\ntleas.exe %GAME_PATH%",
"exec": "C:\\ntleas046_x64\\x86\\ntleas.exe %GAME_PATH%",
"name": "Ntleas"
}
},
Expand Down Expand Up @@ -66,9 +66,9 @@
],
"translators": {
"jBeijing": {
"dictPath": "E:\\yuki\\yuki\\lib\\dict\\jb",
"dictPath": "C:\\YUKI\\yuki\\lib\\dict\\jb",
"enable": true,
"path": "D:\\Visual Novel Reader V2\\JBeijing7"
"path": "C:\\JBeijing7"
}
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
"vuetify": "^2.1.4",
"vuetify-dialog": "^1.0.0-alpha.5",
"vuex": "^3.0.1",
"wanakana": "^4.0.2"
"wanakana": "^4.0.2",
"xterm": "^4.2.0-vscode1",
"xterm-addon-fit": "^0.3.0"
},
"devDependencies": {
"@kazupon/vue-i18n-loader": "^0.3.0",
Expand Down Expand Up @@ -105,6 +107,7 @@
"electron-rebuild": "^1.8.6",
"fibers": "^4.0.1",
"file-loader": "^1.1.11",
"hard-source-webpack-plugin": "^0.13.1",
"html-webpack-plugin": "^3.2.0",
"ignore-loader": "^0.1.2",
"inject-loader": "^4.0.1",
Expand Down Expand Up @@ -140,7 +143,7 @@
"vue-template-compiler": "^2.6.10",
"vuetify-loader": "^1.3.0",
"vuex-class": "^0.3.1",
"webpack": "^4.19.1",
"webpack": "^4.41.2",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.11",
"webpack-hot-middleware": "^2.22.2",
Expand Down
4 changes: 3 additions & 1 deletion src/common/IpcTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ enum IpcTypes {
REQUEST_PAUSE_DOWNLOAD = 'request-pause-download',
REQUEST_RESUME_DOWNLOAD = 'request-resume-download',
REQUEST_ABORT_DOWNLOAD = 'request-abort-download',
REQUEST_DOWNLOAD_LIBRARY = 'request-download-library'
REQUEST_DOWNLOAD_LIBRARY = 'request-download-library',
HAS_NEW_DEBUG_MESSAGE = 'has-new-debug-message',
GAME_ABORTED = 'game-aborted'
}

export default IpcTypes
10 changes: 8 additions & 2 deletions src/common/locales.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"add": "添加",
"prompt": "提示",
"saved": "已保存",
"toggleDevTools": "切换开发人员工具"
"toggleDevTools": "切换开发人员工具",
"debugMessages": "调试信息",
"debugMsg": "调试信息",
"description": "说明"
},
"en": {
"YUKIGalgameTranslator": "Galgame Translator",
Expand All @@ -51,6 +54,9 @@
"add": "Add",
"prompt": "Prompt",
"saved": "Saved",
"toggleDevTools": "Toggle Dev Tools"
"toggleDevTools": "Toggle Dev Tools",
"debugMessages": "Debug Messages",
"debugMsg": "Debug Msg",
"description": "Description"
}
}
30 changes: 23 additions & 7 deletions src/main/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ export default class Game extends EventEmitter {
this.exeName = ''
}

public start () {
this.execGameProcess()
this.registerHookerWithPid()
public async start () {
try {
await this.execGameProcess()
this.registerHookerWithPid()
} catch (e) {
this.emit('abort')
this.emit('exited')
}
}

public getPids () {
Expand All @@ -46,10 +51,20 @@ export default class Game extends EventEmitter {
}

private execGameProcess () {
this.getRawExecStringOrDefault()
this.replaceExecStringTokensWithActualValues()
debug('exec string: %s', this.execString)
exec(this.execString)
return new Promise((resolve, reject) => {
this.getRawExecStringOrDefault()
this.replaceExecStringTokensWithActualValues()
debug('exec string: %s', this.execString)
exec(this.execString, (err, stdout, stderr) => {
if (err) {
debug('program exited unexpectedly with code %d', err.code)
reject()
}
if (stdout) debug('program stdout: %s', stdout)
if (stderr) debug('program stderr: %s', stderr)
resolve()
})
})
}

private getRawExecStringOrDefault () {
Expand Down Expand Up @@ -79,6 +94,7 @@ export default class Game extends EventEmitter {
await this.findPids()
} catch (e) {
debug('could not find game %s. abort', this.exeName)
this.emit('abort')
this.emit('exited')
return
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/setup/Ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { app, dialog, ipcMain } from 'electron'
import IpcTypes from '../../common/IpcTypes'
const debug = require('debug')('yuki:ipc')
import { extname } from 'path'
import { format } from 'util'
import ConfigManager from '../config/ConfigManager'
import DownloaderFactory from '../DownloaderFactory'
import Game from '../Game'
Expand All @@ -13,6 +14,15 @@ let runningGame: Game
let translatorWindow: TranslatorWindow | null

export default function (mainWindow: Electron.BrowserWindow) {
require('debug').log = (message: any, ...optionalParams: any[]) => {
// tslint:disable-next-line: no-console
console.log(message, ...optionalParams)
mainWindow.webContents.send(
IpcTypes.HAS_NEW_DEBUG_MESSAGE,
format(message, ...optionalParams)
)
}

ipcMain.on(IpcTypes.MAIN_PAGE_LOAD_FINISHED, () => {
debug('main page load finished. starting apis...')
TranslationManager.getInstance().initializeApis(
Expand Down Expand Up @@ -41,6 +51,9 @@ export default function (mainWindow: Electron.BrowserWindow) {
translatorWindow = null
mainWindow.show()
})
runningGame.on('abort', () => {
mainWindow.webContents.send(IpcTypes.GAME_ABORTED)
})
runningGame.start()
}
)
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/components/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@
</v-list-item>
</v-list-group>

<v-list-item to="/debugMessages">
<v-list-item-icon>
<v-icon>mdi-alert</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{$t('debugMsg')}}</v-list-item-title>
</v-list-item-content>
</v-list-item>

<v-list-item to="/about">
<v-list-item-icon>
<v-icon>mdi-information</v-icon>
Expand Down
Loading

0 comments on commit 73f2a50

Please sign in to comment.