VolantisDev / Launchpad

Step up your non-Steam game! Generate Steam-compatible .exe files to effortlessly launch any game through Steam with overlay support.
https://launchpad.games
MIT License
88 stars 3 forks source link

Use dynamic hotkey passed in from config #234

Closed github-actions[bot] closed 3 years ago

github-actions[bot] commented 3 years ago

Use dynamic hotkey passed in from config

https://github.com/VolantisDev/Launchpad/blob/b475e3c2828044ed2daef81287ad91238eb610f4/Lib/LaunchpadLauncher/Service/OverlayManager.ahk#L57


class OverlayManager extends AppServiceBase {
    exeName := "LaunchpadOverlay.exe"
    pid := 0
    launchTime := ""
    additionalModifiers := []
    isShown := false

    __New(app) {
        this.launchTime := A_Now
        super.__New(app)
    }

    IsRunning() {
        return !!(this.GetPid())
    }

    GetPid() {
        pid := 0
        detectHidden := A_DetectHiddenWindows
        DetectHiddenWindows(true)
        pid := WinExist("ahk_exe " . this.exeName)
        DetectHiddenWindows(detectHidden)
        this.pid := pid
        return pid
    }

    Start(overlayHotkey := "Alt+Shift+Tab") {
        pid := this.GetPid()

        if (!pid) {
            config := this.app.Service("LauncherConfig")
            resourcesDir := config["ResourcesDir"]
            path := resourcesDir . "\LaunchpadLauncher\" . this.exeName

            if (FileExist(path)) {
                Run(path, this.app.appDir,, pid)
                this.pid := pid
                WinWait("ahk_pid " . pid)
                WinHide("ahk_pid " . pid)
            } else {
                ; TODO Log an error about not being able to launch the overlay
            }
        }

        keys := StrSplit(overlayHotkey, "+")
        removeLength := 1
        initialCombo := keys[1]

        if (keys.Length > 1) {
            initialCombo .= " & " . keys[2]
            removeLength += 1
        }

        keys.RemoveAt(1, removeLength)
        this.additionalModifiers := keys

        ; TODO: Use dynamic hotkey passed in from config
        hotkeys := "+{Tab}"
        Hotkey(hotkeys, ObjBindMethod(this, "ToggleOverlay"))
    }

    ToggleOverlay(*) {
        if (this.isShown) {
            Send(hotkeys)
            this.Hide()
        } else {
            this.Show()
            Send(hotkeys)
        }
    }

    Show() {
        if (!this.pid) {
            this.Start()
        }

        WinShow("ahk_pid " . this.pid)
        this.isShown := true
    }

    Hide() {
        if (this.pid) {
            WinHide("ahk_pid " . this.pid)
        }

        this.isShown := false
    }

    Close() {
        if (this.pid) {
            WinClose("ahk_pid" . this.pid)
            this.pid := 0
            this.isShown := false
        }
    }

    __Delete() {
        this.Close()
        super.__Delete()
    }
}

0a3fdce4b4603ee19366e449ed179802e4caa625

github-actions[bot] commented 3 years ago

Closed in 72eda8617f054dc27ee8662afc634cc8a89faa73