overwolf / sample-app

The Official Overwolf Sample App
https://overwolf.github.io/
119 stars 136 forks source link

Issue in onStateChanged implementation #34

Closed gabrielmicko closed 3 years ago

gabrielmicko commented 3 years ago

I think this has an implementation issue based on my logs: https://github.com/overwolf/sample-app/blob/master/native/windows/background/background-controller.js#L41

// Listen to changes in windows
    overwolf.windows.onStateChanged.addListener(async () => {
      const windowsStates = await this.windowsService.getWindowsStates();
      console.log('windowsStates', JSON.stringify(windowsStates));
      // If all UI (non-background) windows are closed, close the app
      const shouldClose = Object.entries(windowsStates)
        .filter(([windowName, windowState]) => {
          console.log('in filter - windowName', windowName);
          return windowName !== 'background';
        })
        .every(([windowName, windowState]) => {
          console.log('in every - windowState', windowState);
          return windowState === 'closed';
        });

      if (shouldClose) {
        window.close();
      }
windowsStates {"success":true,"status":"success","result":{"background":"minimized","nodge":"closed","ingame":"closed","desktop":"closed"},"resultV2":{"background":"hidden","nodge":"closed","ingame":"closed","desktop":"closed"}}
background-controller.js:48 in filter - windowName success
background-controller.js:48 in filter - windowName status
background-controller.js:48 in filter - windowName result
background-controller.js:48 in filter - windowName resultV2
background-controller.js:52 in every - windowState true
eransharv commented 3 years ago

Hey @gabrielmicko and thank you. We pushed a fix.

gabrielmicko commented 3 years ago

Awesome