Skip to content

Commit

Permalink
feat: support win
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Nov 17, 2019
1 parent 50d6a39 commit 5711968
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "google-translate",
"version": "3.3.2",
"version": "4.0.0",
"description": "google translate, work io any app",
"main": "./dist/index.js",
"scripts": {
Expand Down
45 changes: 23 additions & 22 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';

import { app, Tray, globalShortcut, MenuItem, Menu } from 'electron';
import AutoLaunch from 'auto-launch';

Expand All @@ -17,7 +19,7 @@ if (!config.isDebug) {
}
});
checkForUpdates();
app.dock.hide();
app.dock?.hide();

const menu = new Menu();
// 加了菜单才有 cmd + shift + i 的功能
Expand All @@ -35,27 +37,26 @@ if (!config.isDebug) {
let tray: Tray;
app.on('ready', () => {
const window = new Window({});

// tray = new Tray(`${__public}/[email protected]`);
// tray
// .on('click', () => {
// if (window.isVisible()) {
// window.fadeOut();
// } else {
// window.fadeIn();
// }
// })
// .on('right-click', () => {
// const contextMenu = Menu.buildFromTemplate([
// {
// label: 'Quit',
// click() {
// app.exit();
// },
// },
// ]);
// tray.popUpContextMenu(contextMenu);
// });
tray = new Tray(path.resolve(__public, '[email protected]'));
tray
.on('click', () => {
if (window.isVisible()) {
window.fadeOut();
} else {
window.fadeIn();
}
})
.on('right-click', () => {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Quit',
click() {
app.exit();
},
},
]);
tray.popUpContextMenu(contextMenu);
});

globalShortcut.register('CommandOrControl+Q', async () => {
if (!window) return;
Expand Down
7 changes: 5 additions & 2 deletions src/main/nativeMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/camelcase */
import process from 'process';
import os from 'os';
import path from 'path';
import fs from 'fs';
import { promisify } from 'util';
Expand All @@ -15,7 +16,9 @@ export function installNativeMessageManifest() {
const manifest = {
name: 'google_translate_bridge',
description: '谷歌翻译',
path: config.isDebug ? `${process.cwd()}/src/bridge/target/debug/bridge` : `${__public}/google-translate-bridge`,
path: config.isDebug
? path.resolve(process.cwd(), 'src/bridge/target/debug/bridge')
: path.resolve(__public, 'google-translate-bridge'),
type: 'stdio',
};

Expand All @@ -42,7 +45,7 @@ export function installNativeMessageManifest() {

browsersOpt.forEach(async opt => {
const title = 'Google 翻译添加浏览器支持失败';
const absDir = path.resolve(process.env.HOME!, opt.dir);
const absDir = path.resolve(os.homedir(), opt.dir);
try {
try {
await promisify(fs.readdir)(absDir);
Expand Down
3 changes: 2 additions & 1 deletion src/main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default class Window extends BrowserWindow {
super({
show: false,
transparent: true,
// vibrancy: 'light',
frame: false,
skipTaskbar: true,
titleBarStyle: 'customButtonsOnHover',
minimizable: false,
maximizable: false,
Expand Down
8 changes: 3 additions & 5 deletions src/preload/css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from '@mantou/gem';

import config from '../config';

export default async () => {
await new Promise(resolve => {
window.addEventListener('DOMContentLoaded', resolve);
Expand Down Expand Up @@ -36,16 +38,12 @@ export default async () => {
}
body {
-webkit-app-region: drag;
background: transparent;
transform: translateX(100%);
}
a {
-webkit-app-region: no-drag;
}
.frame {
background: #f5f5f5;
margin-left: 20px;
margin: ${config.isWin ? '20px' : 0} 0 0 20px;
filter: drop-shadow(rgba(0, 0, 0, 0.5) 0px 0px 0.5px);
box-shadow: 0 1px 10px rgba(0, 0, 0, 0.15) !important;
}
Expand Down
2 changes: 1 addition & 1 deletion src/preload/shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ window.addEventListener('keydown', e => {
}
// esc
if (e.keyCode === 27) {
ipcRenderer.send('hide-window');
ipcRenderer.emit('fade-out');
}
});
4 changes: 3 additions & 1 deletion webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const commonConfig: webpack.Configuration = {
},
plugins: [
new webpack.DefinePlugin({
__public: isDevelopment ? `"${__dirname}/public"` : `process.resourcesPath + "/public"`,
__public: isDevelopment
? `'${__dirname}${path.sep}public'`.replace(/\\/g, '\\\\')
: `require('path').resolve(process.resourcesPath, 'public')`,
}),
],
devtool: 'source-map',
Expand Down

0 comments on commit 5711968

Please sign in to comment.