Skip to content

Commit

Permalink
Merge pull request #192 from harmonherring/master
Browse files Browse the repository at this point in the history
Fixes #191 - Use named listener functions
  • Loading branch information
AlbericoD authored Nov 26, 2024
2 parents c7a6be8 + 08830e8 commit bd7838f
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions template/src/screens/background/components/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ const BackgroundWindow = () => {
[desktop, ingame, start, stop]
);

const onGameInfoUpdated = async (event: overwolf.games.GameInfoUpdatedEvent) => {
if (
event.runningChanged &&
event.gameInfo?.classId === HEARTHSTONE_CLASS_ID
) {
startApp("onGameInfoUpdated");
}
};

const onAppLaunchTriggered = () => {
startApp("onAppLaunchTriggered");
};

useEffect(() => {
startApp("on initial load");
overwolf.games.onGameInfoUpdated.addListener(async (event) => {
if (
event.runningChanged &&
event.gameInfo?.classId === HEARTHSTONE_CLASS_ID
) {
startApp("onGameInfoUpdated");
}
});
overwolf.extensions.onAppLaunchTriggered.addListener(() => {
startApp("onAppLaunchTriggered");
});
overwolf.games.onGameInfoUpdated.addListener(onGameInfoUpdated);
overwolf.extensions.onAppLaunchTriggered.addListener(onAppLaunchTriggered);
return () => {
overwolf.games.onGameInfoUpdated.removeListener(() => {});
overwolf.extensions.onAppLaunchTriggered.removeListener(() => {});
overwolf.games.onGameInfoUpdated.removeListener(onGameInfoUpdated);
overwolf.extensions.onAppLaunchTriggered.removeListener(onAppLaunchTriggered);
};
}, [startApp]);

Expand Down

0 comments on commit bd7838f

Please sign in to comment.