fix: 修复mini窗口显示异常
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const { app, Menu } = require('electron');
|
const { app, Menu } = require('electron');
|
||||||
const { toggleTrayIcon } = require('./tools');
|
const { toggleTrayIcon } = require('./tools');
|
||||||
|
const { config } = require('./config');
|
||||||
|
|
||||||
function getMenu(/** @type Electron.BrowserWindow */mainWindow, miniWindow, current) {
|
function getMenu(/** @type Electron.BrowserWindow */mainWindow, miniWindow, current) {
|
||||||
const template = [{
|
const template = [{
|
||||||
@@ -21,6 +22,12 @@ function getMenu(/** @type Electron.BrowserWindow */mainWindow, miniWindow, curr
|
|||||||
miniWindow.focus();
|
miniWindow.focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "重载页面",
|
||||||
|
click: () => {
|
||||||
|
current.loadURL(config.url);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "打开调试控制台",
|
label: "打开调试控制台",
|
||||||
click: () => current.webContents.openDevTools()
|
click: () => current.webContents.openDevTools()
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
const { ipcRenderer } = require("electron");
|
||||||
|
|
||||||
|
ipcRenderer.on("focus-input", () => {
|
||||||
|
var source = document.querySelector("textarea");
|
||||||
|
if (source) {
|
||||||
|
source.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ipcRenderer.on("clear-input", () => {
|
||||||
|
var button = document.querySelector(
|
||||||
|
"body>c-wiz>div>div>c-wiz>div:nth-of-type(2)>c-wiz>div>div:nth-of-type(2)>div:nth-of-type(2)>c-wiz>div:nth-of-type(2) div button"
|
||||||
|
);
|
||||||
|
if (button) {
|
||||||
|
button.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ipcRenderer.on("random-input", () => {
|
||||||
|
var source = document.querySelector("textarea");
|
||||||
|
if (source) {
|
||||||
|
source.value = source.value ? "" : Math.random();
|
||||||
|
}
|
||||||
|
});
|
||||||
+5
-19
@@ -12,6 +12,7 @@ function createMiniWindow () {
|
|||||||
maxHeight: 315,
|
maxHeight: 315,
|
||||||
icon: path.resolve(__dirname, './assets/icon.png'),
|
icon: path.resolve(__dirname, './assets/icon.png'),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
|
preload: path.resolve(__dirname, 'mini-preload.js'),
|
||||||
nodeIntegration: false
|
nodeIntegration: false
|
||||||
},
|
},
|
||||||
title: "Google Translate Mini",
|
title: "Google Translate Mini",
|
||||||
@@ -23,7 +24,6 @@ function createMiniWindow () {
|
|||||||
fullscreenable: false,
|
fullscreenable: false,
|
||||||
skipTaskbar: false,
|
skipTaskbar: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
miniWindow.on('focus', () => {
|
miniWindow.on('focus', () => {
|
||||||
miniWindow.setOpacity(1);
|
miniWindow.setOpacity(1);
|
||||||
});
|
});
|
||||||
@@ -45,6 +45,7 @@ function createMiniWindow () {
|
|||||||
}
|
}
|
||||||
/* mini窗口隐藏header和历史记录按钮和拼音 */
|
/* mini窗口隐藏header和历史记录按钮和拼音 */
|
||||||
header,
|
header,
|
||||||
|
body > c-wiz:first-of-type > div:first-of-type > div:first-of-type,
|
||||||
.gp-footer,
|
.gp-footer,
|
||||||
.tlid-source-transliteration-container.source-transliteration-container {
|
.tlid-source-transliteration-container.source-transliteration-container {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
@@ -91,12 +92,7 @@ function createMiniWindow () {
|
|||||||
interval = Math.max(1000, interval);
|
interval = Math.max(1000, interval);
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (!miniWindow.isVisible()) {
|
if (!miniWindow.isVisible()) {
|
||||||
miniWindow.webContents.executeJavaScript(`
|
miniWindow.webContents.send('random-input');
|
||||||
var source = document.getElementById('source');
|
|
||||||
if (source) {
|
|
||||||
source.value = source.value ? '' : Math.random();
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
}
|
}
|
||||||
}, interval);
|
}, interval);
|
||||||
}
|
}
|
||||||
@@ -118,20 +114,10 @@ function toggleMiniWindowVisibility(miniWindow, mainWindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearInput(window) {
|
function clearInput(window) {
|
||||||
window.webContents.executeJavaScript(`
|
window.webContents.send('clear-input');
|
||||||
var source = document.getElementById('source');
|
|
||||||
if (source) {
|
|
||||||
source.value = '';
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
}
|
}
|
||||||
function focusInput (window) {
|
function focusInput (window) {
|
||||||
window.webContents.executeJavaScript(`
|
window.webContents.send('focus-input');
|
||||||
var source = document.getElementById('source');
|
|
||||||
if (source) {
|
|
||||||
source.focus();
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in New Issue
Block a user