Skip to content

feat(window): add cross-platform close confirm and shutdown KDF on exit #2853

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

Conversation

CharlVS
Copy link
Member

@CharlVS CharlVS commented Jul 2, 2025

This pull request introduces a robust window close handling mechanism across platforms, ensuring proper cleanup of resources, particularly the disposal of the KomodoDefiSdk. It also adds platform-specific utilities and integrates the flutter_window_close plugin for desktop platforms. Below are the most significant changes grouped by theme:

@DeckerSU: This complements another open PR (#2770), which restores the auth state in case the user terminates the app by means other than closing with confirmation.

Window Close Handling

  • Added WindowCloseHandler widget to manage window close events and SDK disposal across platforms (lib/sdk/widgets/window_close_handler.dart).
  • Integrated WindowCloseHandler into the main application widget tree (lib/main.dart).

Platform-Specific Utilities

  • Enhanced PlatformTuner with isNativeMobile to identify mobile platforms (lib/shared/utils/platform_tuner.dart).
  • Added _BeforeUnloadObserver for native platforms to intercept back button or window close requests (lib/shared/utils/window/window_native.dart).

Plugin Integration

  • Registered the flutter_window_close plugin for Linux, macOS, and Windows platforms (linux/flutter/generated_plugin_registrant.cc, macos/Flutter/GeneratedPluginRegistrant.swift, windows/flutter/generated_plugin_registrant.cc). [1] [2] [3]
  • Updated pubspec.yaml to include the flutter_window_close dependency (pubspec.yaml).

SDK Resource Management

  • Added dispose method in MM2 class to clean up resources (lib/mm2/mm2.dart).

Web-Specific Enhancements

  • Integrated showMessageBeforeUnload for browser beforeunload event handling (lib/views/main_layout/main_layout.dart).

TODO @takenagain: in near future PR, add lifecycle hooks listeners as a fallback to terminate KDF upon exit if user closes app by means other than the exit button. Afaik, this is only needed for platforms using the stand-alone binary.

@CharlVS CharlVS added the codex label Jul 2, 2025 — with ChatGPT Connector
Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jul 2, 2025

Visit the preview URL for this PR (updated for commit 43bc8ab):

https://walletrc--pull-2853-merge-7gel4tk7.web.app

(expires Tue, 15 Jul 2025 17:25:08 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f66a4ff03faa546f12f0ae5a841bd9eff2714dcc

@CharlVS CharlVS marked this pull request as draft July 2, 2025 11:32
@CharlVS CharlVS changed the title feat(window): add native before-unload prompt feat(window): add desktop close confirm and shut-down KDF on exit Jul 3, 2025
@CharlVS CharlVS changed the title feat(window): add desktop close confirm and shut-down KDF on exit feat(window): add cross-platform close confirm and shutdown KDF on exit Jul 3, 2025
@CharlVS CharlVS marked this pull request as ready for review July 3, 2025 18:22
@CharlVS CharlVS requested review from Copilot, DeckerSU and smk762 July 3, 2025 18:24
@CharlVS CharlVS self-assigned this Jul 3, 2025
@CharlVS CharlVS added bug Something isn't working enhancement New feature or request and removed codex labels Jul 3, 2025
@CharlVS CharlVS added this to the v0.9.2 Release milestone Jul 3, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds cross-platform window close confirmation and ensures proper disposal of the KomodoDefiSdk on exit.

  • Introduces WindowCloseHandler widget and integrates flutter_window_close plugin across desktop platforms.
  • Implements browser beforeunload handling and native mobile back-button interception.
  • Adds dispose method in MM2 for SDK cleanup and updates plugin registrations and dependencies.

Reviewed Changes

Copilot reviewed 13 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
windows/flutter/generated_plugins.cmake Registered flutter_window_close in plugin list
windows/flutter/generated_plugin_registrant.cc Included and registered FlutterWindowClosePlugin
pubspec.yaml Added flutter_window_close: ^1.2.0 dependency
macos/Flutter/GeneratedPluginRegistrant.swift Imported and registered FlutterWindowClosePlugin
linux/flutter/generated_plugins.cmake Registered flutter_window_close in plugin list
linux/flutter/generated_plugin_registrant.cc Included and registered FlutterWindowClosePlugin
lib/views/main_layout/main_layout.dart Added web beforeunload hook using showMessageBeforeUnload
lib/shared/utils/window/window_native.dart Implemented _BeforeUnloadObserver and showMessageBeforeUnload
lib/shared/utils/utils.dart Minor formatting fix and added logger dispose TODO
lib/shared/utils/platform_tuner.dart Added isNativeMobile helper
lib/sdk/widgets/window_close_handler.dart New widget for handling window close across platforms
lib/mm2/mm2.dart Added dispose method to clean up SDK resources
lib/main.dart Integrated WindowCloseHandler into app root
Comments suppressed due to low confidence (4)

lib/sdk/widgets/window_close_handler.dart:1

  • [nitpick] Add unit or widget tests for WindowCloseHandler to validate its behavior on desktop, web, and mobile platforms, including confirmation dialogs and SDK disposal.
import 'package:flutter/foundation.dart';

lib/mm2/mm2.dart:31

  • [nitpick] Add tests for MM2.dispose() to ensure the SDK is properly disposed and that exceptions are handled as expected.
  Future<void> dispose() async {

lib/views/main_layout/main_layout.dart:33

  • The function showMessageBeforeUnload is not imported in this file. Add import 'package:web_dex/shared/utils/window/window_native.dart'; (or the appropriate window utility) to resolve it.
      showMessageBeforeUnload('Are you sure you want to leave?');

lib/shared/utils/window/window_native.dart:26

  • scaffoldKey is referenced but not defined or imported. Add import 'package:web_dex/shared/utils/window/window.dart'; to access the shared scaffoldKey.
    final context = scaffoldKey.currentContext;

@CharlVS CharlVS added the QA Ready for QA Testing label Jul 3, 2025
@smk762
Copy link
Collaborator

smk762 commented Jul 5, 2025

Confirmed working as expected in linux. kdf process is killed on logout / app close, and restarted on launch / login.
Testing revealed issue outside this PR's scope, but one which needs to be fixed #2833

@smk762
Copy link
Collaborator

smk762 commented Jul 7, 2025

Testing on Windows via CI build:
image
Is signing implemented for release builds?

Encountered same dll error as previously reported
image

Unable to complete further testing. It was expected that KomodoPlatform/komodo-defi-framework#2464 would resolve this, though KDF does not appear to be the problem (apart from defender complaining) when running manually from command prompt.

image

MacOS CI builds failed. Is someone else able to build/test this PR for MacOS?

@smk762 smk762 requested review from gcharang and cipig July 7, 2025 06:02
…-showmessagebeforeunload-for-native-platforms

# Conflicts:
#	lib/views/main_layout/main_layout.dart
#	packages/komodo_ui_kit/pubspec.lock
#	pubspec.lock
@CharlVS
Copy link
Member Author

CharlVS commented Jul 7, 2025

@smk762, I believe @DeckerSU is still working on implementing signing for Windows.

Regarding the DLL error: Did you fully unzip the app before running?

@smk762
Copy link
Collaborator

smk762 commented Jul 8, 2025

@smk762, I believe @DeckerSU is still working on implementing signing for Windows.

Regarding the DLL error: Did you fully unzip the app before running?

Screencast.from.2025-07-08.14-19-53.mp4

@DeckerSU
Copy link

DeckerSU commented Jul 8, 2025

Installing the latest Microsoft Visual C++ Redistributable version should help. Most apps don’t include runtime libraries, as it’s assumed the user already has them installed.

Is signing implemented for release builds?

As for signing, I still don’t have a key for it. Our Jenkins environment is already set up and ready for signing — we just need the key to proceed.

@smk762
Copy link
Collaborator

smk762 commented Jul 8, 2025

Installing the latest Microsoft Visual C++ Redistributable version should help

Can it be safely assumed most windows users have installed this? Is it part of auto-updates? I'm running in a relatively fresh VM, installing latest updates now to retest.
image

CharlVS added 2 commits July 8, 2025 19:03
…ive-platforms

- Resolved pubspec.lock conflicts by taking dev version
- Merged showMessageBeforeUnload implementation for native platforms
- Integrated Trezor SDK migration changes from dev
- Updated plugin registrations to include FlutterWindowClosePlugin
@CharlVS CharlVS merged commit e70fc7b into dev Jul 8, 2025
10 of 14 checks passed
@CharlVS CharlVS deleted the v2jl4p-codex/implement-showmessagebeforeunload-for-native-platforms branch July 8, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request QA Ready for QA Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kdf.exe Not Terminated on Wallet Close Leading to Login Issues and Ambiguous Error Messages
3 participants