GithubHelp home page GithubHelp logo

albericod / overwolf-hooks Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 6.0 1.12 MB

Custom hooks to help use overwolf api with the new react hooks technology.

Home Page: https://www.npmjs.com/package/overwolf-hooks

License: MIT License

JavaScript 3.75% TypeScript 96.25%
overwolf react reactjs hooks hooks-api tools react-hooks npm-package overwolf-api overwolf-hooks

overwolf-hooks's Introduction

Overwolf Hooks

Custom hooks to help use overwolf api with the new react hooks technology.

NPM JavaScript Style Guide

Install

$ npm install --save overwolf-hooks
$ pnpm install --save overwolf-hooks
$ yarn add overwolf-hooks

How to use

Hooks

  1. useWindow.tsx
import { useWindow } from 'overwolf-hooks';

const shouldDisplayLog = true;
const shouldListenToWindowStateChanges = true;

const Panel = () => {

const [desktopWindow] = useWindow("desktop", shouldDisplayLog,shouldListenToWindowStateChanges);

return (
    <div>
      <h1>Desktop Window</h1>
      <button onClick={()=> desktopWindow?.minimize()}>Minimize</button>
      <button onClick={()=> desktopWindow?.restore()}>Restore</button>
      <button onClick={()=> desktopWindow?.maximize()}>Maximize</button>
      <button onClick={()=> desktopWindow?.close()}>Close</button>
    </div>
  )
}

Force Window update

If you need to force update the window state, you can use the refreshState function.

import { useWindow } from "overwolf-hooks";

const shouldDisplayLog = true;
const shouldListenToWindowStateChanges = true;

//listenToWindowStateChanges is set to true to listen to window state changes, so you can read the window state from the desktopWindowStateChanged variable
const [desktopWindow, desktopWindowStateChanged, refreshState] = useWindow(
  "desktop",
  shouldDisplayLog,
  shouldListenToWindowStateChanges
);

const Panel = () => {
  useEffect(() => {
    //........ any other code
    //force update/rebind the window object
    refreshState();
  }, [refreshState]);

  useEffect(() => {
    //........ any other code
    console.info("desktopWindowStateChanged", desktopWindowStateChanged);
  }, [desktopWindowStateChanged]);

  return <CustomComponent {...desktopWindow} />;
};
  1. useDrag.tsx
import { useEffect, useCallback } from "react";
import { useDrag, useWindow } from 'overwolf-hooks'

const shouldDisplayLog = true;

const Header = () => {

const [desktopWindow] = useWindow("desktop", shouldDisplayLog);
const { onDragStart, onMouseMove, setCurrentWindowID } = useDrag(null, shouldDisplayLog);

const updateDragWindow = useCallback(() => {
  if (desktopWindow?.id) setCurrentWindowID(desktopWindow.id);
}, [desktopWindow, setCurrentWindowID]);

useEffect(updateDragWindow, [updateDragWindow])

return (
    <header
      onMouseDown={event => onDragStart(event)}
      onMouseMove={event => onMouseMove(event)}>
        Header Text
    </header>
  )
}
  1. useGameEventProvider.tsx
const REQUIRED_FEATURES = ["game_info", "match_info", "game_events"];
const RETRY_TIMES = 10;
const DISPLAY_OVERWOLF_HOOKS_LOGS = true;

const BackgroundWindow = () => {
  const [ingame] = useWindow("ingame", DISPLAY_OVERWOLF_HOOKS_LOGS);
  const { started, start, stop } = useGameEventProvider(
    {
      onInfoUpdates: (info) => { console.log("info", info); },
      onNewEvents: (events) =>  { console.log("events", events); }),
    },
    REQUIRED_FEATURES,
    RETRY_TIMES,
    DISPLAY_OVERWOLF_HOOKS_LOGS
  );

  useEffect(() => {
    start();
    return () => stop();
  }, [start, stop]);

  return null;
}
  1. useRunningGame.tsx
import { useEffect } from "react";
import { useGameEventProvider, useRunningGame } from 'overwolf-hooks'

const shouldDisplayLog = true;

const Alert = () => {

  const [currentGame] = useRunningGame(shouldDisplayLog);

  useEffect(() => {
    console.info("currentGame", currentGame);
  }, [currentGame]);

return <p>Alert Window</p>

}

License

MIT Β© AlbericoD

overwolf-hooks's People

Contributors

albericod avatar dependabot[bot] avatar rmrt1n avatar semantic-release-bot avatar smethan avatar travisc671 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

overwolf-hooks's Issues

useGameEventProvider does not emit any data

Describe the bug
While the targeted game running rebuilding the react app causes some issues. the useGameEventProvider does not emit any data

To Reproduce
Steps to reproduce the behavior:

  1. change any file and save
  2. rebuild
  3. info and event will be undefined

Expected behavior
get info and event that are emitted by OW from useGameEventProvider

Screenshots
image
image

Create automatic publish to NPM with GitHub Actions

Is your feature request related to a problem? Please describe.

There is a better way with GitHub Actions to release and publish a new version in every new commit automatic.

Describe the solution you'd like

Create a Github Action to release and publish a new package.

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Missing package.json file.

A package.json file at the root of your project is required to release on npm.

Please follow the npm guideline to create a valid package.json file.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.