bitsdojo_window icon indicating copy to clipboard operation
bitsdojo_window copied to clipboard

Handle/Listen close button on macOs

Open hungryemon opened this issue 2 years ago • 2 comments

How to handle onClose button press on mac?

hungryemon avatar Dec 26 '23 04:12 hungryemon

Not available at this moment but event handling support is planned (already started working on it).

bitsdojo avatar Jan 05 '24 23:01 bitsdojo

@hungryemon using flutter AppLifecycleListener#onExitRequested, just like this:

class AppPage extends StatefulWidget {
  const AppPage({super.key});

  @override
  State<AppPage> createState() => _AppPageState();
}

class _AppPageState extends State<AppPage> {
  late AppLifecycleListener _appLifecycleListener;

  @override
  void initState() {
    super.initState();
    _appLifecycleListener = AppLifecycleListener(
      onExitRequested: _onExitRequested,
    );
  }

  Future<AppExitResponse> _onExitRequested() async {
    // save some data to disk
    await SettingsService().updateWindowSize(appWindow.size);
    await WorkspaceService().saveWorkspace();

    return AppExitResponse.exit;
  }
...

If you don't allow close app, just return AppExitResponse.cancel.

YorekLiu avatar Jan 23 '24 14:01 YorekLiu