feat: 新增获取LOL客户端窗口信息和显示器信息
This commit is contained in:
parent
ab6cdfb797
commit
cba1f67400
@ -13,6 +13,12 @@ asarUnpack:
|
|||||||
win:
|
win:
|
||||||
executableName: lol-assistant
|
executableName: lol-assistant
|
||||||
requestedExecutionLevel: requireAdministrator
|
requestedExecutionLevel: requireAdministrator
|
||||||
|
extraResources: [
|
||||||
|
{
|
||||||
|
"from": "./tool.exe",
|
||||||
|
"to": "./tool.exe",
|
||||||
|
},
|
||||||
|
]
|
||||||
nsis:
|
nsis:
|
||||||
artifactName: ${name}-${version}-setup.${ext}
|
artifactName: ${name}-${version}-setup.${ext}
|
||||||
shortcutName: ${productName}
|
shortcutName: ${productName}
|
||||||
|
BIN
resources/tool.exe
Normal file
BIN
resources/tool.exe
Normal file
Binary file not shown.
@ -3,6 +3,7 @@ import { join } from 'path'
|
|||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
import { exec } from 'child_process'
|
import { exec } from 'child_process'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
const getBaseConfig = () => {
|
const getBaseConfig = () => {
|
||||||
return new Promise((resolve) =>
|
return new Promise((resolve) =>
|
||||||
@ -44,6 +45,74 @@ const getBaseConfig = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getLOLClientWindowInfo = () => {
|
||||||
|
const command = path.join(process.cwd(), '/resources/tool.exe -f getLOLClientWindowPosition')
|
||||||
|
return new Promise((resolve) =>
|
||||||
|
exec(command, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.log('error', error)
|
||||||
|
resolve({
|
||||||
|
ok: true
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (stderr) {
|
||||||
|
console.log('stderr', stderr)
|
||||||
|
resolve({
|
||||||
|
ok: true
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log('stdout', stdout)
|
||||||
|
try {
|
||||||
|
const lines = stdout.split('\n')
|
||||||
|
const windowItems = lines[0].split(' ').map(item => parseInt(item, 10));
|
||||||
|
const monitorItems = lines[1].split(' ').map(item => parseInt(item, 10));
|
||||||
|
resolve({
|
||||||
|
ok: true,
|
||||||
|
client: {
|
||||||
|
left: windowItems[0],
|
||||||
|
top: windowItems[1],
|
||||||
|
bottom: windowItems[2],
|
||||||
|
right: windowItems[3],
|
||||||
|
width: windowItems[4],
|
||||||
|
height: windowItems[5]
|
||||||
|
},
|
||||||
|
monitor: {
|
||||||
|
left: monitorItems[0],
|
||||||
|
top: monitorItems[1],
|
||||||
|
bottom: monitorItems[2],
|
||||||
|
right: monitorItems[3],
|
||||||
|
width: monitorItems[4],
|
||||||
|
height: monitorItems[5]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (_) {
|
||||||
|
resolve({
|
||||||
|
ok: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// const tokenMatch = stdout.match(/--remoting-auth-token=([^\s"]+)/)
|
||||||
|
// const portMatch = stdout.match(/--app-port=([^\s"]+)/)
|
||||||
|
// const token = tokenMatch?.[1] || ''
|
||||||
|
// const auth = Buffer.from(`riot:${token}`).toString('base64')
|
||||||
|
// const port = portMatch?.[1] || ''
|
||||||
|
// resolve(
|
||||||
|
// token !== ''
|
||||||
|
// ? {
|
||||||
|
// Auth: `Basic ${auth}`,
|
||||||
|
// BASE_URL: `https://127.0.0.1:${port}`
|
||||||
|
// }
|
||||||
|
// : {
|
||||||
|
// Auth: 'Auth required',
|
||||||
|
// BASE_URL: ''
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
@ -84,6 +153,7 @@ app.whenReady().then(() => {
|
|||||||
electronApp.setAppUserModelId('com.electron')
|
electronApp.setAppUserModelId('com.electron')
|
||||||
|
|
||||||
ipcMain.handle('getBaseConfig', getBaseConfig)
|
ipcMain.handle('getBaseConfig', getBaseConfig)
|
||||||
|
ipcMain.handle('getLOLClientWindowInfo', getLOLClientWindowInfo)
|
||||||
// Default open or close DevTools by F12 in development
|
// Default open or close DevTools by F12 in development
|
||||||
// and ignore CommandOrControl + R in production.
|
// and ignore CommandOrControl + R in production.
|
||||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { contextBridge, ipcRenderer } from 'electron'
|
import electron, { contextBridge, ipcRenderer } from 'electron'
|
||||||
import { electronAPI } from '@electron-toolkit/preload'
|
import { electronAPI } from '@electron-toolkit/preload'
|
||||||
|
|
||||||
// Custom APIs for renderer
|
// Custom APIs for renderer
|
||||||
@ -11,9 +11,12 @@ if (process.contextIsolated) {
|
|||||||
try {
|
try {
|
||||||
contextBridge.exposeInMainWorld('electron', electronAPI)
|
contextBridge.exposeInMainWorld('electron', electronAPI)
|
||||||
contextBridge.exposeInMainWorld('api', api)
|
contextBridge.exposeInMainWorld('api', api)
|
||||||
contextBridge.exposeInMainWorld('electronAPI', {
|
contextBridge.exposeInMainWorld('baseConfig', {
|
||||||
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
||||||
})
|
})
|
||||||
|
contextBridge.exposeInMainWorld('client', {
|
||||||
|
getLOLClientWindowInfo: () => ipcRenderer.invoke('getLOLClientWindowInfo')
|
||||||
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
@ -23,4 +26,7 @@ if (process.contextIsolated) {
|
|||||||
window.electronAPI = {
|
window.electronAPI = {
|
||||||
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
||||||
}
|
}
|
||||||
|
window.electronAPI = {
|
||||||
|
getLOLClientWindowInfo: () => ipcRenderer.invoke('getLOLClientWindowInfo')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import Versions from './components/Versions.vue'
|
import Versions from './components/Versions.vue'
|
||||||
|
|
||||||
const ipcHandle = async () => {
|
const getBaseConfig = async () => {
|
||||||
const baseConfig = await window.electronAPI.getBaseConfig()
|
return await window.baseConfig.getBaseConfig()
|
||||||
console.log(baseConfig)
|
}
|
||||||
|
|
||||||
|
const getLOLClientWindowInfo = async () => {
|
||||||
|
const LOLClientWindowInfo = await window.client.getLOLClientWindowInfo()
|
||||||
|
console.log(LOLClientWindowInfo)
|
||||||
|
return LOLClientWindowInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
const intervalId = setInterval(async () => {
|
const intervalId = setInterval(async () => {
|
||||||
const config = await window.electronAPI.getBaseConfig()
|
const config = await getBaseConfig()
|
||||||
|
|
||||||
// 假设我们在某些条件下想停止定时器
|
// 假设我们在某些条件下想停止定时器
|
||||||
if (config.Auth && config.Auth === 'Auth required') {
|
if (config.Auth && config.Auth === 'Auth required') {
|
||||||
@ -15,10 +20,10 @@ const intervalId = setInterval(async () => {
|
|||||||
console.log('请以管理员权限启动')
|
console.log('请以管理员权限启动')
|
||||||
} else if (config.Auth && config.Auth !== '') {
|
} else if (config.Auth && config.Auth !== '') {
|
||||||
clearInterval(intervalId)
|
clearInterval(intervalId)
|
||||||
|
await getLOLClientWindowInfo()
|
||||||
console.log('检测到客户端运行')
|
console.log('检测到客户端运行')
|
||||||
}
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -34,7 +39,7 @@ const intervalId = setInterval(async () => {
|
|||||||
<a href="https://electron-vite.org/" target="_blank" rel="noreferrer">Documentation</a>
|
<a href="https://electron-vite.org/" target="_blank" rel="noreferrer">Documentation</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="action">
|
<div class="action">
|
||||||
<a target="_blank" rel="noreferrer" @click="ipcHandle">Send IPC</a>
|
<a target="_blank" rel="noreferrer" @click="getLOLClientWindowInfo">Send IPC</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Versions />
|
<Versions />
|
||||||
|
Reference in New Issue
Block a user