Skip to content

Commit

Permalink
现在调用菜单项开发者工具同时也会显示游戏Webview的开发者工具了
Browse files Browse the repository at this point in the history
  • Loading branch information
iamapig120 committed Jan 28, 2019
1 parent 4f84a68 commit 466d430
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 93 deletions.
6 changes: 6 additions & 0 deletions bin/main/mainLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ ipcRenderer.on('take-screenshot', () => {
}
})

ipcRenderer.on('open-devtools', () => {
if (webContents) {
mainWindow.openDevTools({ mode: 'detach' })
}
})

const testRedirectGameWindow = url => {
return url.startsWith(configs.REMOTE_DOMAIN)
}
Expand Down
186 changes: 94 additions & 92 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,100 @@ electronApp.on(
}
)

// 设置一个菜单
const gameWindowMenu = new Menu()
gameWindowMenu.append(
new MenuItem({
label: '游戏',
role: 'services',
submenu: [
new MenuItem({
label: '截图',
accelerator: 'F12',
click: (menuItem, browserWindow) => {
Util.takeScreenshot(browserWindow.webContents)
}
}),
new MenuItem({
label: '截图',
accelerator: 'CmdOrCtrl+P',
enabled: true,
// visible: false,
click: (menuItem, browserWindow) => {
Util.takeScreenshot(browserWindow.webContents)
}
}),
new MenuItem({
label: '退出游戏',
accelerator: 'Alt+F4',
click: (menuItem, browserWindow) => {
browserWindow.close()
}
})
]
})
)
gameWindowMenu.append(
new MenuItem({
label: '窗口',
role: 'window',
submenu: [
new MenuItem({
label: '全屏',
accelerator: 'F11',
click: (menuItem, browserWindow) => {
if (!userConfigs.window.isKioskModeOn) {
browserWindow.setFullScreen(!browserWindow.isFullScreen())
} else {
browserWindow.setKiosk(!browserWindow.isKiosk())
}
}
}),
new MenuItem({
label: '全屏',
accelerator: 'F5',
enabled: true,
visible: false,
click: (menuItem, browserWindow) => {
if (!userConfigs.window.isKioskModeOn) {
browserWindow.setFullScreen(!browserWindow.isFullScreen())
} else {
browserWindow.setKiosk(!browserWindow.isKiosk())
}
}
}),
new MenuItem({
label: '退出全屏',
accelerator: 'Esc',
click: (menuItem, browserWindow) => {
if (browserWindow.isFullScreen()) {
browserWindow.setFullScreen(false)
return
}
if (browserWindow.isKiosk()) {
browserWindow.setKiosk(false)
}
}
})
]
})
)
gameWindowMenu.append(
new MenuItem({
label: '更多',
submenu: [
new MenuItem({
label: '开发者工具',
accelerator: 'CmdOrCtrl+I',
click: (menuItem, browserWindow) => {
browserWindow.openDevTools({ mode: 'detach' })
browserWindow.send('open-devtools')
}
})
]
})
)

const windowControl = {
windowMap: { toolsMap: {} },
_getGameWindowTitle: () => {
Expand Down Expand Up @@ -207,98 +301,6 @@ const windowControl = {
gameWindow.openDevTools({ mode: 'detach' })
}

// 设置一个菜单
const gameWindowMenu = new Menu()
gameWindowMenu.append(
new MenuItem({
label: '游戏',
role: 'services',
submenu: [
new MenuItem({
label: '截图',
accelerator: 'F12',
click: (menuItem, browserWindow) => {
Util.takeScreenshot(browserWindow.webContents)
}
}),
new MenuItem({
label: '截图',
accelerator: 'CmdOrCtrl+P',
enabled: true,
// visible: false,
click: (menuItem, browserWindow) => {
Util.takeScreenshot(browserWindow.webContents)
}
}),
new MenuItem({
label: '退出游戏',
accelerator: 'Alt+F4',
click: (menuItem, browserWindow) => {
browserWindow.close()
}
})
]
})
)
gameWindowMenu.append(
new MenuItem({
label: '窗口',
role: 'window',
submenu: [
new MenuItem({
label: '全屏',
accelerator: 'F11',
click: (menuItem, browserWindow) => {
if (!userConfigs.window.isKioskModeOn) {
browserWindow.setFullScreen(!browserWindow.isFullScreen())
} else {
browserWindow.setKiosk(!browserWindow.isKiosk())
}
}
}),
new MenuItem({
label: '全屏',
accelerator: 'F5',
enabled: true,
visible: false,
click: (menuItem, browserWindow) => {
if (!userConfigs.window.isKioskModeOn) {
browserWindow.setFullScreen(!browserWindow.isFullScreen())
} else {
browserWindow.setKiosk(!browserWindow.isKiosk())
}
}
}),
new MenuItem({
label: '退出全屏',
accelerator: 'Esc',
click: (menuItem, browserWindow) => {
if (browserWindow.isFullScreen()) {
browserWindow.setFullScreen(false)
return
}
if (browserWindow.isKiosk()) {
browserWindow.setKiosk(false)
}
}
})
]
})
)
gameWindowMenu.append(
new MenuItem({
label: '更多',
submenu: [
new MenuItem({
label: '开发者工具',
accelerator: 'CmdOrCtrl+I',
click: (menuItem, browserWindow) => {
browserWindow.openDevTools({ mode: 'detach' })
}
})
]
})
)
Menu.setApplicationMenu(gameWindowMenu)

windowControl.windowMap['game'] = gameWindow
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "majsoul-plus-client",
"version": "1.8.12-alpha.1",
"version": "1.8.12-alpha.2",
"productName": "Majsoul Plus",
"author": "MajsoulPlus Team",
"description": "Majsoul Plus",
Expand Down

0 comments on commit 466d430

Please sign in to comment.