generated from SteamDeckHomebrew/Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getGamepadNavigationTrees } from "decky-frontend-lib"; | ||
|
||
export function getElementFromNavID(navID: string) { | ||
const all = getGamepadNavigationTrees(); | ||
if (!all) return null; | ||
const tree = all?.find((e: any) => e.m_ID == navID); | ||
if (!tree) return null; | ||
return tree.Root.Element; | ||
} | ||
export function getSP() { | ||
return getElementFromNavID("root_1_"); | ||
} | ||
export function getQAM() { | ||
return getElementFromNavID("QuickAccess-NA"); | ||
} | ||
export function getMainMenu() { | ||
return getElementFromNavID("MainNavMenuContainer"); | ||
} | ||
export function getRootElements() { | ||
return [getSP(), getQAM(), getMainMenu()].filter((e) => e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { unminifyClass } from "decky-frontend-lib"; | ||
import { getRootElements } from "./SteamTabElementsFinder"; | ||
|
||
export function unminifyElement(element: Element) { | ||
if (element.classList.length === 0) return; | ||
|
||
const classList = Array.from(element.classList); | ||
const unminifiedClassList = classList.map((c) => unminifyClass(c) ?? c); | ||
element.setAttribute("unminified-class", unminifiedClassList.join(" ")); | ||
} | ||
|
||
export function recursivelyUnminifyElement(element: Element) { | ||
unminifyElement(element); | ||
Array.from(element.children).forEach(recursivelyUnminifyElement); | ||
} | ||
|
||
export function initialUnminification(rootElement: any) { | ||
const allElements = rootElement.ownerDocument.all as HTMLAllCollection; | ||
Array.from(allElements).forEach(unminifyElement); | ||
} | ||
|
||
var mutationObservers: MutationObserver[] = []; | ||
|
||
export function disconnectMutationObservers() { | ||
mutationObservers.forEach((observer) => observer.disconnect()); | ||
mutationObservers = []; | ||
} | ||
|
||
export function mutationObserverCallback(mutations: MutationRecord[]) { | ||
mutations.forEach((mutation) => { | ||
if (mutation.type === "childList" && mutation.addedNodes.length > 0) { | ||
mutation.addedNodes.forEach((node) => { | ||
recursivelyUnminifyElement(node as Element); | ||
}); | ||
} | ||
if (mutation.type === "attributes" && mutation.attributeName === "class") { | ||
unminifyElement(mutation.target as HTMLElement); | ||
} | ||
}); | ||
} | ||
|
||
export function setUpMutationObserver(rootElement: any) { | ||
const mutationObserver = new MutationObserver(mutationObserverCallback); | ||
mutationObserver.observe(rootElement.ownerDocument.documentElement, { | ||
attributes: true, | ||
attributeFilter: ["class"], | ||
childList: true, | ||
subtree: true, | ||
}); | ||
mutationObservers.push(mutationObserver); | ||
} | ||
|
||
export function enableUnminifyMode() { | ||
if (mutationObservers.length > 0) disconnectMutationObservers(); | ||
const roots = getRootElements(); | ||
roots.forEach(initialUnminification); | ||
roots.forEach(setUpMutationObserver); | ||
} | ||
|
||
export function disableUnminifyMode() { | ||
disconnectMutationObservers(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters