Skip to content

Commit

Permalink
feat: improve process list cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Wurielle committed Jan 16, 2025
1 parent 94c886e commit 73bcb35
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
42 changes: 16 additions & 26 deletions apps/app/resources/detect-game.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { getProcessInfo } = require('windows-tlist')
const wqlImport = import('wql-process-monitor')


function send(...args) {
process.send(...args)
}
Expand All @@ -10,37 +8,29 @@ wqlImport.then((wql) => {
const { subscribe } = wql
return subscribe({
creation: true,
deletion: false,
deletion: true,
bin: {
filter: ['cmd.exe', 'tlist.exe', 'conhost.exe'],
},
})
})
.then((processMonitor) => {

// require('windows-tlist').getProcessInfo(pid).then(console.log)
processMonitor.on('creation', ([process, pid, filepath, user]) => {

console.log(`[game-detection]: process creation - ${process}::${pid}(${user}) ["${filepath}"]`)
// getProcessInfo(pid)
// .then(processInfo => {
const isGame = [
// processInfo.modules.find(module => module.path.includes('d3d')),
// processInfo.modules.find(module => module.path.includes('dxgi')),
// processInfo.modules.find(module => module.path.includes('steamapps')),
filepath.includes('steamapps'),
filepath.includes('demo.exe'),
].some(Boolean)
if (isGame) {
console.log('[game-detection]: Game launched', filepath)
send({
type: 'game-detection',
payload: {
process, pid, filepath, user,
},
})
// getProcessInfo(pid).then(console.log)
}
// })
send({
type: 'process-creation',
payload: {
process, pid, filepath, user,
},
})
})
processMonitor.on('deletion', ([process, pid, filepath, user]) => {
send({
type: 'process-deletion',
payload: {
process, pid, filepath, user,
},
})
})
})

Expand Down
37 changes: 29 additions & 8 deletions apps/app/src/electron/game-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ProcessInfo = {
}

type ProcessEvent = {
type: string
type: 'process-creation' | 'process-deletion'
payload: ProcessInfo
}

Expand All @@ -33,7 +33,8 @@ class GameOverlay {
private markQuit = false
private scaleFactor = 1.0

constructor() {}
constructor() {
}

public isReady = () => ready.promise

Expand All @@ -53,6 +54,7 @@ class GameOverlay {
])

this.Overlay!.setEventCallback((event: string, payload: any) => {
console.log(event, payload)
if (['graphics.window.event.resize', 'graphics.window'].includes(event)) {
const { width, height } = payload
emitIPCGameOverlayResize({
Expand Down Expand Up @@ -84,12 +86,12 @@ class GameOverlay {
const { top, left, right, bottom } = Window.getByPid(
payload.pid,
).getDimensions()
const width = right - left
const height = bottom - top
const width = right-left
const height = bottom-top

mouse.getPosition().then(async (initialPosition) => {
await mouse.setPosition(
new Point(left + width / 2, top + height / 2),
new Point(left+width / 2, top+height / 2),
)
await mouse.leftClick()
await mouse.setPosition(initialPosition)
Expand Down Expand Up @@ -250,7 +252,7 @@ class GameOverlay {
for (const window of this.Overlay.getTopWindows()) {
if (window.processId === processInfo.pid) {
console.log(
`--------------------\n injecting ${JSON.stringify(window)}`,
`--------------------\n injecting ${ JSON.stringify(window) }`,
)
this.Overlay.injectProcess(window)
this.hookedProcesses.push(processInfo)
Expand All @@ -271,8 +273,25 @@ class GameOverlay {
const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js'))

child.on('message', (processInfo: ProcessEvent) => {
if (processInfo.type === 'game-detection') {
this.injectByProcessOnceFocused(processInfo.payload)
if (processInfo.type === 'process-creation') {
const { filepath } = processInfo.payload
// console.log(`[game-detection]: process creation - ${process}::${pid}(${user}) ["${filepath}"]`)
const isGame = [
// processInfo.modules.find(module => module.path.includes('d3d')),
// processInfo.modules.find(module => module.path.includes('dxgi')),
// processInfo.modules.find(module => module.path.includes('steamapps')),
filepath.includes('steamapps'),
filepath.includes('demo.exe'),
].some(Boolean)
if (isGame) {
console.log('[game-overlay]: Game launched', filepath)
this.injectByProcessOnceFocused(processInfo.payload)
}
}
if (processInfo.type === 'process-deletion') {
if (this.hookedProcesses.find((process) => process.pid === processInfo.payload.pid)) {
this.hookedProcesses = this.hookedProcesses.filter((process) => process.pid !== processInfo.payload.pid)
}
}
})

Expand Down Expand Up @@ -317,9 +336,11 @@ class GameOverlay {
) {
const window = new BrowserWindow(option)
this.windows.set(name, window)

window.on('closed', () => {
this.windows.delete(name)
})

window.webContents.on('new-window', (e, url) => {
e.preventDefault()
shell.openExternal(url)
Expand Down

0 comments on commit 73bcb35

Please sign in to comment.