Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use the process ID #7

Open
TGTGamer opened this issue Jan 3, 2021 · 5 comments
Open

feat: use the process ID #7

TGTGamer opened this issue Jan 3, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@TGTGamer
Copy link

TGTGamer commented Jan 3, 2021

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
Copy link
Owner

SnosMe commented Jan 4, 2021

Impl:

  • Windows: EnumWindows
  • X11: XResQueryClientIds with fallback to _NET_WM_PID

Things to note:

  • Process can have multiple windows, title is more unique thing.
  • From README "You can initialize library only once", that's a very big limitation atm. It's common to restart target app but keep your utility app in tray for days, so need to add cleanup code to stop watching window, so we can change PID.

I don't have time for this now.

@SnosMe SnosMe added the enhancement New feature or request label Jan 4, 2021
@omiinaya
Copy link

omiinaya commented Jan 13, 2021

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
Copy link
Author

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
Copy link

omiinaya commented Jan 13, 2021

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants