diff --git a/package.json b/package.json index 5939ec5..61815e5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/main/index.ts b/src/main/index.ts index 760c77e..e9c256c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,3 +1,5 @@ +import path from 'path'; + import { app, Tray, globalShortcut, MenuItem, Menu } from 'electron'; import AutoLaunch from 'auto-launch'; @@ -17,7 +19,7 @@ if (!config.isDebug) { } }); checkForUpdates(); - app.dock.hide(); + app.dock?.hide(); const menu = new Menu(); // 加了菜单才有 cmd + shift + i 的功能 @@ -35,27 +37,26 @@ if (!config.isDebug) { let tray: Tray; app.on('ready', () => { const window = new Window({}); - - // tray = new Tray(`${__public}/iconTemplate@2x.png`); - // 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, 'iconTemplate@2x.png')); + 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; diff --git a/src/main/nativeMessage.ts b/src/main/nativeMessage.ts index 51ec333..ba562ec 100644 --- a/src/main/nativeMessage.ts +++ b/src/main/nativeMessage.ts @@ -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'; @@ -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', }; @@ -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); diff --git a/src/main/window.ts b/src/main/window.ts index dd77c29..baca213 100644 --- a/src/main/window.ts +++ b/src/main/window.ts @@ -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, diff --git a/src/preload/css.ts b/src/preload/css.ts index d37178a..609cfd4 100644 --- a/src/preload/css.ts +++ b/src/preload/css.ts @@ -1,5 +1,7 @@ import { css } from '@mantou/gem'; +import config from '../config'; + export default async () => { await new Promise(resolve => { window.addEventListener('DOMContentLoaded', resolve); @@ -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; } diff --git a/src/preload/shortcut.ts b/src/preload/shortcut.ts index 090fb92..587ec82 100644 --- a/src/preload/shortcut.ts +++ b/src/preload/shortcut.ts @@ -10,6 +10,6 @@ window.addEventListener('keydown', e => { } // esc if (e.keyCode === 27) { - ipcRenderer.send('hide-window'); + ipcRenderer.emit('fade-out'); } }); diff --git a/webpack.config.ts b/webpack.config.ts index 4eda2e6..4b7642a 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -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',