Skip to content

Commit

Permalink
chore: Adjust the code directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
王先硚 committed Sep 11, 2018
1 parent 5478aa5 commit e40b8e1
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
- 在任意应用中选择文本,使用 <kbd>command</kbd> + <kbd>q</kbd> 进行翻译
- 在窗口内使用快捷键:<br>
<kbd>esc</kbd> - 关闭窗口<br>
<kbd>enter</kbd> - 聚焦到输入框<br>
<kbd>enter</kbd> - Google 翻译页面聚焦到输入框<br>
<kbd>command</kbd> + <kbd>r</kbd> - 刷新页面<br>
<kbd>command</kbd> + <kbd>back</kbd> - 回到翻译页面<br>
<kbd>command</kbd> + <kbd>1</kbd> - 朗读源文本<br>
<kbd>command</kbd> + <kbd>2</kbd> - 朗读翻译文本<br>
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import Vue from 'vue';
import Comopnent from 'vue-class-component';
import styled from 'vue-emotion';

import config from '../config';
import config from './config';
import registerShortcut from './globalShortcut';
import './globalCSS';

registerShortcut();

const isDevelopment = process.env.NODE_ENV !== 'production';

const Wrap = styled.div<{ color: string }>`
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions src/renderer/globalShortcut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ipcRenderer, remote } from 'electron';
import { frequency } from './inject/util';

export default function () {
const exitApp = frequency(() => remote.app.quit());
window.addEventListener('keydown', (e) => {
// command + shift + w
if (e.keyCode === 87 && e.shiftKey && (e.metaKey || e.ctrlKey)) {
exitApp();
}
// command + r
if (e.keyCode === 82 && (e.metaKey || e.ctrlKey)) {
window.location.reload();
}
// esc
if (e.keyCode === 27) {
ipcRenderer.send('hideWindow');
}
});
}
15 changes: 4 additions & 11 deletions src/inject/index.ts → src/renderer/inject/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ipcRenderer, remote } from 'electron';
import { frequency } from './util';
import { ipcRenderer } from 'electron';
import textBoxHistory from './textboxhistory';
import injectCSS from './injectCSS';
import lang from './lang';
import config from '../config';
import registerShortcut from '../globalShortcut';

registerShortcut();

const initTranslatePage = () => {
const i18n = lang();
Expand All @@ -26,16 +28,7 @@ const initTranslatePage = () => {
sourceTextHistory.addValueToHistory(arg);
});

const exitApp = frequency(() => remote.app.quit());
window.addEventListener('keydown', (e) => {
// command + shift + w
if (e.keyCode === 87 && e.shiftKey && (e.metaKey || e.ctrlKey)) {
exitApp();
}
// esc
if (e.keyCode === 27) {
ipcRenderer.send('hideWindow');
}
// enter
if (e.keyCode === 13 && document.activeElement !== sourceTextArea) {
sourceTextArea.focus();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
filename: 'index.html',
},
inject: {
entry: './src/inject/index.ts',
entry: './src/renderer/inject/index.ts',
filename: 'inject.html',
},
},
Expand Down

0 comments on commit e40b8e1

Please sign in to comment.