From 442b4fb30f8332bbe1a86da529998a8f2194703f Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 25 Feb 2022 10:26:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BB=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/modules/userApi/rendererEvent/rendererEvent.js | 5 ++--- src/main/rendererEvents/openDevtools.js | 5 ++--- src/main/rendererEvents/winEvent.js | 3 ++- src/main/utils/index.js | 6 ++++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/modules/userApi/rendererEvent/rendererEvent.js b/src/main/modules/userApi/rendererEvent/rendererEvent.js index 2982416b..e57088cc 100644 --- a/src/main/modules/userApi/rendererEvent/rendererEvent.js +++ b/src/main/modules/userApi/rendererEvent/rendererEvent.js @@ -3,6 +3,7 @@ const { mainOn, mainSend } = require('@common/ipc') const USER_API_RENDERER_EVENT_NAME = require('../rendererEvent/name') const { createWindow } = require('../main') const { getUserApis } = require('../utils') +const { openDevTools } = require('@main/utils') let userApi let status = { status: true } @@ -32,9 +33,7 @@ const handleResponse = (event, { status, data: { requestKey, result }, message } } const handleOpenDevTools = () => { if (global.modules.userApiWindow) { - global.modules.userApiWindow.webContents.openDevTools({ - mode: 'undocked', - }) + openDevTools(global.modules.userApiWindow.webContents) } } const handleShowUpdateAlert = (event, { data }) => { diff --git a/src/main/rendererEvents/openDevtools.js b/src/main/rendererEvents/openDevtools.js index 20d6626d..cb8bee00 100644 --- a/src/main/rendererEvents/openDevtools.js +++ b/src/main/rendererEvents/openDevtools.js @@ -1,13 +1,12 @@ const { mainOn, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc') +const { openDevTools } = require('@main/utils') mainOn(ipcMainWindowNames.open_dev_tools, event => { if (global.modules.mainWindow) { if (global.modules.mainWindow.isDevToolsOpened()) { global.modules.mainWindow.webContents.closeDevTools() } else { - global.modules.mainWindow.webContents.openDevTools({ - mode: 'undocked', - }) + openDevTools(global.modules.mainWindow.webContents) } } }) diff --git a/src/main/rendererEvents/winEvent.js b/src/main/rendererEvents/winEvent.js index 8b4ced28..6e983023 100644 --- a/src/main/rendererEvents/winEvent.js +++ b/src/main/rendererEvents/winEvent.js @@ -1,4 +1,5 @@ const { isWin } = require('../../common/utils') +const { openDevTools } = require('@main/utils') const { mainSend, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc') global.isQuitting = false global.isTrafficLightClose = false // 是否点击软件上的关闭按钮关闭 @@ -30,7 +31,7 @@ module.exports = mainWindow => { mainWindow.once('ready-to-show', () => { mainWindow.show() global.lx_event.mainWindow.readyToShow() - if (global.envParams.cmdParams.debug) global.modules.mainWindow.webContents.openDevTools() + if (global.envParams.cmdParams.debug) openDevTools(global.modules.mainWindow.webContents) }) mainWindow.on('show', () => { diff --git a/src/main/utils/index.js b/src/main/utils/index.js index 53c974bc..ac83ce72 100644 --- a/src/main/utils/index.js +++ b/src/main/utils/index.js @@ -41,3 +41,9 @@ exports.initSetting = (isShowErrorAlert = true) => { global.appSetting = info.setting global.appSettingVersion = info.version } + +exports.openDevTools = webContents => { + webContents.openDevTools({ + mode: 'undocked', + }) +}