Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub window is freezed when switch to other app or main window #5

Open
CaoGiaHieu-dev opened this issue Oct 16, 2024 · 5 comments
Open

Comments

@CaoGiaHieu-dev
Copy link

same as this issue MixinNetwork/flutter-plugins#319

it also happen when i create new window then quickly switch to other app or main window

@yeonsh
Copy link

yeonsh commented Oct 17, 2024

There is a workaround. Refer to this comment.

MixinNetwork/flutter-plugins#289 (comment)

@CaoGiaHieu-dev
Copy link
Author

There is a workaround. Refer to this comment.

MixinNetwork/flutter-plugins#289 (comment)

Thank you . for now this was the only solutions

@pichillilorenzo
Copy link
Owner

pichillilorenzo commented Oct 23, 2024

Unfortunately, this was something I didn't expect and I didn't find any solution to fix it.
It seems to be something related to Flutter itself on macOS.
Instead, on Windows I didn't have any problem.

On macOS, the curious thing is that if I resize the window, it updates. If I lose focus and then regain it by switching to another window of another program, then it works correctly again.

@pichillilorenzo
Copy link
Owner

for reference: flutter/flutter#133533

@pichillilorenzo
Copy link
Owner

pichillilorenzo commented Oct 24, 2024

I was able to create a workaround without changing the Flutter source code, using an AppLifecycleListener to force to trigger _setFramesEnabledState(true); instead of _setFramesEnabledState(false);.

In your app implement this listener this way inside your main widget extending a State:

class _MyAppState extends State<MyApp> {

  // your code ....

  late final AppLifecycleListener? _appLifecycleListener;

  @override
  void initState() {
    // your code ....
    // workaround applies for all sub-windows (all windows with id > 0) on macOS 
    if (WindowManagerPlus.current.id > 0 && Platform.isMacOS) {
      _appLifecycleListener = AppLifecycleListener(
        onStateChange: _handleStateChange,
      );
    }
    super.initState();
  }

  void _handleStateChange(AppLifecycleState state) {
    // workaround applies for all sub-windows (all windows with id > 0) on macOS 
    if (WindowManagerPlus.current.id > 0 && Platform.isMacOS && state == AppLifecycleState.hidden) {
      // trigger _setFramesEnabledState(true); method
      SchedulerBinding.instance.handleAppLifecycleStateChanged(
          AppLifecycleState.inactive);
    }
  }

  @override
  void dispose() {
    // your code ....
    _appLifecycleListener?.dispose();
    super.dispose();
  }

  // your code ....
}

It is using the protected method SchedulerBinding.handleAppLifecycleStateChanged but this seems to be the only way to achieve that without changing the Flutter source code.

pichillilorenzo added a commit to pichillilorenzo/flutter_browser_app that referenced this issue Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants