SnosMe / electron-overlay-window

Creating overlays is easy like never before
MIT License
200 stars 37 forks source link

feat: use the process ID #7

Open TGTGamer opened 3 years ago

TGTGamer commented 3 years ago

Heya, so I would like to use this alongside https://github.com/Rob--/memoryjs to create game extensions. I have the processID from memoryjs but would like to use this within your application to select which process should be overlayed, is that possible?

SnosMe commented 3 years ago

Impl:

Things to note:


I don't have time for this now.

omiinaya commented 3 years ago

you can use something like npm all-windows to get the metadata of all open windows, filter out the specific one you want using PiD, then grab the title from there and create an overlay.

TGTGamer commented 3 years ago

you can use something like npm all-windows to get the metadata of all open windows, filter out the specific one you want using PiD, then grab the title from there and create an overlay.

Slightly backwards way of doing it, as you can do it like seen here which works pretty well. Note I know as I'm working with games only one instance of the game will be open at any time with only one window.

https://github.com/Videndum/twitch-extension-template/blob/master/electron/src/GameHander.ts

    async findGame() {
        const game = getProcesses().find(p => p.szExeFile.toLowerCase() == this.GameToFind?.toLowerCase())
        this.details = { name: this.details.name, process: this.details.process, ...game }
        if (game) return game
        else return null
    }
    windows = {
        GetGameWindow: async () => {
            let stout = (await exec(`(tasklist /FI "PID eq ${this.details.th32ProcessID}" /fo list /v)`)).stdout
            let execDetails: { [x: string]: string } = {}

            stout.split("\r\n").forEach(line => {
                let param = line.split(":")
                if (!param[1]) return
                execDetails[param[0].trim()] = param[1].trim()
            })
            console.log(execDetails)
            const details: Details = {
                ...this.details,
                ImageName: execDetails["Image Name"],
                PID: Number(execDetails["PID"]),
                SessionName: execDetails["Session Name"],
                Session: Number(execDetails["Session#"]),
                MemUsage: execDetails["Mem Usage"],
                Status: execDetails["Status"],
                UserName: execDetails["User Name"],
                CPUTime: execDetails["CPU Time"],
                WindowTitle: execDetails["Window Title"]
            }
            this.details = details
            return this.details
        }
    }

Still working on a solution to mac, but following the same principle of listing all processes, finding the correct one using the name (in my case using the exe) and then finding the details which would include the window titles which can then be passed to this package.

Still would be nice to be able to have this built into this package so users don't have to go through the entire process like I have

omiinaya commented 3 years ago

you can use something like npm all-windows to get the metadata of all open windows, filter out the specific one you want using PiD, then grab the title from there and create an overlay.

Slightly backwards way of doing it, as you can do it like seen here which works pretty well. Note I know as I'm working with games only one instance of the game will be open at any time with only one window.

https://github.com/Videndum/twitch-extension-template/blob/master/electron/src/GameHander.ts

cool, i didn't know about this tasklist method. you just saved me a lot of headaches my friend :DD

pl4yradam commented 3 years ago

Be very careful using tasklist so verbosely, it can hammer a users memory, our app currently does this round trip but the package has some real issues with window states that arent practical to real-world use cases.