feat: 新增获取LOL客户端窗口信息和显示器信息
This commit is contained in:
parent
ab6cdfb797
commit
cba1f67400
@ -13,6 +13,12 @@ asarUnpack:
|
||||
win:
|
||||
executableName: lol-assistant
|
||||
requestedExecutionLevel: requireAdministrator
|
||||
extraResources: [
|
||||
{
|
||||
"from": "./tool.exe",
|
||||
"to": "./tool.exe",
|
||||
},
|
||||
]
|
||||
nsis:
|
||||
artifactName: ${name}-${version}-setup.${ext}
|
||||
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 icon from '../../resources/icon.png?asset'
|
||||
import { exec } from 'child_process'
|
||||
import path from 'path'
|
||||
|
||||
const getBaseConfig = () => {
|
||||
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() {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
@ -84,6 +153,7 @@ app.whenReady().then(() => {
|
||||
electronApp.setAppUserModelId('com.electron')
|
||||
|
||||
ipcMain.handle('getBaseConfig', getBaseConfig)
|
||||
ipcMain.handle('getLOLClientWindowInfo', getLOLClientWindowInfo)
|
||||
// Default open or close DevTools by F12 in development
|
||||
// and ignore CommandOrControl + R in production.
|
||||
// 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'
|
||||
|
||||
// Custom APIs for renderer
|
||||
@ -11,9 +11,12 @@ if (process.contextIsolated) {
|
||||
try {
|
||||
contextBridge.exposeInMainWorld('electron', electronAPI)
|
||||
contextBridge.exposeInMainWorld('api', api)
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
contextBridge.exposeInMainWorld('baseConfig', {
|
||||
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
||||
})
|
||||
contextBridge.exposeInMainWorld('client', {
|
||||
getLOLClientWindowInfo: () => ipcRenderer.invoke('getLOLClientWindowInfo')
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
@ -23,4 +26,7 @@ if (process.contextIsolated) {
|
||||
window.electronAPI = {
|
||||
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
||||
}
|
||||
window.electronAPI = {
|
||||
getLOLClientWindowInfo: () => ipcRenderer.invoke('getLOLClientWindowInfo')
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
<script setup>
|
||||
import Versions from './components/Versions.vue'
|
||||
|
||||
const ipcHandle = async () => {
|
||||
const baseConfig = await window.electronAPI.getBaseConfig()
|
||||
console.log(baseConfig)
|
||||
const getBaseConfig = async () => {
|
||||
return await window.baseConfig.getBaseConfig()
|
||||
}
|
||||
|
||||
const getLOLClientWindowInfo = async () => {
|
||||
const LOLClientWindowInfo = await window.client.getLOLClientWindowInfo()
|
||||
console.log(LOLClientWindowInfo)
|
||||
return LOLClientWindowInfo
|
||||
}
|
||||
|
||||
const intervalId = setInterval(async () => {
|
||||
const config = await window.electronAPI.getBaseConfig()
|
||||
const config = await getBaseConfig()
|
||||
|
||||
// 假设我们在某些条件下想停止定时器
|
||||
if (config.Auth && config.Auth === 'Auth required') {
|
||||
@ -15,10 +20,10 @@ const intervalId = setInterval(async () => {
|
||||
console.log('请以管理员权限启动')
|
||||
} else if (config.Auth && config.Auth !== '') {
|
||||
clearInterval(intervalId)
|
||||
await getLOLClientWindowInfo()
|
||||
console.log('检测到客户端运行')
|
||||
}
|
||||
}, 500)
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -34,7 +39,7 @@ const intervalId = setInterval(async () => {
|
||||
<a href="https://electron-vite.org/" target="_blank" rel="noreferrer">Documentation</a>
|
||||
</div>
|
||||
<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>
|
||||
<Versions />
|
||||
|
Reference in New Issue
Block a user